resumen de artifacts

This commit is contained in:
Jordan
2026-04-02 00:34:06 +01:00
parent bfccb02373
commit 2997622b4d
3 changed files with 109 additions and 3 deletions

View File

@@ -84,11 +84,15 @@ class ContextEngine:
if kb_section:
sections.append(kb_section)
# 4. Task state
# 4. Task history — compact summaries of past tasks in this session
if "task_state" in allowed and session.task_history:
sections.append(self._build_task_history(session))
# 5. Task state — current task
if "task_state" in allowed and session.current_task:
sections.append(self._build_task_state(session.current_task))
# 5. Artifact memory — summarised, never raw
# 6. Artifact memory — summarised, never raw (only current task's)
if "artifact_memory" in allowed and artifacts:
sections.append(self._build_artifact_memory(artifacts))
@@ -379,6 +383,42 @@ class ContextEngine:
parts.extend(session.current_task.facts_extracted[-5:])
return " ".join(parts)
def _build_task_history(self, session: SessionState) -> ContextSection:
"""Build a compact summary of past tasks in this session.
Each completed task is ~50 tokens instead of hundreds.
The agent retains awareness of what was done before.
"""
lines = [
"# Session History",
f"_{len(session.task_history)} previous task(s) in this session_",
"",
]
for i, entry in enumerate(session.task_history):
status = entry.get("status", "?")
objective = entry.get("objective", "")[:100]
summary = entry.get("summary", "")[:150]
facts = entry.get("facts", [])
lines.append(f"**Task {i + 1}** [{status}]: {objective}")
if summary:
lines.append(f" Result: {summary}")
if facts:
lines.append(f" Facts: {'; '.join(facts[:5])}")
review = entry.get("review", "")
if review:
lines.append(f" Review: {review[:100]}")
lines.append("")
content = "\n".join(lines)
return ContextSection(
section_type=ContextSectionType.TASK_STATE,
content=content,
priority=55, # Below knowledge (60), above artifacts (50)
token_estimate=estimate_tokens(content),
)
def _build_task_state(self, task: TaskState) -> ContextSection:
lines = [
"# Current Task",