mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
feat(usage): add unified provider usage backend
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Tests for SubagentManager."""
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
@@ -10,6 +11,7 @@ from nanobot.agent.subagent import SubagentManager, SubagentStatus
|
||||
from nanobot.agent.tools.filesystem import FileToolsConfig
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.config.schema import ToolsConfig
|
||||
from nanobot.llm_usage.context import llm_usage_source
|
||||
from nanobot.providers.base import GenerationSettings, LLMProvider
|
||||
from nanobot.security.workspace_access import build_workspace_scope
|
||||
from nanobot.utils.llm_runtime import LLMRuntime
|
||||
@@ -198,3 +200,30 @@ async def test_subagent_forwards_fail_on_tool_error_to_runner(tmp_path):
|
||||
|
||||
spec = sm.runner.run.call_args.args[0]
|
||||
assert spec.fail_on_tool_error is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_spawned_subagent_inherits_llm_usage_source(tmp_path):
|
||||
provider = MagicMock(spec=LLMProvider)
|
||||
provider.get_default_model.return_value = "test"
|
||||
sm = SubagentManager(
|
||||
workspace=tmp_path,
|
||||
bus=MessageBus(),
|
||||
max_tool_result_chars=16_000,
|
||||
)
|
||||
sm.runner.run = AsyncMock(
|
||||
return_value=AgentRunResult(final_content="ok", messages=[], stop_reason="completed")
|
||||
)
|
||||
sm._announce_result = AsyncMock()
|
||||
|
||||
with llm_usage_source("cron"):
|
||||
await sm.spawn(
|
||||
"automation task",
|
||||
session_key="websocket:bound-automation",
|
||||
runtime=_runtime(provider),
|
||||
)
|
||||
tasks = list(sm._running_tasks.values())
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
spec = sm.runner.run.call_args.args[0]
|
||||
assert spec.llm_usage_source == "cron"
|
||||
|
||||
Reference in New Issue
Block a user