wiki-query
Margot checks the wiki first. External research only fires when the wiki can't answer — or when the answer exists but the data might be stale.
When to invoke
Before every [RESEARCH] sentinel resolution in margot_bot.handle_turn. The wiki-query result either:
- Replaces the external call (confidence=high, not time-sensitive)
- Supplements it (confidence=medium — wiki context injected alongside external findings)
- Defers entirely (confidence=low — skip wiki, go straight to external)
Algorithm
- Load
Wiki/index.md— the page map. - Identify relevant pages. LLM call: given the query, name ≤5 pages from the index that are likely to contain an answer.
- Read those pages. Load them from disk (max 5, max 1 500 chars each to bound prompt size).
- Synthesise an answer. LLM call: answer the query from the page content. Return the answer plus a confidence assessment.
- Return. Structured result with answer, pages consulted, confidence, go_external flag, and stale flag.
Confidence → go_external mapping
| Confidence | Meaning | go_external |
|---|---|---|
high |
Answer found, complete, not time-sensitive | False |
medium |
Partial answer or possibly stale | True (supplement) |
low |
Not in wiki | True (skip wiki) |
Time-sensitive topics (market data, competitor moves, pricing, regulatory) always set go_external=True regardless of confidence — the wiki is a starting point, not a substitute for Gemini grounded search on fast-moving topics.
Input schema
{
"query": "What is CCW's contract value?",
"time_sensitive": false
}
Output schema
{
"answer": "CCW signed a 12-month SaaS contract at $2,400/year on 2026-05-08.",
"pages_consulted": ["ccw.md", "businesses-overview.md"],
"confidence": "high" | "medium" | "low",
"go_external": false,
"stale": false,
"error": null
}
Python entry point
from swarm.wiki_query import query
result = query("What is CCW's contract value?", time_sensitive=False)
if not result.go_external:
# use result.answer directly
else:
# inject result.answer as context, then fire external research
Integration point in margot_bot
In handle_turn, before _run_research_batch:
from .wiki_query import query as wiki_query
wiki_result = wiki_query(research_request.topic,
time_sensitive=(research_request.depth == "quick"))
if not wiki_result.go_external and wiki_result.answer:
# substitute wiki answer — no external call needed
research_findings.append({
"topic": research_request.topic,
"depth": "wiki",
"summary": wiki_result.answer,
"error": None,
})
else:
# fire external + optionally prepend wiki context
...
Safety
- Read-only — never writes to the wiki. Use
wiki-ingestfor writes. - Read from
config.BRAIN1_WIKI_DIRonly. - Failure is always non-fatal — on error,
go_external=Trueso Margot falls through to external research.
Verification
from swarm.wiki_query import query
r = query("What is CCW's first-response SLA?")
assert r.confidence in ("high", "medium")
assert "15 min" in r.answer or "15" in r.answer
assert "ccw.md" in r.pages_consulted
r2 = query("What did Anthropic announce this week?", time_sensitive=True)
assert r2.go_external is True
References
- Wiki schema:
~/2nd Brain/2nd Brain/CLAUDE.md - Config:
swarm/config.py→BRAIN1_WIKI_DIR - Companion skills:
wiki-ingest(Wave 5),wiki-lint(Wave 5)