Skip to content

Personal AI, On Personal Devices

Python

feat: wire DeepResearch tools in managed agent streaming endpoint

Jon Saad-Falconadd0abde4198
diff --git a/src/openjarvis/server/agent_manager_routes.py b/src/openjarvis/server/agent_manager_routes.py
index 714a168d..02d63f12 100644
--- a/src/openjarvis/server/agent_manager_routes.py
+++ b/src/openjarvis/server/agent_manager_routes.py
@@ -207,6 +207,41 @@ def build_tools_list() -> List[Dict[str, Any]]:
return items
+def _build_deep_research_tools(
+ engine: Any,
+ model: str,
+ knowledge_db_path: str = "",
+) -> list:
+ """Build the 4 DeepResearch tools from a KnowledgeStore.
+
+ Returns an empty list if the knowledge DB does not exist.
+ """
+ from pathlib import Path
+
+ if not knowledge_db_path:
+ from openjarvis.core.config import DEFAULT_CONFIG_DIR
+ knowledge_db_path = str(DEFAULT_CONFIG_DIR / "knowledge.db")
+
+ if not Path(knowledge_db_path).exists():
+ return []
+
+ from openjarvis.connectors.retriever import TwoStageRetriever
+ from openjarvis.connectors.store import KnowledgeStore
+ from openjarvis.tools.knowledge_search import KnowledgeSearchTool
+ from openjarvis.tools.knowledge_sql import KnowledgeSQLTool
+ from openjarvis.tools.scan_chunks import ScanChunksTool
+ from openjarvis.tools.think import ThinkTool
+
+ store = KnowledgeStore(knowledge_db_path)
+ retriever = TwoStageRetriever(store)
+ return [
+ KnowledgeSearchTool(retriever=retriever),
+ KnowledgeSQLTool(store=store),
+ ScanChunksTool(store=store, engine=engine, model=model),
+ ThinkTool(),
+ ]
+
+
async def _stream_managed_agent(
*,
manager: AgentManager,
@@ -262,6 +297,12 @@ async def _stream_managed_agent(
if config.get("max_turns") is not None:
agent_kwargs["max_turns"] = config["max_turns"]
+ # Build DeepResearch tools when applicable
+ if agent_type == "deep_research":
+ dr_tools = _build_deep_research_tools(engine=engine, model=model)
+ if dr_tools:
+ agent_kwargs["tools"] = dr_tools
+
try:
agent = agent_cls(**agent_kwargs)
except TypeError as exc:
diff --git a/tests/server/test_deep_research_tools_wiring.py b/tests/server/test_deep_research_tools_wiring.py
new file mode 100644
index 00000000..2f7c6756
--- /dev/null
+++ b/tests/server/test_deep_research_tools_wiring.py
@@ -0,0 +1,46 @@
+"""Test that _build_deep_research_tools works correctly."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from unittest.mock import MagicMock
+
+import pytest
+
+from openjarvis.connectors.store import KnowledgeStore
+
+
+def test_deep_research_agent_gets_tools(tmp_path: Path) -> None:
+ """When knowledge.db exists, returns 4 tools."""
+ db_path = tmp_path / "knowledge.db"
+ store = KnowledgeStore(str(db_path))
+ store.store("test content", source="test", doc_type="note")
+
+ from openjarvis.server.agent_manager_routes import _build_deep_research_tools
+
+ tools = _build_deep_research_tools(
+ engine=MagicMock(),
+ model="test-model",
+ knowledge_db_path=str(db_path),
+ )
+
+ tool_ids = [t.tool_id for t in tools]
+ assert "knowledge_search" in tool_ids
+ assert "knowledge_sql" in tool_ids
+ assert "scan_chunks" in tool_ids
+ assert "think" in tool_ids
+ assert len(tools) == 4
+ store.close()
+
+
+def test_deep_research_tools_returns_empty_when_no_db() -> None:
+ """When knowledge.db doesn't exist, returns empty list."""
+ from openjarvis.server.agent_manager_routes import _build_deep_research_tools
+
+ tools = _build_deep_research_tools(
+ engine=MagicMock(),
+ model="test-model",
+ knowledge_db_path="/nonexistent/path/knowledge.db",
+ )
+
+ assert tools == []