Skip to content

Personal AI, On Personal Devices

Python

feat: rewrite DeepResearch system prompt, wire SQL + scan + think tools, increase max_turns to 8

Jon Saad-Falcona1626960c1dd
diff --git a/src/openjarvis/agents/deep_research.py b/src/openjarvis/agents/deep_research.py
index 64792319..0d7c4a32 100644
--- a/src/openjarvis/agents/deep_research.py
+++ b/src/openjarvis/agents/deep_research.py
@@ -32,25 +32,48 @@ def _tc_args(tc: dict) -> str:
DEEP_RESEARCH_SYSTEM_PROMPT = """\
/no_think
-You are a deep research agent. Your job is to search the user's personal \
-knowledge base thoroughly and produce a well-cited narrative report.
+You are a deep research agent with access to a personal knowledge base \
+containing emails, messages, meeting notes, documents, and notes.
-## Instructions
+## Your Tools
-1. Use the **knowledge_search** tool to search ingested personal data \
-(emails, Slack messages, documents, notes). Make multiple searches with \
-different queries to cross-reference information across sources.
-2. Use the **think** tool to reason between searches -- plan your next \
-query, evaluate what you have found so far, and identify gaps.
-3. After gathering enough evidence, produce a final narrative answer \
-with inline citations in the format: [source] title -- author
-4. Include a **Sources** section at the end listing all referenced sources.
+- **knowledge_search**: BM25 keyword search. Best for finding specific topics, \
+names, or phrases. Use filters (source, author, since, until) to narrow results.
+
+- **knowledge_sql**: Run read-only SQL against the knowledge_chunks table. \
+Schema: knowledge_chunks(id, content, source, doc_type, doc_id, title, \
+author, participants, timestamp, thread_id, url, metadata, chunk_index). \
+Best for counting, ranking, and aggregation. \
+Example: SELECT author, COUNT(*) as n FROM knowledge_chunks \
+WHERE source='imessage' GROUP BY author ORDER BY n DESC LIMIT 10
+
+- **scan_chunks**: Semantic search — feeds chunks to an LM that reads the \
+actual text looking for relevant information. Use when keyword search returns \
+nothing useful or when you need semantic matching (e.g. searching for 'VCs' \
+when text says 'fundraising round'). Slower but catches what BM25 misses.
+
+- **think**: Reasoning scratchpad. Use between searches to plan your next \
+query, evaluate findings so far, and identify gaps.
+
+## Strategy
+
+1. Start with **think** to plan your approach — which tools suit this query?
+2. For "who/what/how many" queries → use **knowledge_sql** with GROUP BY
+3. For specific topics or names → use **knowledge_search**
+4. If keyword search returns nothing useful → try **scan_chunks** with filters
+5. Cross-reference across sources (emails, messages, meeting notes)
+6. After gathering evidence → write a cited narrative report
+
+## Citation Format
+
+Cite sources as: [source] title -- author
+End with a Sources section listing all referenced items.
## Rules
- Always cite your sources. Never present information without attribution.
- Make at least two searches to cross-reference across different sources.
-- If a search returns no results, try rephrasing the query.
+- If a search returns no results, try a different tool or rephrase the query.
- Prefer specificity: filter by source, author, or date when appropriate.
- Your final answer should be a coherent narrative, not a list of raw results."""
@@ -60,7 +83,7 @@ class DeepResearchAgent(ToolUsingAgent):
"""Multi-hop research agent with native function calling and citations."""
agent_id = "deep_research"
- _default_max_turns = 5
+ _default_max_turns = 8
_default_temperature = 0.3
_default_max_tokens = 4096
diff --git a/src/openjarvis/cli/deep_research_setup_cmd.py b/src/openjarvis/cli/deep_research_setup_cmd.py
index 99964f11..5e9af601 100644
--- a/src/openjarvis/cli/deep_research_setup_cmd.py
+++ b/src/openjarvis/cli/deep_research_setup_cmd.py
@@ -267,6 +267,9 @@ def _launch_chat(store: KnowledgeStore, console: Console) -> None:
from openjarvis.connectors.retriever import TwoStageRetriever
from openjarvis.engine.ollama import OllamaEngine
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
console.print("\n[bold]Setting up Deep Research agent...[/bold]")
@@ -290,20 +293,26 @@ def _launch_chat(store: KnowledgeStore, console: Console) -> None:
)
return
- # Retriever + tool
+ # Tools
retriever = TwoStageRetriever(store)
- search_tool = KnowledgeSearchTool(retriever=retriever)
+ tools = [
+ KnowledgeSearchTool(retriever=retriever),
+ KnowledgeSQLTool(store=store),
+ ScanChunksTool(store=store, engine=engine, model=_OLLAMA_MODEL),
+ ThinkTool(),
+ ]
# Agent
agent = DeepResearchAgent(
engine=engine,
model=_OLLAMA_MODEL,
- tools=[search_tool],
+ tools=tools,
interactive=True,
)
console.print(
f"[green]Ready![/green] Using [bold]{_OLLAMA_MODEL}[/bold] via Ollama.\n"
+ "Tools: knowledge_search, knowledge_sql, scan_chunks, think\n"
"Type your research question. Type [bold]/quit[/bold] to exit.\n"
)
diff --git a/tests/agents/test_deep_research.py b/tests/agents/test_deep_research.py
index 31b0400b..3c712872 100644
--- a/tests/agents/test_deep_research.py
+++ b/tests/agents/test_deep_research.py
@@ -173,6 +173,6 @@ def test_agent_system_prompt_mentions_research(mock_engine, store):
def test_agent_defaults():
"""Verify agent_id, default max_turns, temperature, max_tokens."""
assert DeepResearchAgent.agent_id == "deep_research"
- assert DeepResearchAgent._default_max_turns == 5
+ assert DeepResearchAgent._default_max_turns == 8
assert DeepResearchAgent._default_temperature == 0.3
assert DeepResearchAgent._default_max_tokens == 4096