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
Showing only changes of commit 2f24dc1b50 - Show all commits

View file

@ -44,8 +44,20 @@ pub(crate) async fn start() -> anyhow::Result<()> {
async fn research(topic: &str) -> anyhow::Result<String> {
let client = ollama::Client::new(Nothing)?;
let findings = gather_findings(&client, topic).await?;
let report = write_report(&client, topic, &findings).await?;
Ok(report)
}
/// Wraps the tool-calling research loop in its own span so it's visible as a
/// single unit in traces, distinct from the writing phase and nesting rig's
/// own per-turn `chat`/`execute_tool` spans underneath it.
#[tracing::instrument(skip(client), fields(gen_ai.agent.name = "researcher"))]
async fn gather_findings(client: &ollama::Client, topic: &str) -> anyhow::Result<String> {
let researcher = client
.agent(RESEARCHER_MODEL)
.name("researcher")
.preamble(
"You are a meticulous research assistant. Use the search_web and fetch_page tools to \
investigate the user's topic: run several searches with varied phrasing, fetch the \
@ -59,8 +71,6 @@ async fn research(topic: &str) -> anyhow::Result<String> {
.tool(FetchPage)
.build();
tracing::info!(topic, "starting research phase");
let findings = researcher
.runner(topic)
.max_turns(MAX_RESEARCH_TURNS)
@ -68,10 +78,16 @@ async fn research(topic: &str) -> anyhow::Result<String> {
.await?
.output;
tracing::info!(findings = %findings, "research phase complete, starting writing phase");
tracing::info!(findings = %findings, "research phase complete");
Ok(findings)
}
#[tracing::instrument(skip(client, findings), fields(gen_ai.agent.name = "writer"))]
async fn write_report(client: &ollama::Client, topic: &str, findings: &str) -> anyhow::Result<String> {
let writer = client
.agent(WRITER_MODEL)
.name("writer")
.preamble(
"You turn raw research notes into a clear, well-organized report for the reader. \
Structure the report with headings, cite source URLs inline next to the claims they \