refactor(agent): unify request context routing

This commit is contained in:
chengyongru
2026-07-10 17:54:34 +08:00
committed by Xubin Ren
parent bb3b449e09
commit 42d7ad34a4
20 changed files with 363 additions and 423 deletions
+9 -10
View File
@@ -159,19 +159,18 @@ async def test_spawn_tool_rejects_when_at_concurrency_limit(tmp_path):
mgr.runner.run = AsyncMock(side_effect=fake_run)
from nanobot.agent.tools.context import RequestContext
from nanobot.agent.tools.context import RequestContext, request_context
tool = SpawnTool(mgr)
tool.set_context(RequestContext(channel="test", chat_id="c1", session_key="test:c1"))
with request_context(RequestContext(channel="test", chat_id="c1", session_key="test:c1")):
# First spawn succeeds
result = await tool.execute(task="first task")
assert "started" in result
# First spawn succeeds
result = await tool.execute(task="first task")
assert "started" in result
# Second spawn should be rejected (default limit is 1)
result = await tool.execute(task="second task")
assert "Cannot spawn subagent" in result
assert "concurrency limit reached" in result
# Second spawn should be rejected (default limit is 1)
result = await tool.execute(task="second task")
assert "Cannot spawn subagent" in result
assert "concurrency limit reached" in result
# Release the first subagent
release.set()