feat(subagent): add session-owned task messaging and cancellation (#5985)
let's go!
This commit is contained in:
1 parent
f75470e72f
commit
6ff96f2a8f
93 files changed
+5632
-1156
No files matched your search
@@ -6,7 +6,6 @@ import asyncio
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
@@ -15,7 +14,7 @@ import pytest
|
||||
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.agent.memory import Consolidator
|
||||
from nanobot.agent.subagent import SubagentManager, SubagentStatus
|
||||
from nanobot.agent.subagent import SubagentManager
|
||||
from nanobot.agent.tools.registry import is_tool_error_result
|
||||
from nanobot.agent.tools.search import FindFilesTool, GrepTool
|
||||
from nanobot.agent.tools.web import WebSearchTool
|
||||
@@ -801,15 +800,14 @@ async def test_subagent_registers_search_backend(tmp_path: Path, monkeypatch, us
|
||||
mgr.runner.run = fake_run
|
||||
mgr._announce_result = AsyncMock()
|
||||
|
||||
status = SubagentStatus(task_id="sub-1", label="label", task_description="search task", started_at=time.monotonic())
|
||||
await mgr._run_subagent(
|
||||
"sub-1",
|
||||
"search task",
|
||||
"label",
|
||||
{"channel": "cli", "chat_id": "direct"},
|
||||
status,
|
||||
LLMRuntime.capture(provider, "test-model", context_window_tokens=128_000),
|
||||
await mgr.spawn(
|
||||
task="search task",
|
||||
label="label",
|
||||
origin_channel="cli",
|
||||
origin_chat_id="direct",
|
||||
runtime=LLMRuntime.capture(provider, "test-model", context_window_tokens=128_000),
|
||||
)
|
||||
await asyncio.gather(*mgr._running_tasks.values(), return_exceptions=True)
|
||||
|
||||
assert ("rg" in captured["tool_names"]) == use_rg
|
||||
assert ("find_files" in captured["tool_names"]) == (not use_rg)
|
||||
|
||||
@@ -95,7 +95,7 @@ def test_discover_finds_concrete_tools():
|
||||
assert "CliAppsTool" in class_names
|
||||
assert "MessageTool" in class_names
|
||||
assert "MyTool" in class_names
|
||||
assert "SpawnTool" in class_names
|
||||
assert "SubagentTool" in class_names
|
||||
assert "ExecSessionTool" in class_names
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ def test_fs_tool_create_respects_sandbox():
|
||||
assert tool._allowed_dir == Path("/tmp/test")
|
||||
|
||||
|
||||
# --- Task 5: MessageTool, SpawnTool, CronTool ---
|
||||
# --- Message, subagent, and cron tool factories ---
|
||||
|
||||
|
||||
async def test_message_tool_create():
|
||||
@@ -221,13 +221,13 @@ async def test_message_tool_create():
|
||||
assert isinstance(tool, MessageTool)
|
||||
|
||||
|
||||
def test_spawn_tool_create():
|
||||
from nanobot.agent.tools.spawn import SpawnTool
|
||||
def test_subagent_tool_create():
|
||||
from nanobot.agent.tools.subagent import SubagentTool
|
||||
mock_mgr = MagicMock()
|
||||
mock_config = MagicMock()
|
||||
ctx = ToolContext(config=mock_config, workspace="/tmp", subagent_manager=mock_mgr)
|
||||
tool = SpawnTool.create(ctx)
|
||||
assert isinstance(tool, SpawnTool)
|
||||
tool = SubagentTool.create(ctx)
|
||||
assert isinstance(tool, SubagentTool)
|
||||
|
||||
|
||||
def test_cron_tool_enabled_without_service():
|
||||
@@ -407,7 +407,7 @@ def test_mcp_wrappers_not_discoverable():
|
||||
# --- Task 10: Integration test ---
|
||||
|
||||
|
||||
def test_loader_registers_same_tools_as_old_hardcoded():
|
||||
def test_loader_registers_builtin_tools():
|
||||
"""Verify the loader produces the same tool set as the old _register_default_tools."""
|
||||
from nanobot.agent.tools.loader import ToolLoader
|
||||
from nanobot.agent.tools.registry import ToolRegistry
|
||||
@@ -448,7 +448,7 @@ def test_loader_registers_same_tools_as_old_hardcoded():
|
||||
"read_file", "write_file", "edit_file", "list_dir",
|
||||
"exec", "exec_session", "list_exec_sessions",
|
||||
"web_search", "web_fetch",
|
||||
"message", "spawn", "cron",
|
||||
"message", "subagent", "cron",
|
||||
"my",
|
||||
}
|
||||
actual = set(registered)
|
||||
|
||||
Reference in new issue
Block a user