mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
refactor(agent): reduce loop runner parameter plumbing
This commit is contained in:
@@ -10,6 +10,7 @@ import pytest
|
||||
|
||||
from agent.runner_helpers import make_run_spec
|
||||
from nanobot.agent.automation_turns import publish_next_deferred_turn
|
||||
from nanobot.agent.tools.context import RequestContext
|
||||
from nanobot.config.schema import AgentDefaults
|
||||
from nanobot.providers.base import LLMResponse, ToolCallRequest
|
||||
|
||||
@@ -390,13 +391,13 @@ async def test_goal_continuation_precedes_terminal_wait():
|
||||
])
|
||||
tools = MagicMock()
|
||||
tools.get_definitions.return_value = []
|
||||
goal_checks = 0
|
||||
continuation_checks = 0
|
||||
terminal_waits = 0
|
||||
|
||||
def goal_active() -> bool:
|
||||
nonlocal goal_checks
|
||||
goal_checks += 1
|
||||
return goal_checks == 1
|
||||
def continue_goal() -> str | None:
|
||||
nonlocal continuation_checks
|
||||
continuation_checks += 1
|
||||
return "Continue the active goal." if continuation_checks == 1 else None
|
||||
|
||||
async def drain_available():
|
||||
return []
|
||||
@@ -415,7 +416,7 @@ async def test_goal_continuation_precedes_terminal_wait():
|
||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||
injection_callback=drain_available,
|
||||
terminal_injection_callback=wait_at_terminal,
|
||||
goal_active_predicate=goal_active,
|
||||
continuation_callback=continue_goal,
|
||||
))
|
||||
|
||||
assert provider.chat_with_retry.await_count == 2
|
||||
@@ -614,11 +615,11 @@ async def test_loop_injected_followup_preserves_image_media(tmp_path):
|
||||
media=[str(image_path)],
|
||||
))
|
||||
|
||||
runtime = loop.llm_runtime()
|
||||
result = await loop._run_agent_loop(
|
||||
[{"role": "user", "content": "hello"}],
|
||||
runtime=loop.llm_runtime(),
|
||||
channel="cli",
|
||||
chat_id="c",
|
||||
runtime=runtime,
|
||||
request_context=RequestContext(channel="cli", chat_id="c", runtime=runtime),
|
||||
pending_queue=pending_queue,
|
||||
)
|
||||
|
||||
@@ -708,13 +709,17 @@ async def test_pending_injection_resolves_its_own_runtime_context(tmp_path):
|
||||
},
|
||||
))
|
||||
|
||||
runtime = loop.llm_runtime()
|
||||
result = await loop._run_agent_loop(
|
||||
[{"role": "user", "content": "initial message from user A"}],
|
||||
runtime=loop.llm_runtime(),
|
||||
runtime=runtime,
|
||||
session=session,
|
||||
channel="telegram",
|
||||
chat_id="group-1",
|
||||
session_key=session.key,
|
||||
request_context=RequestContext(
|
||||
channel="telegram",
|
||||
chat_id="group-1",
|
||||
session_key=session.key,
|
||||
runtime=runtime,
|
||||
),
|
||||
pending_queue=pending_queue,
|
||||
)
|
||||
|
||||
@@ -805,11 +810,11 @@ async def test_subagent_pending_injection_is_hidden_history_and_not_merged(tmp_p
|
||||
metadata={"injected_event": "subagent_result", "subagent_task_id": "sub-1"},
|
||||
))
|
||||
|
||||
runtime = loop.llm_runtime()
|
||||
result = await loop._run_agent_loop(
|
||||
[{"role": "user", "content": "hello"}],
|
||||
runtime=loop.llm_runtime(),
|
||||
channel="cli",
|
||||
chat_id="c",
|
||||
runtime=runtime,
|
||||
request_context=RequestContext(channel="cli", chat_id="c", runtime=runtime),
|
||||
pending_queue=pending_queue,
|
||||
)
|
||||
|
||||
@@ -1469,11 +1474,11 @@ async def test_pending_queue_preserves_overflow_for_next_injection_cycle(tmp_pat
|
||||
content=f"follow-up-{idx}",
|
||||
))
|
||||
|
||||
runtime = loop.llm_runtime()
|
||||
result = await loop._run_agent_loop(
|
||||
[{"role": "user", "content": "hello"}],
|
||||
runtime=loop.llm_runtime(),
|
||||
channel="cli",
|
||||
chat_id="c",
|
||||
runtime=runtime,
|
||||
request_context=RequestContext(channel="cli", chat_id="c", runtime=runtime),
|
||||
pending_queue=pending_queue,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user