<- all tokdocs

Building an Open-Source Deep Research API with Multi-Agent Workflows

Watch on TikTok

View on TikTok ->

A client needed a tool that goes beyond standard web search. They wanted a fully open-source, on-premise deep research engine that could think, question, and compile detailed reports on its own. This walkthrough covers how it was built, from the multi-agent foundation to the production API.

The Multi-Agent Architecture

The system is built on a multi-agent workflow from LlamaIndex. Four specialized agents work as a research team:

  • A question agent that brainstorms what needs to be asked
  • An answer agent that scours the web for information
  • A review agent that critiques the findings for quality
  • A report agent that compiles everything into a final document

Title card showing "How I built an Open Source Deep Research API" with a developer at a multi-monitor setup

The web search was customized to target specific high-quality websites relevant to the client's industry. The agent prompts were rewritten to match the client's needs and tone.

The Iterative Loop

The real value is in the review cycle. The system generates questions, finds answers, and then the review agent evaluates the quality. If the report is not thorough enough, the review agent sends the team back for another round with more refined questions. This loop continues until the output meets a quality threshold.

Developer working at a triple-monitor desk, coding the research pipeline

Wrapping It in a Production API

After the research workflow proved solid in evaluations, it was wrapped in a FastAPI service. The API lets users start a research session, check its status (in progress or done), and retrieve the final report.

The FastAPI Swagger documentation for the Deep Research API, showing endpoints for starting research, checking status, getting results, listing sessions, canceling, and health checks

A WebSocket endpoint was added for live progress updates, so users can watch the research unfold in real time instead of polling for status.

Production Hardening

The service includes agent pooling for efficiency, error handling, timeout management, structured logging, and health checks. These are the essentials for running a multi-agent system in production without it falling over.

Developer at triple-monitor setup with caption "service is always" indicating health check monitoring

Key Takeaways

  • A multi-agent workflow (question, answer, review, report) handles iterative research better than a single-pass search
  • The review agent creates a quality feedback loop that refines results across multiple passes
  • FastAPI with WebSocket support provides both synchronous result retrieval and real-time progress streaming
  • Production concerns like agent pooling, timeouts, and health checks are essential for multi-agent services

Resources

  • LlamaIndex -- Framework providing the multi-agent workflow foundation
  • FastAPI -- Python web framework used for the API layer

Published May 25, 2026. Writeup generated from a favorited TikTok.