DeepTheoria is a high-fidelity, multi-agent research intelligence platform that transforms raw topics or questions into deeply researched, structured markdown reports. It handles the complete pipeline: searching the web, scraping top sources, pausing for human review (Human-in-the-Loop), drafting reports with token-by-token streaming, and iteratively critiquing and revising the output until a target quality is met.
The user interface follows a premium, warm editorial design system inspired by Mistralβfeaturing a cream/sunset canvas, high-contrast serif typography, and a vibrant sunset accent gradient.
| Architecture Map |
|---|
![]() |
graph TD
Client[Next.js Frontend] -->|1. Start topic stream /api/research/stream| API[FastAPI Server]
API -->|2. Run Graph| GatherGraph[Research Graph]
GatherGraph -->|2a. Search Node| Tavily[Tavily Search API]
GatherGraph -->|2b. Reader Node| Scraper[BeautifulSoup4 Scraper]
GatherGraph -->|3. Interrupt & Await Review| HITL[Awaiting Review State]
HITL -->|4. Stream gathered resources to UI| Client
Client -->|"5. Approve /api/research/approve/{id}"| API
API -->|6. Resume Execution| WriterNode[Writer Node]
WriterNode -->|6a. Write draft & stream tokens| Mistral[Mistral AI]
WriterNode -->|7. Critique Node| CriticNode[Critic Node]
CriticNode -->|7a. Evaluate & score| ScoreCheck{Score < 6 & revision < MAX?}
ScoreCheck -->|Yes: Revise| WriterNode
ScoreCheck -->|No: Finish| SaveDB[Save to Postgres]
SaveDB -->|8. Stream completion done| Client
Here is the step-by-step visual workflow of the DeepTheoria application in action:
| 1. Research Console (Landing Page) |
|---|
![]() |
| Features prompt suggestions and the multi-agent pipeline overview in the Warm Sunset editorial theme. |
| 2. Live Pipeline Progress (Processing Stage) |
|---|
![]() |
| Visual status indicators track the active agents as they search the web and scrape sources in real time. |
| 3. Human-in-the-Loop Review (Interrupt State) |
|---|
![]() |
| The execution flow pauses, presenting scraped metadata and characters. The user reviews and clicks "Approve" to run the writer. |
| 4. Live Token-Streaming Report (Results) |
|---|
![]() |
| Renders the generated report live using rich serif typography and clean markdown presentation. |
| 5. Automated Critique & Scorecard |
|---|
![]() |
| Displays the critique feedback, quality scores, and grading details from the Critic Agent. |
- SSE Stream (
/api/research/stream): Real-time progress updates are sent to the client via Server-Sent Events (SSE) as each pipeline step finishes, including live token-by-token report streaming from Mistral AI. - Pipeline Checkpoints (Fault Tolerance): Using LangGraph's checkpointer (
AsyncPostgresSaver), execution state is saved at each checkpoint, allowing seamless interruption and resumption.
- Interrupt State: The research graph automatically halts before the writing phase begins.
- Interactive Approval: Users can review the raw search results, scraped text, and active URLs. Once satisfied, they click "Approve" to send a POST request to
/api/research/approve/{thread_id}, releasing the block and initiating report generation.
- Automatic Iterative Refinement: The writer drafts the report in markdown. A critic node evaluates the report's quality and outputs a score (out of 10) and qualitative feedback.
- Target-Quality Threshold: If the score is less than 6 and the revision budget hasn't been exhausted, the graph automatically loops back to the writer node, appending the critique to the prompt for a target revision.
- PostgreSQL Store: All completed research recordsβcontaining the original topic, search results, scraped content, final report, and critic feedbackβare stored persistently in a database table.
- Interactive Dashboard: Users can load, read, and delete historical research runs directly from the UI.
- Monorepo Manager: Turborepo & Bun
- Frontend: Next.js 15+ (TypeScript, App Router), Tailwind CSS (v4)
- Backend: Python 3.10+, FastAPI, LangGraph, LangChain, asyncpg, psycopg
- Database: PostgreSQL (handling both LangGraph checkpoints and history storage)
- AI Models & Engines:
- Core LLM & Intelligence: Mistral AI (
mistral-large-latestor configured model) - Search Engine: Tavily API (for structured, AI-optimized web queries)
- Scraper: BeautifulSoup4 (
bs4) for fetching clean text from URLs
- Core LLM & Intelligence: Mistral AI (
Ensure you have the following installed:
- Bun (for frontend and package manager)
- Python 3.10+ (for backend)
- PostgreSQL (running locally or a cloud database URL)
-
Database Setup: Create a PostgreSQL database (e.g., named
deeptheoria). -
Backend Configuration: Create a
.envfile inapps/backend/and populate it with your keys:MISTRAL_API_KEY=your_mistral_api_key_here MISTRAL_MODEL=mistral-large-latest TAVILY_API_KEY=your_tavily_api_key_here DATABASE_URL=postgresql+asyncpg://username:password@localhost:5432/deeptheoria
-
Backend Dependencies: Navigate to the backend directory and set up a Python virtual environment:
cd apps/backend python -m venv .venv # Activate environment: # On Windows (PowerShell) .venv\Scripts\activate # On macOS/Linux source .venv/bin/activate # Install dependencies: pip install -r requirements.txt
From the root directory of the project, run all applications in development mode simultaneously:
bun dev- Frontend: Running on http://localhost:3000
- Backend: Running on http://localhost:8000
Create apps/backend/.env to configure the backend:
| Variable | Required | Default / Recommendation | Description |
|---|---|---|---|
MISTRAL_API_KEY |
Yes | β | Mistral AI API key |
MISTRAL_MODEL |
No | mistral-large-latest |
Mistral model used for report generation and critiquing |
TAVILY_API_KEY |
Yes | β | Tavily Search API key |
DATABASE_URL |
Yes | β | PostgreSQL connection DSN (postgresql+asyncpg://...) |
DeepTheoria/
βββ apps/
β βββ backend/
β β βββ db/ # Database handlers
β β β βββ history.py # asyncpg-based PostgreSQL CRUD operations
β β βββ graph/ # LangGraph orchestration
β β β βββ graph.py # Compiles the StateGraph with Postgres Saver
β β β βββ nodes.py # Agent nodes (search, reader, writer, critic)
β β β βββ prompt.py # Writer and Critic prompt templates
β β β βββ state.py # Typed ResearchState representation
β β βββ tools/ # Scraping and search tools
β β β βββ scraper.py # BeautifulSoup4 scraping handler
β β β βββ search.py # Tavily Search client wrapper
β β βββ config.py # Pydantic Settings configuration parser
β β βββ main.py # FastAPI server and SSE router
β β βββ requirements.txt # Backend Python dependencies
β βββ frontend/
β βββ app/ # Next.js Page components & stylesheets
β β βββ history/ # Interactive research history viewer
β β βββ globals.css # Mistral-inspired design tokens and styling
β β βββ layout.tsx # Page wrappers and sidebar layouts
β β βββ page.tsx # Interactive research console
β βββ components/ # Modular UI components
β β βββ ui/ # Shared base elements (button, dialog, input, etc.)
β β βββ HistoryCard.tsx # Sidebar card for historical runs
β β βββ HumanReview.tsx # HITL inspection and approval pane
β β βββ LiveReport.tsx # Live markdown text streamer
β β βββ PipelineProgress.tsx # Horizontal progress flow tracker
β β βββ ReportTabs.tsx # Tabbed interface for Report, Scraped data, and Critique
β β βββ ResearchForm.tsx # Initial topic submit input
β β βββ ScoreCard.tsx # Graphic display of the critic's scores
β β βββ Sidebar.tsx # History and navigation drawer
β βββ lib/ # API fetching utilities
β β βββ api.ts # EventSource and POST helpers
β β βββ parse-feedback.ts # String parser for critique scores
β β βββ types.ts # TypeScript definitions
β βββ package.json # Frontend packages
βββ package.json # Root Bun workspaces manifest
βββ turbo.json # Turborepo task pipeline configuration
DeepTheoria's UI is designed with a premium, Warm Sunset editorial theme inspired by Mistral AI:
- Serif Elegance: Titles and major headers render in the high-contrast
EB Garamondserif typeface, giving research reports a classic, literary publication feel. - Warm Canvas: A warm-cream page background (
#fbf9f8) paired with off-black text (#1b1c1c) reduces eye strain for comfortable reading. - Sunset Accents: Key interactive items and primary buttons leverage a vibrant orange primary accent (
#ae3200) and a gradient sunset stripe (#3a0b00to#ffdbd0) for a modern aesthetic. - Structural Lines: Grid dividers and containers utilize thin, clean hairline borders (
#e5e5e5) to elevate content structure cleanly without heavy box-shadows.





