mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-19 16:12:30 +00:00
The llm_timeout_s was computed once when creating AgentRunSpec, so if long_task was called during a turn, subsequent LLM requests still used the original timeout (default 300s). Now it's a callable that re-reads session metadata on each _call_llm invocation.
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Subagent forwards loop-provided LLM wall-timeout resolver into AgentRunSpec."""
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
|
|
from nanobot.agent.runner import AgentRunResult
|
|
from nanobot.agent.subagent import SubagentManager, SubagentStatus
|
|
from nanobot.bus.queue import MessageBus
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_subagent_forwards_resolver_to_agent_run_spec(tmp_path: Path) -> None:
|
|
provider = MagicMock()
|
|
provider.get_default_model.return_value = "m"
|
|
mgr = SubagentManager(
|
|
provider=provider,
|
|
workspace=tmp_path,
|
|
bus=MessageBus(),
|
|
max_tool_result_chars=64,
|
|
llm_wall_timeout_for_session=lambda sk: 0.0 if sk == "cli:direct" else None,
|
|
)
|
|
|
|
mgr.runner.run = AsyncMock(
|
|
return_value=AgentRunResult(final_content="ok", messages=[], stop_reason="completed")
|
|
)
|
|
mgr._announce_result = AsyncMock()
|
|
|
|
status = SubagentStatus(
|
|
task_id="t1",
|
|
label="lbl",
|
|
task_description="task",
|
|
started_at=0.0,
|
|
)
|
|
await mgr._run_subagent(
|
|
"t1",
|
|
"task",
|
|
"lbl",
|
|
{"channel": "cli", "chat_id": "direct", "session_key": "cli:direct"},
|
|
status,
|
|
)
|
|
mgr.runner.run.assert_called_once()
|
|
spec = mgr.runner.run.call_args[0][0]
|
|
assert spec.session_key == "cli:direct"
|
|
assert callable(spec.llm_timeout_s)
|
|
assert spec.llm_timeout_s() == 0.0
|