fix(agent): remove local context tail truncation (#5820)

* fix(agent): remove local context tail truncation

* fix(agent): defer subagent type annotations

* fix(agent): require context consolidator for runner

* refactor(agent): minimize consolidator contract diff
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-20 16:00:44 +08:00
1 parent 8d0430c761
commit 29ba4c7f2d
18 files changed
+483 -855

No files matched your search

+25 -29
View File
@@ -378,6 +378,16 @@ class AgentLoop:
self.tools = tool_registry if tool_registry is not None else ToolRegistry()
self._exec_session_manager = ExecSessionManager()
self.runner = AgentRunner()
self.consolidator = Consolidator(
store=self.context.memory,
sessions=self.sessions,
build_messages=self.context.build_messages,
get_tool_definitions=self.tools.get_definitions,
resolve_prompt_context=PersistedPromptContextResolver(
workspace_scopes=self.workspace_scopes,
unified_session=unified_session,
),
)
self.subagents = SubagentManager(
workspace=workspace,
bus=bus,
@@ -387,6 +397,7 @@ class AgentLoop:
disabled_skills=disabled_skills,
max_iterations=self.max_iterations,
max_concurrent_subagents=max_concurrent_subagents,
consolidator=self.consolidator,
)
self._unified_session = unified_session
self._running = False
@@ -421,16 +432,6 @@ class AgentLoop:
self._concurrency_gate: asyncio.Semaphore | None = (
asyncio.Semaphore(_max) if _max > 0 else None
)
self.consolidator = Consolidator(
store=self.context.memory,
sessions=self.sessions,
build_messages=self.context.build_messages,
get_tool_definitions=self.tools.get_definitions,
resolve_prompt_context=PersistedPromptContextResolver(
workspace_scopes=self.workspace_scopes,
unified_session=unified_session,
),
)
self.auto_compact = AutoCompact(
sessions=self.sessions,
consolidator=self.consolidator,
@@ -1146,6 +1147,7 @@ class AgentLoop:
runtime=runtime,
)
active_session_key = session.key if session else request_ctx.session_key
consolidation_session_key = active_session_key or "agent:transient"
request_metadata = request_ctx.metadata
effective_scope = self.workspace_scopes.for_turn(
channel=request_ctx.channel,
@@ -1216,25 +1218,19 @@ class AgentLoop:
session_key=session.key if session else None,
provider_retry_mode=self.provider_retry_mode,
checkpoint_callback=_checkpoint,
consolidate_history=(
partial(
self.consolidator.summarize_transcript,
runtime=runtime,
session_key=session.key,
tools=effective_tools.get_definitions(),
)
if session is not None and not ephemeral
else None
consolidate_history=partial(
self.consolidator.summarize_transcript,
runtime=runtime,
session_key=consolidation_session_key,
tools=effective_tools.get_definitions(),
persist=session is not None and not ephemeral,
),
consolidate_provider_compaction=(
partial(
self.consolidator.summarize_provider_compaction,
runtime=runtime,
session_key=session.key,
tools=effective_tools.get_definitions(),
)
if session is not None and not ephemeral
else None
consolidate_provider_compaction=partial(
self.consolidator.summarize_provider_compaction,
runtime=runtime,
session_key=consolidation_session_key,
tools=effective_tools.get_definitions(),
persist=session is not None and not ephemeral,
),
injection_callback=_drain_pending,
terminal_injection_callback=_wait_for_pending,
@@ -2114,7 +2110,7 @@ class AgentLoop:
self._save_turn(
session, ctx.all_messages, ctx.save_skip,
turn_latency_ms=ctx.turn_latency_ms,
summary_checkpoint=ctx.summary_checkpoint,
summary_checkpoint=None if ctx.ephemeral else ctx.summary_checkpoint,
input_persisted_early=ctx.input_persisted_early,
)
if (