mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
refactor(agent): make run usage explicit (#5546)
* refactor(agent): make run usage explicit * fix(api): capture usage per run
This commit is contained in:
@@ -457,12 +457,12 @@ async def test_agent_loop_extra_hook_receives_calls(tmp_path):
|
||||
)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
content, tools_used, messages, _, _ = await loop._run_agent_loop(
|
||||
result = await loop._run_agent_loop(
|
||||
[{"role": "user", "content": "hi"}],
|
||||
runtime=loop.llm_runtime(),
|
||||
)
|
||||
|
||||
assert content == "done"
|
||||
assert result.final_content == "done"
|
||||
assert "before_run" in events
|
||||
assert "before_iter:0" in events
|
||||
assert "after_iter:0" in events
|
||||
@@ -545,12 +545,12 @@ async def test_agent_loop_extra_hook_error_isolation(tmp_path):
|
||||
)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
content, _, _, _, _ = await loop._run_agent_loop(
|
||||
result = await loop._run_agent_loop(
|
||||
[{"role": "user", "content": "hi"}],
|
||||
runtime=loop.llm_runtime(),
|
||||
)
|
||||
|
||||
assert content == "still works"
|
||||
assert result.final_content == "still works"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -590,11 +590,11 @@ async def test_agent_loop_no_hooks_backward_compat(tmp_path):
|
||||
loop.tools.execute = AsyncMock(return_value="ok")
|
||||
loop.max_iterations = 2
|
||||
|
||||
content, tools_used, _, _, _ = await loop._run_agent_loop(
|
||||
result = await loop._run_agent_loop(
|
||||
[], runtime=loop.llm_runtime()
|
||||
)
|
||||
assert content == (
|
||||
assert result.final_content == (
|
||||
"I reached the maximum number of tool call iterations (2) "
|
||||
"without completing the task. You can try breaking the task into smaller steps."
|
||||
)
|
||||
assert tools_used == ["list_dir", "list_dir"]
|
||||
assert result.tools_used == ["list_dir", "list_dir"]
|
||||
|
||||
Reference in New Issue
Block a user