fix(agent): require subagent consolidator at construction
This commit is contained in:
1 parent
3cf6ed60ce
commit
b7abbcd70b
7 files changed
+173
-22
No files matched your search
+17
-22
@@ -11,7 +11,7 @@ from collections.abc import Mapping
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any, NotRequired, TypedDict
|
from typing import TYPE_CHECKING, Any, NotRequired, TypedDict, cast
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
@@ -111,8 +111,11 @@ class SubagentManager:
|
|||||||
disabled_skills: list[str] | None = None,
|
disabled_skills: list[str] | None = None,
|
||||||
max_iterations: int | None = None,
|
max_iterations: int | None = None,
|
||||||
max_concurrent_subagents: int | None = None,
|
max_concurrent_subagents: int | None = None,
|
||||||
consolidator: Consolidator | None = None,
|
*,
|
||||||
|
consolidator: Consolidator,
|
||||||
):
|
):
|
||||||
|
if cast(object, consolidator) is None:
|
||||||
|
raise TypeError("SubagentManager requires a consolidator")
|
||||||
if workspace is None:
|
if workspace is None:
|
||||||
raise TypeError("SubagentManager.__init__() missing required argument: 'workspace'")
|
raise TypeError("SubagentManager.__init__() missing required argument: 'workspace'")
|
||||||
if bus is None:
|
if bus is None:
|
||||||
@@ -433,27 +436,19 @@ class SubagentManager:
|
|||||||
token = bind_workspace_scope(workspace_scope) if workspace_scope is not None else None
|
token = bind_workspace_scope(workspace_scope) if workspace_scope is not None else None
|
||||||
try:
|
try:
|
||||||
tool_definitions = tools.get_definitions()
|
tool_definitions = tools.get_definitions()
|
||||||
consolidate_history = (
|
consolidate_history = partial(
|
||||||
partial(
|
self.consolidator.summarize_transcript,
|
||||||
self.consolidator.summarize_transcript,
|
runtime=runtime,
|
||||||
runtime=runtime,
|
session_key=f"subagent:{task_id}",
|
||||||
session_key=f"subagent:{task_id}",
|
tools=tool_definitions,
|
||||||
tools=tool_definitions,
|
persist=False,
|
||||||
persist=False,
|
|
||||||
)
|
|
||||||
if self.consolidator is not None
|
|
||||||
else None
|
|
||||||
)
|
)
|
||||||
consolidate_provider_compaction = (
|
consolidate_provider_compaction = partial(
|
||||||
partial(
|
self.consolidator.summarize_provider_compaction,
|
||||||
self.consolidator.summarize_provider_compaction,
|
runtime=runtime,
|
||||||
runtime=runtime,
|
session_key=f"subagent:{task_id}",
|
||||||
session_key=f"subagent:{task_id}",
|
tools=tool_definitions,
|
||||||
tools=tool_definitions,
|
persist=False,
|
||||||
persist=False,
|
|
||||||
)
|
|
||||||
if self.consolidator is not None
|
|
||||||
else None
|
|
||||||
)
|
)
|
||||||
result = await self.runner.run(AgentRunSpec(
|
result = await self.runner.run(AgentRunSpec(
|
||||||
initial_messages=messages,
|
initial_messages=messages,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from nanobot.agent.memory import Consolidator
|
||||||
from nanobot.agent.runner import AgentRunResult
|
from nanobot.agent.runner import AgentRunResult
|
||||||
from nanobot.agent.subagent import SubagentManager, SubagentStatus
|
from nanobot.agent.subagent import SubagentManager, SubagentStatus
|
||||||
from nanobot.agent.tools.filesystem import FileToolsConfig
|
from nanobot.agent.tools.filesystem import FileToolsConfig
|
||||||
@@ -31,6 +32,7 @@ async def test_subagent_uses_tool_loader():
|
|||||||
workspace=Path("/tmp"),
|
workspace=Path("/tmp"),
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
tools = sm._build_tools()
|
tools = sm._build_tools()
|
||||||
assert tools.has("read_file")
|
assert tools.has("read_file")
|
||||||
@@ -49,6 +51,7 @@ async def test_subagent_build_tools_isolates_file_read_state(tmp_path):
|
|||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
|
|
||||||
first_read = sm._build_tools().get("read_file")
|
first_read = sm._build_tools().get("read_file")
|
||||||
@@ -68,6 +71,7 @@ def test_subagent_respects_file_tool_toggle(tmp_path):
|
|||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
tools_config=ToolsConfig(file=FileToolsConfig(enable=False)),
|
tools_config=ToolsConfig(file=FileToolsConfig(enable=False)),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -98,6 +102,7 @@ def test_subagent_prompt_keeps_agent_paths_for_selected_project(tmp_path):
|
|||||||
workspace=agent_workspace,
|
workspace=agent_workspace,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
|
|
||||||
prompt = manager._build_subagent_prompt(workspace=project)
|
prompt = manager._build_subagent_prompt(workspace=project)
|
||||||
@@ -119,6 +124,7 @@ def test_subagent_prompt_uses_relative_paths_in_agent_workspace(tmp_path):
|
|||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
|
|
||||||
prompt = manager._build_subagent_prompt()
|
prompt = manager._build_subagent_prompt()
|
||||||
@@ -140,6 +146,7 @@ async def test_subagent_keeps_project_runtime_scope_with_agent_owned_tools(tmp_p
|
|||||||
workspace=agent_workspace,
|
workspace=agent_workspace,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
manager.runner.run = AsyncMock(
|
manager.runner.run = AsyncMock(
|
||||||
return_value=AgentRunResult(final_content="ok", messages=[], stop_reason="completed")
|
return_value=AgentRunResult(final_content="ok", messages=[], stop_reason="completed")
|
||||||
@@ -270,6 +277,7 @@ async def test_spawned_subagent_inherits_llm_usage_source(tmp_path):
|
|||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
sm.runner.run = AsyncMock(
|
sm.runner.run = AsyncMock(
|
||||||
return_value=AgentRunResult(final_content="ok", messages=[], stop_reason="completed")
|
return_value=AgentRunResult(final_content="ok", messages=[], stop_reason="completed")
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
"""Public construction and execution contracts for subagent consolidation."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from nanobot.agent.memory import Consolidator, MemoryStore
|
||||||
|
from nanobot.agent.subagent import SubagentManager
|
||||||
|
from nanobot.bus.queue import MessageBus
|
||||||
|
from nanobot.providers.base import GenerationSettings, LLMProvider, LLMResponse, ToolCallRequest
|
||||||
|
from nanobot.session.manager import SessionManager
|
||||||
|
from nanobot.utils.helpers import estimate_prompt_tokens_chain
|
||||||
|
from nanobot.utils.llm_runtime import LLMRuntime
|
||||||
|
|
||||||
|
|
||||||
|
def test_subagent_requires_consolidator_at_construction(tmp_path):
|
||||||
|
with pytest.raises(TypeError, match="consolidator"):
|
||||||
|
SubagentManager(workspace=tmp_path, bus=MessageBus(), max_tool_result_chars=16_000)
|
||||||
|
|
||||||
|
|
||||||
|
def test_subagent_rejects_explicit_none_consolidator(tmp_path):
|
||||||
|
with pytest.raises(TypeError, match="consolidator"):
|
||||||
|
SubagentManager(
|
||||||
|
workspace=tmp_path,
|
||||||
|
bus=MessageBus(),
|
||||||
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class _EvidenceProvider(LLMProvider):
|
||||||
|
"""Model protocol fixture; all execution and consolidation machinery is real."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(provider_name="test")
|
||||||
|
self.generation = GenerationSettings(max_tokens=2048)
|
||||||
|
self.reads = 0
|
||||||
|
self.summaries = 0
|
||||||
|
|
||||||
|
def get_default_model(self):
|
||||||
|
return "test"
|
||||||
|
|
||||||
|
def estimate_prompt_tokens(self, messages, tools, model):
|
||||||
|
# Deterministic provider counter; no tokenizer cache or network dependency.
|
||||||
|
return len(json.dumps([messages, tools])) // 2, "test-provider"
|
||||||
|
|
||||||
|
async def chat(self, messages, tools=None, **kwargs):
|
||||||
|
text = json.dumps(messages)
|
||||||
|
tokens, _ = estimate_prompt_tokens_chain(self, "test", messages, tools)
|
||||||
|
assert tokens <= 21_952
|
||||||
|
if self.reads:
|
||||||
|
assert "EARLY_EVIDENCE_78291" in text
|
||||||
|
if messages[-1].get("content", "").startswith("Create a compact replacement checkpoint"):
|
||||||
|
self.summaries += 1
|
||||||
|
return LLMResponse(content="- [ephemeral] Preserve EARLY_EVIDENCE_78291.")
|
||||||
|
if self.reads == 8:
|
||||||
|
return LLMResponse(content="Completed: EARLY_EVIDENCE_78291")
|
||||||
|
index = self.reads
|
||||||
|
self.reads += 1
|
||||||
|
return LLMResponse(content=None, tool_calls=[ToolCallRequest(
|
||||||
|
id=f"read-{index}",
|
||||||
|
name="read_file",
|
||||||
|
arguments={"path": f"evidence-{index}.txt"},
|
||||||
|
)])
|
||||||
|
|
||||||
|
|
||||||
|
def _files(root: Path):
|
||||||
|
return {
|
||||||
|
str(path.relative_to(root)): hashlib.sha256(path.read_bytes()).hexdigest()
|
||||||
|
for path in root.rglob("*") if path.is_file()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("background", [False, True])
|
||||||
|
async def test_sdk_preserves_evidence_across_transient_compaction(tmp_path, background):
|
||||||
|
workspace = tmp_path / "workspace"
|
||||||
|
workspace.mkdir()
|
||||||
|
for index in range(8):
|
||||||
|
lines = ["EARLY_EVIDENCE_78291" if index == 0 else f"EVIDENCE_{index}"]
|
||||||
|
lines += [
|
||||||
|
f"{n:04d} " + hashlib.sha256(f"{index}/{n}".encode()).hexdigest()[:32]
|
||||||
|
for n in range(330)
|
||||||
|
]
|
||||||
|
(workspace / f"evidence-{index}.txt").write_text("\n".join(lines), encoding="utf-8")
|
||||||
|
sessions = SessionManager(workspace, sessions_root=tmp_path / "sessions")
|
||||||
|
consolidator = Consolidator(
|
||||||
|
MemoryStore(workspace), sessions, lambda **kwargs: [], lambda: [],
|
||||||
|
)
|
||||||
|
bus = MessageBus()
|
||||||
|
provider = _EvidenceProvider()
|
||||||
|
runtime = LLMRuntime.capture(provider, "test", context_window_tokens=24_000)
|
||||||
|
manager = SubagentManager(
|
||||||
|
workspace=workspace,
|
||||||
|
bus=bus,
|
||||||
|
max_tool_result_chars=16_000,
|
||||||
|
max_iterations=12,
|
||||||
|
restrict_to_workspace=True,
|
||||||
|
consolidator=consolidator,
|
||||||
|
)
|
||||||
|
before = _files(tmp_path)
|
||||||
|
try:
|
||||||
|
kwargs = {
|
||||||
|
"task": "Read evidence-0.txt through evidence-7.txt and retain the early identifier.",
|
||||||
|
"session_key": "test:parent",
|
||||||
|
"runtime": runtime,
|
||||||
|
}
|
||||||
|
if background:
|
||||||
|
await manager.spawn(**kwargs)
|
||||||
|
event = await asyncio.wait_for(bus.consume_inbound(), timeout=15)
|
||||||
|
assert event.session_key_override == "test:parent"
|
||||||
|
assert event.metadata["injected_event"] == "subagent_result"
|
||||||
|
result = event.content
|
||||||
|
else:
|
||||||
|
result = await asyncio.wait_for(manager.run_inline(**kwargs), timeout=15)
|
||||||
|
assert "Completed: EARLY_EVIDENCE_78291" in result
|
||||||
|
assert provider.reads == 8
|
||||||
|
assert provider.summaries >= 2
|
||||||
|
assert _files(tmp_path) == before
|
||||||
|
finally:
|
||||||
|
await manager.close()
|
||||||
@@ -9,6 +9,7 @@ import pytest
|
|||||||
|
|
||||||
from nanobot.agent import SubagentManager
|
from nanobot.agent import SubagentManager
|
||||||
from nanobot.agent.hook import AgentHookContext
|
from nanobot.agent.hook import AgentHookContext
|
||||||
|
from nanobot.agent.memory import Consolidator
|
||||||
from nanobot.agent.runner import AgentRunResult
|
from nanobot.agent.runner import AgentRunResult
|
||||||
from nanobot.agent.subagent import (
|
from nanobot.agent.subagent import (
|
||||||
SubagentStatus,
|
SubagentStatus,
|
||||||
@@ -28,6 +29,7 @@ def _manager(tmp_path: Path, **kw) -> SubagentManager:
|
|||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
defaults.update(kw)
|
defaults.update(kw)
|
||||||
return SubagentManager(**defaults)
|
return SubagentManager(**defaults)
|
||||||
@@ -114,6 +116,7 @@ class TestLegacyCompatibility:
|
|||||||
MessageBus(),
|
MessageBus(),
|
||||||
16_000,
|
16_000,
|
||||||
"legacy-model",
|
"legacy-model",
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert sm.workspace == tmp_path
|
assert sm.workspace == tmp_path
|
||||||
@@ -130,6 +133,7 @@ class TestLegacyCompatibility:
|
|||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=16_000,
|
max_tool_result_chars=16_000,
|
||||||
model="legacy-model",
|
model="legacy-model",
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
sm.runner.run = AsyncMock(return_value=AgentRunResult(
|
sm.runner.run = AsyncMock(return_value=AgentRunResult(
|
||||||
final_content="done", messages=[], stop_reason="completed",
|
final_content="done", messages=[], stop_reason="completed",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from agent.session_helpers import run_session
|
from agent.session_helpers import run_session
|
||||||
|
from nanobot.agent.memory import Consolidator
|
||||||
from nanobot.bus.outbound_events import StreamDeltaEvent, StreamEndEvent
|
from nanobot.bus.outbound_events import StreamDeltaEvent, StreamEndEvent
|
||||||
from nanobot.config.schema import AgentDefaults
|
from nanobot.config.schema import AgentDefaults
|
||||||
from nanobot.providers.base import GenerationSettings
|
from nanobot.providers.base import GenerationSettings
|
||||||
@@ -463,6 +464,7 @@ class TestSubagentCancellation:
|
|||||||
workspace=MagicMock(),
|
workspace=MagicMock(),
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
|
|
||||||
cancelled = asyncio.Event()
|
cancelled = asyncio.Event()
|
||||||
@@ -493,6 +495,7 @@ class TestSubagentCancellation:
|
|||||||
workspace=MagicMock(),
|
workspace=MagicMock(),
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
assert await mgr.cancel_by_session("nonexistent") == 0
|
assert await mgr.cancel_by_session("nonexistent") == 0
|
||||||
|
|
||||||
@@ -507,6 +510,7 @@ class TestSubagentCancellation:
|
|||||||
workspace=MagicMock(),
|
workspace=MagicMock(),
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
# Replace the real exec session manager with a mock
|
# Replace the real exec session manager with a mock
|
||||||
mock_exec_mgr = AsyncMock(spec=ExecSessionManager)
|
mock_exec_mgr = AsyncMock(spec=ExecSessionManager)
|
||||||
@@ -588,6 +592,7 @@ class TestSubagentCancellation:
|
|||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
tools_config=ToolsConfig(exec=ExecToolConfig(enable=False)),
|
tools_config=ToolsConfig(exec=ExecToolConfig(enable=False)),
|
||||||
)
|
)
|
||||||
mgr._announce_result = AsyncMock()
|
mgr._announce_result = AsyncMock()
|
||||||
@@ -746,6 +751,7 @@ class TestSubagentAnnounceSessionKey:
|
|||||||
workspace=MagicMock(),
|
workspace=MagicMock(),
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
)
|
)
|
||||||
return mgr, bus
|
return mgr, bus
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from nanobot.agent.context import TranscriptInput
|
from nanobot.agent.context import TranscriptInput
|
||||||
|
from nanobot.agent.memory import Consolidator
|
||||||
from nanobot.agent.tools.context import RequestContext
|
from nanobot.agent.tools.context import RequestContext
|
||||||
from nanobot.config.schema import AgentDefaults
|
from nanobot.config.schema import AgentDefaults
|
||||||
from nanobot.providers.base import GenerationSettings
|
from nanobot.providers.base import GenerationSettings
|
||||||
@@ -29,6 +30,7 @@ async def test_run_inline_returns_result_without_announcement(tmp_path):
|
|||||||
|
|
||||||
provider = MagicMock()
|
provider = MagicMock()
|
||||||
manager = SubagentManager(
|
manager = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -62,6 +64,7 @@ async def test_run_inline_returns_structured_error(tmp_path):
|
|||||||
from nanobot.bus.queue import MessageBus
|
from nanobot.bus.queue import MessageBus
|
||||||
|
|
||||||
manager = SubagentManager(
|
manager = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -97,6 +100,7 @@ async def test_subagent_exec_tool_receives_allowed_env_keys(tmp_path):
|
|||||||
provider = MagicMock()
|
provider = MagicMock()
|
||||||
provider.get_default_model.return_value = "test-model"
|
provider.get_default_model.return_value = "test-model"
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -142,6 +146,7 @@ async def test_subagent_uses_configured_max_iterations(tmp_path):
|
|||||||
provider = MagicMock()
|
provider = MagicMock()
|
||||||
provider.get_default_model.return_value = "test-model"
|
provider.get_default_model.return_value = "test-model"
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -185,6 +190,7 @@ async def test_spawn_forwards_temperature_to_run_spec(tmp_path):
|
|||||||
provider = MagicMock()
|
provider = MagicMock()
|
||||||
provider.get_default_model.return_value = "test-model"
|
provider.get_default_model.return_value = "test-model"
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -222,6 +228,7 @@ async def test_background_spawn_waits_for_concurrency_capacity(tmp_path):
|
|||||||
provider = MagicMock()
|
provider = MagicMock()
|
||||||
provider.get_default_model.return_value = "test-model"
|
provider.get_default_model.return_value = "test-model"
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -322,6 +329,7 @@ async def test_inline_spawn_waits_for_concurrency_capacity(tmp_path):
|
|||||||
from nanobot.bus.queue import MessageBus
|
from nanobot.bus.queue import MessageBus
|
||||||
|
|
||||||
manager = SubagentManager(
|
manager = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -387,6 +395,7 @@ async def test_runner_executes_inline_spawn_batch_concurrently(tmp_path):
|
|||||||
from nanobot.providers.base import ToolCallRequest
|
from nanobot.providers.base import ToolCallRequest
|
||||||
|
|
||||||
manager = SubagentManager(
|
manager = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -456,6 +465,7 @@ async def test_cancel_by_session_cancels_inline_subagent(tmp_path):
|
|||||||
from nanobot.bus.queue import MessageBus
|
from nanobot.bus.queue import MessageBus
|
||||||
|
|
||||||
manager = SubagentManager(
|
manager = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=MessageBus(),
|
bus=MessageBus(),
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -489,6 +499,7 @@ def test_subagent_default_max_concurrent_matches_agent_defaults(tmp_path):
|
|||||||
|
|
||||||
bus = MessageBus()
|
bus = MessageBus()
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
@@ -505,6 +516,7 @@ def test_subagent_default_max_iterations_matches_agent_defaults(tmp_path):
|
|||||||
|
|
||||||
bus = MessageBus()
|
bus = MessageBus()
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from nanobot.agent.loop import AgentLoop
|
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, SubagentStatus
|
||||||
from nanobot.agent.tools.registry import is_tool_error_result
|
from nanobot.agent.tools.registry import is_tool_error_result
|
||||||
from nanobot.agent.tools.search import FindFilesTool, GrepTool
|
from nanobot.agent.tools.search import FindFilesTool, GrepTool
|
||||||
@@ -781,6 +782,7 @@ async def test_subagent_registers_search_backend(tmp_path: Path, monkeypatch, us
|
|||||||
provider.get_default_model.return_value = "test-model"
|
provider.get_default_model.return_value = "test-model"
|
||||||
provider.generation = GenerationSettings()
|
provider.generation = GenerationSettings()
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=4096,
|
max_tool_result_chars=4096,
|
||||||
@@ -823,6 +825,7 @@ def test_subagent_prompt_respects_disabled_skills(tmp_path: Path) -> None:
|
|||||||
(skills_dir / "beta" / "SKILL.md").write_text("# Beta\n\nshown\n", encoding="utf-8")
|
(skills_dir / "beta" / "SKILL.md").write_text("# Beta\n\nshown\n", encoding="utf-8")
|
||||||
|
|
||||||
mgr = SubagentManager(
|
mgr = SubagentManager(
|
||||||
|
consolidator=MagicMock(spec=Consolidator),
|
||||||
workspace=tmp_path,
|
workspace=tmp_path,
|
||||||
bus=bus,
|
bus=bus,
|
||||||
max_tool_result_chars=4096,
|
max_tool_result_chars=4096,
|
||||||
|
|||||||
Reference in new issue
Block a user