refactor(channels): move tool hint rendering out of core (#6498)
* refactor(channels): move tool hint rendering out of core * test: align progress privacy check with structured tool events
This commit is contained in:
1 parent
b1cc89e922
commit
acc3750c28
30 files changed
+530
-124
No files matched your search
@@ -53,7 +53,7 @@ async def test_start_and_finish_events_emitted() -> None:
|
||||
assert progress == [
|
||||
("Visible", False, None),
|
||||
(
|
||||
'custom_tool("foo.txt")',
|
||||
"",
|
||||
True,
|
||||
[{
|
||||
"version": 1,
|
||||
@@ -139,5 +139,51 @@ async def test_streamed_content_is_not_repeated_before_tool_execution() -> None:
|
||||
|
||||
assert result.final_content == "Done"
|
||||
assert streamed == ["I will", " inspect it."]
|
||||
assert progress[0][0] == 'custom_tool("foo.txt")'
|
||||
assert progress[0] == ("", True, [{
|
||||
"version": 1, "phase": "start", "call_id": "call1", "name": "custom_tool",
|
||||
"arguments": {"path": "foo.txt"}, "result": None, "error": None,
|
||||
"files": [], "embeds": [],
|
||||
}])
|
||||
assert all(item[0] != "I will inspect it." for item in progress)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_batched_file_reads_keep_each_call_and_complete_arguments() -> None:
|
||||
provider = MagicMock()
|
||||
calls = [
|
||||
ToolCallRequest(
|
||||
id=f"read-{offset}", name="read_file",
|
||||
arguments={"path": "src/" + "very-long-directory/" * 8 + "说明.md", "offset": offset},
|
||||
)
|
||||
for offset in (1, 200)
|
||||
]
|
||||
responses = iter([
|
||||
LLMResponse(content="", tool_calls=calls),
|
||||
LLMResponse(content="Done", tool_calls=[]),
|
||||
])
|
||||
provider.chat_stream_with_retry = AsyncMock(side_effect=lambda *a, **kw: next(responses))
|
||||
tools = MagicMock()
|
||||
tools.get_definitions.return_value = []
|
||||
tools.prepare_call.side_effect = lambda _name, args: (None, args, None)
|
||||
tools.execute = AsyncMock(return_value="file contents")
|
||||
progress = []
|
||||
|
||||
async def on_progress(content, *, tool_hint=False, tool_events=None):
|
||||
progress.append((content, tool_hint, tool_events))
|
||||
|
||||
result = await AgentRunner().run(make_run_spec(
|
||||
provider, initial_messages=[], tools=tools, model="test-model",
|
||||
max_iterations=2, max_tool_result_chars=_DEFAULTS.max_tool_result_chars,
|
||||
concurrent_tools=True, hook=AgentProgressHook(output_events(on_progress=on_progress)),
|
||||
))
|
||||
|
||||
assert result.final_content == "Done"
|
||||
assert [(content, hint) for content, hint, _events in progress] == [("", True), ("", False)]
|
||||
for _content, _hint, events in progress:
|
||||
assert [(item["call_id"], item["name"], item["arguments"]) for item in events] == [
|
||||
(call.id, call.name, call.arguments) for call in calls
|
||||
]
|
||||
assert [item["phase"] for item in progress[0][2]] == ["start", "start"]
|
||||
assert [(item["phase"], item["result"]) for item in progress[1][2]] == [
|
||||
("end", "file contents"), ("end", "file contents"),
|
||||
]
|
||||
Reference in new issue
Block a user