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:
1 parent
8d0430c761
commit
29ba4c7f2d
18 files changed
+483
-855
No files matched your search
@@ -188,6 +188,7 @@ async def test_subagent_recovers_from_tool_error_in_same_run(tmp_path):
|
||||
workspace=tmp_path,
|
||||
bus=MessageBus(),
|
||||
max_tool_result_chars=16_000,
|
||||
consolidator=MagicMock(),
|
||||
)
|
||||
|
||||
result = await sm.run_inline(
|
||||
@@ -200,6 +201,67 @@ async def test_subagent_recovers_from_tool_error_in_same_run(tmp_path):
|
||||
assert provider.chat_stream_with_retry.await_count == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_subagent_pressure_uses_transient_summary(tmp_path):
|
||||
provider = MagicMock(spec=LLMProvider)
|
||||
provider.get_default_model.return_value = "test"
|
||||
provider.can_resume_conversation_state.return_value = False
|
||||
provider.generation = GenerationSettings(max_tokens=100)
|
||||
|
||||
def estimate(messages, _tools, _model):
|
||||
if sum(message.get("role") == "tool" for message in messages) >= 2:
|
||||
return 600, "test-counter"
|
||||
return 100, "test-counter"
|
||||
|
||||
provider.estimate_prompt_tokens = MagicMock(side_effect=estimate)
|
||||
provider.chat_stream_with_retry = AsyncMock(side_effect=[
|
||||
LLMResponse(
|
||||
content="checking",
|
||||
tool_calls=[ToolCallRequest(
|
||||
id="call-1",
|
||||
name="list_dir",
|
||||
arguments={"path": "."},
|
||||
)],
|
||||
),
|
||||
LLMResponse(
|
||||
content="checking again",
|
||||
tool_calls=[ToolCallRequest(
|
||||
id="call-2",
|
||||
name="list_dir",
|
||||
arguments={"path": "."},
|
||||
)],
|
||||
),
|
||||
LLMResponse(content="done", tool_calls=[]),
|
||||
])
|
||||
consolidator = MagicMock()
|
||||
consolidator.summarize_transcript = AsyncMock(return_value="Subagent checkpoint.")
|
||||
consolidator.summarize_provider_compaction = AsyncMock(return_value=None)
|
||||
manager = SubagentManager(
|
||||
workspace=tmp_path,
|
||||
bus=MessageBus(),
|
||||
max_tool_result_chars=16_000,
|
||||
consolidator=consolidator,
|
||||
)
|
||||
runtime = LLMRuntime.capture(
|
||||
provider,
|
||||
"test",
|
||||
context_window_tokens=1_624,
|
||||
)
|
||||
|
||||
result = await manager.run_inline(
|
||||
task="inspect the workspace",
|
||||
session_key="test:direct",
|
||||
runtime=runtime,
|
||||
)
|
||||
|
||||
assert result == "done"
|
||||
consolidator.summarize_transcript.assert_awaited_once()
|
||||
assert consolidator.summarize_transcript.await_args.kwargs["persist"] is False
|
||||
model_request = provider.chat_stream_with_retry.await_args_list[2].kwargs["messages"]
|
||||
assert "Subagent checkpoint." in model_request[0]["content"]
|
||||
assert sum(message.get("role") == "tool" for message in model_request) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_spawned_subagent_inherits_llm_usage_source(tmp_path):
|
||||
provider = MagicMock(spec=LLMProvider)
|
||||
|
||||
Reference in new issue
Block a user