feat: Deep research engine — iterative search/summarize/reflect loop (#73, #74, #75) #76

Merged
perplexity merged 1 commits from feat/deep-research into main 2026-03-20 14:49:42 -04:00
Owner

Deep Research Engine — Iterative Search/Summarize/Reflect Loop

Ports the research loop pattern from langchain-ai/local-deep-researcher (MIT) into the Matrix as a first-class capability. No LangGraph dependency.

What's New

server/research.py — Standalone research engine

  • Iterative loop: generate query → DuckDuckGo search → LLM summarize → LLM reflect on gaps → repeat
  • Async generator yields ResearchProgress at each iteration for streaming
  • Ollama HTTP client (raw, no langchain) + DuckDuckGo search (no API key required)
  • <think> token stripping for reasoning models (DeepSeek R1, Hermes, etc.)
  • Source deduplication across iterations
  • Configurable: model, ollama URL, max loops, tokens per source

server/bridge.py — Research lifecycle in CognitiveBridge

  • on_research_request() handler — validates and spawns background task
  • Each iteration: agent_behavior:ponder + bark with findings + research_progress message
  • Completion: research_complete with full markdown report + scene_add artifact + final bark
  • Concurrency guard — one active research at a time

server/gateway.py — Research message routing

  • research_request → route to target agent (like task_action)
  • research_progress / research_complete → broadcast to all browsers

PROTOCOL.md — 3 new message types documented with full specs

Tests

  • 21 new tests for the research engine (all pass)
  • Existing gateway (10/10) and bridge (8/8) tests unaffected

How It Plugs In

When Timmy is connected via the bridge, anyone can send a research_request through the gateway. Timmy's bridge spawns the research loop on local Ollama (Hermes), streams visual progress to the Matrix, and delivers the final report as a world artifact.

Closes #73, #74, #75
Advances #50 (replaces human-in-the-loop Kimi workflow with automated local research)
Advances #45 (adds 3 message types to bridge protocol — 10/12 now implemented)

## Deep Research Engine — Iterative Search/Summarize/Reflect Loop Ports the research loop pattern from [langchain-ai/local-deep-researcher](https://github.com/langchain-ai/local-deep-researcher) (MIT) into the Matrix as a first-class capability. No LangGraph dependency. ### What's New **`server/research.py`** — Standalone research engine - Iterative loop: generate query → DuckDuckGo search → LLM summarize → LLM reflect on gaps → repeat - Async generator yields `ResearchProgress` at each iteration for streaming - Ollama HTTP client (raw, no langchain) + DuckDuckGo search (no API key required) - `<think>` token stripping for reasoning models (DeepSeek R1, Hermes, etc.) - Source deduplication across iterations - Configurable: model, ollama URL, max loops, tokens per source **`server/bridge.py`** — Research lifecycle in CognitiveBridge - `on_research_request()` handler — validates and spawns background task - Each iteration: `agent_behavior:ponder` + `bark` with findings + `research_progress` message - Completion: `research_complete` with full markdown report + `scene_add` artifact + final bark - Concurrency guard — one active research at a time **`server/gateway.py`** — Research message routing - `research_request` → route to target agent (like `task_action`) - `research_progress` / `research_complete` → broadcast to all browsers **`PROTOCOL.md`** — 3 new message types documented with full specs ### Tests - 21 new tests for the research engine (all pass) - Existing gateway (10/10) and bridge (8/8) tests unaffected ### How It Plugs In When Timmy is connected via the bridge, anyone can send a `research_request` through the gateway. Timmy's bridge spawns the research loop on local Ollama (Hermes), streams visual progress to the Matrix, and delivers the final report as a world artifact. Closes #73, #74, #75 Advances #50 (replaces human-in-the-loop Kimi workflow with automated local research) Advances #45 (adds 3 message types to bridge protocol — 10/12 now implemented)
perplexity added 1 commit 2026-03-20 14:49:00 -04:00
- server/research.py: ResearchEngine with Ollama + DuckDuckGo
  - Iterative loop: generate query → search → summarize → reflect → repeat
  - Async generator yields ResearchProgress at each iteration
  - No LangGraph dependency — pure Python + httpx + duckduckgo-search
  - <think> token stripping for reasoning models (DeepSeek R1, etc.)
  - Source deduplication across iterations

- server/bridge.py: Research lifecycle handlers
  - on_research_request() — spawns background research task
  - Visual feedback each iteration (ponder, bark, progress messages)
  - Completion → research_complete + scene artifact + bark
  - Concurrency guard — one research task at a time

- server/gateway.py: Research message routing
  - research_request → route to target agent
  - research_progress/complete → broadcast to all browsers

- PROTOCOL.md: 3 new message types documented
  - research_request, research_progress, research_complete
  - Full field specs and routing rules

- server/test_research.py: 21 tests (all pass)
  - JSON extraction, thinking token stripping, formatting
  - Full loop with mocks, failure handling, deduplication

Pattern adapted from langchain-ai/local-deep-researcher (MIT license).
perplexity merged commit 9120be3794 into main 2026-03-20 14:49:42 -04:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: perplexity/the-matrix#76