diff --git a/navi/core/container.py b/navi/core/container.py index 50e3ad6..6fa0a34 100644 --- a/navi/core/container.py +++ b/navi/core/container.py @@ -97,6 +97,7 @@ session_store=session_store, scheduler=scheduler, kv_store=kv_store, + mcp_manager=mcp_manager, ) # Wire embedding backend into memory store diff --git a/navi/core/registry.py b/navi/core/registry.py index 8a6bc85..e6e340c 100644 --- a/navi/core/registry.py +++ b/navi/core/registry.py @@ -166,10 +166,12 @@ session_store=None, scheduler=None, kv_store=None, + mcp_manager=None, ) -> tuple[ToolRegistry, ProfileRegistry, BackendRegistry, ContextProviderRegistry]: """Build and populate registries with all built-in components.""" from navi.core.ai_helper import AIHelper + # Phase 1: Create registries that have no cross-dependencies on tools. backends = BackendRegistry() backend_instances = _discover_backends() if not backend_instances: @@ -185,9 +187,20 @@ default_model=settings.ollama_default_model, ) + profiles = ProfileRegistry() + for p in ALL_PROFILES: + profiles.register(p) + + cp_registry = ContextProviderRegistry() + from pathlib import Path as _Path + cp_registry.load_from_dir(str(_Path(__file__).parent.parent / "context_providers"), builtin=True) + cp_registry.load_from_dir(settings.context_providers_dir, builtin=False) + + # Phase 2: Create tools with ALL dependencies already available. tools = ToolRegistry() - reload_tool = ReloadToolsTool(registry=tools) - list_tool = ListToolsTool(registry=tools) + + reload_tool = ReloadToolsTool(registry=tools, cp_registry=cp_registry, mcp_manager=mcp_manager) + list_tool = ListToolsTool(registry=tools, profile_registry=profiles, mcp_manager=mcp_manager) manual_tool = ToolManualTool(registry=tools) memory_tool = MemoryTool(memory_store) if memory_store else None mcp_status_tool = McpStatusTool() @@ -195,6 +208,19 @@ test_mcp_tool_tool = TestMcpToolTool() schedule_recall_tool = ScheduleRecallTool(scheduler) manage_recall_tool = ManageRecallTool(scheduler) + spawn_tool = SpawnAgentTool( + profile_registry=profiles, + tool_registry=tools, + backend_registry=backends, + session_store=session_store, + memory_store=memory_store, + mcp_manager=mcp_manager, + ) + switch_tool = SwitchProfileTool( + session_store=session_store, + profile_registry=profiles, + ) + list_profiles_tool = ListProfilesTool(profile_registry=profiles) builtins = [FilesystemTool(ai_helper=ai_helper), CodeExecTool(), TerminalTool(), SshExecTool(), ImageViewTool(), @@ -203,7 +229,8 @@ ReflectTool(ai_helper=ai_helper), reload_tool, list_tool, manual_tool, mcp_status_tool, create_mcp_server_tool, test_mcp_tool_tool, - schedule_recall_tool, manage_recall_tool] + schedule_recall_tool, manage_recall_tool, + spawn_tool, switch_tool, list_profiles_tool] if memory_tool: builtins.append(memory_tool) for builtin in builtins: @@ -217,38 +244,4 @@ # Register built-in middleware tools.add_middleware(LoggingMiddleware()) - profiles = ProfileRegistry() - for p in ALL_PROFILES: - profiles.register(p) - - # Tools that need session_store + profile_registry registered after both are built. - spawn_tool = SpawnAgentTool( - profile_registry=profiles, - tool_registry=tools, - backend_registry=None, # patched below after backends are built - session_store=session_store, - memory_store=memory_store, - ) - tools.register(spawn_tool, builtin=True) - - switch_tool = SwitchProfileTool( - session_store=session_store, - profile_registry=profiles, - ) - tools.register(switch_tool, builtin=True) - - list_profiles_tool = ListProfilesTool(profile_registry=profiles) - tools.register(list_profiles_tool, builtin=True) - - # Patch cross-registry references now that all registries are built - list_tool._profile_registry = profiles - spawn_tool._backend_registry = backends - - # Context providers - cp_registry = ContextProviderRegistry() - from pathlib import Path as _Path - cp_registry.load_from_dir(str(_Path(__file__).parent.parent / "context_providers"), builtin=True) - cp_registry.load_from_dir(settings.context_providers_dir, builtin=False) - reload_tool._cp_registry = cp_registry - return tools, profiles, backends, cp_registry