Personal AI, On Personal Devices
Python
feat: wire tools from agent config to executor via ToolRegistry
Jon Saad-Falcon7366681f62b9
diff --git a/src/openjarvis/agents/executor.py b/src/openjarvis/agents/executor.pyindex c7e34342..713d1a58 100644--- a/src/openjarvis/agents/executor.py+++ b/src/openjarvis/agents/executor.py@@ -54,6 +54,27 @@ class AgentExecutor:except Exception:pass # Non-critical+ def _inject_tool_deps(self, tool: Any) -> None:+ """Inject runtime dependencies into a tool instance.++ Mirrors SystemBuilder._inject_tool_deps (system.py:920-945)+ but uses the lightweight system's references.+ """+ if self._system is None:+ return+ name = getattr(getattr(tool, "spec", None), "name", "")+ if name == "llm":+ if hasattr(tool, "_engine"):+ tool._engine = self._system.engine+ if hasattr(tool, "_model"):+ tool._model = self._system.model+ elif name == "retrieval" or name.startswith("memory_"):+ if hasattr(tool, "_backend"):+ tool._backend = getattr(self._system, "memory_backend", None)+ elif name.startswith("channel_"):+ if hasattr(tool, "_channel"):+ tool._channel = getattr(self._system, "channel_backend", None)+def run_ephemeral(self,agent_type: str,@@ -239,12 +260,44 @@ class AgentExecutor:except Exception:pass # Fall back to configured model- # Construct agent instance (BaseAgent requires engine, model as positional args)+ # Resolve tools from config via ToolRegistry+ tool_names = config.get("tools", [])+ if isinstance(tool_names, str):+ tool_names = [t.strip() for t in tool_names.split(",") if t.strip()]++ tool_instances: list[Any] = []+ if tool_names:+ try:+ from openjarvis.server.agent_manager_routes import (+ _ensure_registries_populated,+ )++ _ensure_registries_populated()+ except ImportError:+ pass+ from openjarvis.core.registry import ToolRegistry++ for tname in tool_names:+ if ToolRegistry.contains(tname):+ try:+ tool_cls = ToolRegistry.get(tname)+ tool = tool_cls()+ self._inject_tool_deps(tool)+ tool_instances.append(tool)+ except Exception:+ logger.warning("Failed to instantiate tool %s", tname)+ if tool_instances:+ logger.info(+ "Agent %s: resolved %d/%d tools",+ agent["name"], len(tool_instances), len(tool_names),+ )++ # Construct agent instanceagent_instance = agent_cls(engine,model,system_prompt=config.get("system_prompt"),- tools=[],+ tools=tool_instances,)# Build input from instruction + summary_memory + pending messagesdiff --git a/tests/agents/test_executor_tools.py b/tests/agents/test_executor_tools.pynew file mode 100644index 00000000..70e26132--- /dev/null+++ b/tests/agents/test_executor_tools.py@@ -0,0 +1,104 @@+"""Tests for tool wiring in AgentExecutor."""++from __future__ import annotations++from openjarvis.agents.executor import AgentExecutor+from openjarvis.agents.manager import AgentManager+from openjarvis.core.events import EventBus+from tests.agents.fake_engine import FakeEngine+from tests.agents.scenario_harness import FakeSystem+++def _register_agent():+ """Re-register MonitorOperativeAgent (cleared by autouse fixture)."""+ from openjarvis.agents.monitor_operative import MonitorOperativeAgent+ from openjarvis.core.registry import AgentRegistry++ if not AgentRegistry.contains("monitor_operative"):+ AgentRegistry.register("monitor_operative")(MonitorOperativeAgent)+++def test_executor_runs_with_tools_from_config(tmp_path):+ """Executor should resolve tool names from config and complete tick."""+ _register_agent()++ engine = FakeEngine([{"content": "test response"}])+ system = FakeSystem(engine=engine)++ mgr = AgentManager(db_path=str(tmp_path / "test.db"))+ agent = mgr.create_agent(+ "test",+ agent_type="monitor_operative",+ config={+ "system_prompt": "You are a test agent.",+ "tools": ["think"],+ "instruction": "test",+ },+ )+ mgr.send_message(agent["id"], "hello", mode="immediate")++ executor = AgentExecutor(manager=mgr, event_bus=EventBus())+ executor.set_system(system)++ executor.execute_tick(agent["id"])+ result_agent = mgr.get_agent(agent["id"])+ assert result_agent["status"] == "idle"+ assert result_agent["total_runs"] == 1+ mgr.close()+++def test_executor_handles_missing_tools(tmp_path):+ """Executor should not crash if tool names don't exist in registry."""+ _register_agent()++ engine = FakeEngine([{"content": "test response"}])+ system = FakeSystem(engine=engine)++ mgr = AgentManager(db_path=str(tmp_path / "test.db"))+ agent = mgr.create_agent(+ "test",+ agent_type="monitor_operative",+ config={+ "system_prompt": "You are a test agent.",+ "tools": ["nonexistent_tool_xyz"],+ "instruction": "test",+ },+ )+ mgr.send_message(agent["id"], "hello", mode="immediate")++ executor = AgentExecutor(manager=mgr, event_bus=EventBus())+ executor.set_system(system)++ executor.execute_tick(agent["id"])+ result_agent = mgr.get_agent(agent["id"])+ assert result_agent["status"] == "idle"+ assert result_agent["total_runs"] == 1+ mgr.close()+++def test_executor_handles_string_tools(tmp_path):+ """Executor should handle comma-separated tool string as well as list."""+ _register_agent()++ engine = FakeEngine([{"content": "test response"}])+ system = FakeSystem(engine=engine)++ mgr = AgentManager(db_path=str(tmp_path / "test.db"))+ agent = mgr.create_agent(+ "test",+ agent_type="monitor_operative",+ config={+ "system_prompt": "You are a test agent.",+ "tools": "think,calculator",+ "instruction": "test",+ },+ )+ mgr.send_message(agent["id"], "hello", mode="immediate")++ executor = AgentExecutor(manager=mgr, event_bus=EventBus())+ executor.set_system(system)++ executor.execute_tick(agent["id"])+ result_agent = mgr.get_agent(agent["id"])+ assert result_agent["status"] == "idle"+ mgr.close()