Deep research agentic loop with rig AgentRunner + Gemma models #2

Merged
schaefera merged 4 commits from worktree-deep-research-agent into master 2026-08-14 17:08:01 +00:00
Collaborator

Summary

  • Pins rig to the newest published crates.io release (0.41.0) instead of the git branch = "main" dependency, and adapts swear_cleanup/revise.rs to that release's API (OneOrMany::first() returns T directly; raw_completion folded into CompletionResponse::raw_response).
  • Adds src/deep_research/ — a lean, three-agent research pipeline built on rig's AgentRunner tool-calling loop and typed Extractor, using local Gemma models via Ollama for different sub-tasks:
    • researcher (gemma4:26b) — drives rig's tool-calling loop (agent.runner(topic).max_turns(12).run()) with two #[rig::tool_macro] tools: search_web (DuckDuckGo HTML search, no API key) and fetch_page (fetch + strip to readable text). Cross-checks claims across sources and dumps raw findings.
    • reviewer (gemma4-e4b, fresh context) — uses rig's typed Extractor to force a structured submit(Review) call judging whether the findings' conclusions are actually backed by their cited sources, split into solid_findings to keep and gaps to close.
    • writer (gemma4-e4b) — turns approved findings into a structured, source-cited report.
  • research() is a plain bounded loop (for round in 1..=MAX_RESEARCH_ROUNDS) — matches rig's own workflow guidance ("the least agentic design that solves your problem"): code stays in control of the retry/stop decision, feeding the reviewer's solid_findings/gaps into the next round's task so the researcher builds on what worked instead of restarting blind.
  • Custom #[tracing::instrument] spans wrap each phase (gather_findings/review_findings/write_report), nesting rig's own chat/execute_tool spans underneath; agents are named (.name(...)) so gen_ai.agent.name is attributable instead of "Unnamed Agent".

Test plan

  • cargo build — clean, no errors
  • cargo clippy --all-targets — no warnings on new code
  • Live end-to-end runs against local Ollama (gemma4:26b, gemma4-e4b) verifying: tool calls fire correctly, reviewer approves/rejects with structured feedback, retry loop reruns research with feedback folded in, final report includes headings and inline source citations
## Summary - Pins `rig` to the newest published crates.io release (`0.41.0`) instead of the `git branch = "main"` dependency, and adapts `swear_cleanup/revise.rs` to that release's API (`OneOrMany::first()` returns `T` directly; `raw_completion` folded into `CompletionResponse::raw_response`). - Adds `src/deep_research/` — a lean, three-agent research pipeline built on rig's `AgentRunner` tool-calling loop and typed `Extractor`, using local Gemma models via Ollama for different sub-tasks: - **`researcher`** (`gemma4:26b`) — drives rig's tool-calling loop (`agent.runner(topic).max_turns(12).run()`) with two `#[rig::tool_macro]` tools: `search_web` (DuckDuckGo HTML search, no API key) and `fetch_page` (fetch + strip to readable text). Cross-checks claims across sources and dumps raw findings. - **`reviewer`** (`gemma4-e4b`, fresh context) — uses rig's typed `Extractor` to force a structured `submit(Review)` call judging whether the findings' conclusions are actually backed by their cited sources, split into `solid_findings` to keep and `gaps` to close. - **`writer`** (`gemma4-e4b`) — turns approved findings into a structured, source-cited report. - `research()` is a plain bounded loop (`for round in 1..=MAX_RESEARCH_ROUNDS`) — matches rig's own workflow guidance ("the least agentic design that solves your problem"): code stays in control of the retry/stop decision, feeding the reviewer's `solid_findings`/`gaps` into the next round's task so the researcher builds on what worked instead of restarting blind. - Custom `#[tracing::instrument]` spans wrap each phase (`gather_findings`/`review_findings`/`write_report`), nesting rig's own `chat`/`execute_tool` spans underneath; agents are named (`.name(...)`) so `gen_ai.agent.name` is attributable instead of `"Unnamed Agent"`. ## Test plan - [x] `cargo build` — clean, no errors - [x] `cargo clippy --all-targets` — no warnings on new code - [x] Live end-to-end runs against local Ollama (`gemma4:26b`, `gemma4-e4b`) verifying: tool calls fire correctly, reviewer approves/rejects with structured feedback, retry loop reruns research with feedback folded in, final report includes headings and inline source citations
claude-bot added 3 commits 2026-08-14 10:59:53 +00:00
Pins rig to the newest published crates.io release (0.41.0) instead of
the git main branch, and adapts swear_cleanup's revise.rs to that
release's API (OneOrMany::first() returns T directly, raw_completion
folded into CompletionResponse::raw_response).

The research agent (gemma4:26b) drives rig's AgentRunner tool-calling
loop with two lean #[rig::tool_macro] tools — a DuckDuckGo HTML search
and a page-text fetcher — to gather and cross-check findings. A second
agent (gemma4-e4b) turns those findings into a structured report; the
smaller/faster model suffices there since it's reformatting already-
digested notes rather than doing multi-step research reasoning.
Agents were showing up as "Unnamed Agent" in rig's built-in gen_ai.*
spans. Naming them via .name(...) fixes that, and splitting the two
phases into #[tracing::instrument]-annotated functions wraps rig's
per-turn chat/execute_tool spans in a parent span per phase, making
the trace tree legible instead of a flat stream of chat calls.
Adds a reviewer step (gemma4-e4b, fresh context) between gathering and
writing: it uses rig's typed Extractor to judge whether the findings'
conclusions actually follow from their cited sources, rather than
relying on free-text parsing. research() is now a plain bounded loop —
"the least agentic design that solves the problem", per rig's own
workflow guidance — that reruns the researcher with the reviewer's
solid_findings/gaps feedback folded into the next round's task until
it approves or MAX_RESEARCH_ROUNDS runs out.
schaefera added 1 commit 2026-08-14 17:06:23 +00:00
Interpolates today's date into the researcher's preamble so it can judge
source freshness instead of relying on training-cutoff knowledge, and
asks it to cite facts with bracketed footnote numbers backed by a
Sources list, which the writer agent is now instructed to preserve
through to the final report.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
schaefera merged commit 91e04ea36d into master 2026-08-14 17:08:01 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: schaefera/doubleo7#2
No description provided.