This commit is contained in:
zyp
2026-11-18 16:01:50 +08:00
parent 0dc48ad092
commit 0c3d0c1ce4
30 changed files with 1525 additions and 93 deletions
+12 -3
View File
@@ -2,6 +2,8 @@
import json
import logging
import re
from itertools import zip_longest
from app.modules.work_assistant.context_text import excerpt
from app.modules.work_assistant.model_gateway import complete_json
from app.modules.work_assistant.schemas import ContinueDecision, ContinueRequest, Evidence, Plan
@@ -10,7 +12,7 @@ from app.modules.work_assistant.protocol import normalize_proposal
logger = logging.getLogger(__name__)
def evidence_context(evidence: list[Evidence], budget: int = 18000, resources=None) -> tuple[list[dict], set[str], bool]:
def evidence_context(evidence: list[Evidence], budget: int = 18000, resources=None, question: str = "") -> tuple[list[dict], set[str], bool]:
records, allowed = [], set()
definitions = {r['id']:r for r in (resources or [])}
reduced = False
@@ -35,14 +37,21 @@ def evidence_context(evidence: list[Evidence], budget: int = 18000, resources=No
records.append(record); allowed.add(record["source_id"]); budget -= cost
else:
reduced = True
for row in item.rows:
# Keep every query's scope/count first, then interleave detail rows. This
# prevents one large source from consuming the context for all other goals.
groups = [[(item, row) for row in item.rows] for item in evidence if item.status == "ok"]
for group in zip_longest(*groups):
for entry in group:
if entry is None:
continue
item, row = entry
reduced = reduced or bool(row.get("truncated_fields"))
if not item.resource or row.get("id") in (None, ""):
continue
fields = {}
for name, label in item.fields.items():
value = str(row.get(name, ""))
fields[label] = value[:1600]
fields[label] = excerpt(value, question)
reduced = reduced or len(value) > 1600
record = {"source_id": f"{item.resource}:{row['id']}", "resource": item.resource,
"title": str(row.get("title", item.title))[:200], "fields": fields}