5.7 KiB
Interactive Research Assistant
Research assistant powered by haiku.rag, Pydantic Graph, and AG-UI. Ask complex questions and watch the research process unfold in real-time with human-in-the-loop control.
Features
- Human-in-the-loop research: Review and modify questions at decision points, then continue searching or generate report
- Multi-iteration research graph: Automated question decomposition and parallel search
- Live state synchronization: Real-time delta updates of research progress via AG-UI protocol
- Rich reporting: Generates comprehensive research reports with findings, conclusions, and sources
Quick Start
Prerequisites
- Docker and Docker Compose
- A haiku.rag database with indexed documents
- Ollama (or configure another LLM provider)
Setup
-
Prepare your knowledge base
Option A: Create a new database
haiku-rag init --db data/haiku_rag.lancedb haiku-rag add-src document.pdf --db data/haiku_rag.lancedbOption B: Use an existing database
Set the
DB_PATHenvironment variable to point to your existing haiku.rag database:# In .env file DB_PATH=/path/to/your/existing/haiku_rag.lancedbOr export it before running docker compose:
export DB_PATH=/path/to/your/existing/haiku_rag.lancedb docker compose up --buildThe database will be mounted as read-write, so the research assistant can access all documents in your existing knowledge base.
-
Configure haiku.rag
cp haiku.rag.yaml.example haiku.rag.yaml # Edit haiku.rag.yaml to customize provider/modelSee haiku.rag configuration for details.
-
Set API keys (if using non-Ollama providers)
cp .env.example .env # Edit .env to set your API keys OPENAI_API_KEY=your-key-here ANTHROPIC_API_KEY=your-key-here DB_PATH=/path/to/your/existing/haiku_rag.lancedb # If using an existing db. -
Start the application
docker compose up --build -
Access the interface
- Frontend: http://localhost:3000
- Backend health: http://localhost:8000/health
How It Works
- Ask a question: Type your research question in the chat
- Plan phase: The research graph decomposes your question into targeted sub-questions
- Decision point: Review the proposed questions in the right panel
- Add new questions using the input field
- Remove questions you don't need
- Click Search to execute searches for pending questions
- Click Generate Report to skip to synthesis (when you have enough answers)
- Research iterations: After each search cycle, you return to a decision point where you can:
- Review collected answers
- Add follow-up questions based on findings
- Continue searching or generate the final report
- Synthesis: Generates a comprehensive research report with:
- Executive summary
- Main findings with supporting evidence
- Conclusions and recommendations
- Source citations
Architecture
Agent + Graph Pattern
This example demonstrates the agent+graph architecture pattern:
-
Conversational Agent (
agent.py):- Pydantic AI agent handles user conversations
- Decides when to invoke the research tool based on user intent
- Responds directly to greetings/casual chat without tools
-
Interactive Research Graph (haiku.rag):
- Multi-step research workflow invoked by the agent's tool
- Pauses at decision points waiting for human input via async queue
- Emits AG-UI events for real-time progress tracking
-
Decision Endpoint (
main.py):/v1/research/decidereceives human decisions from frontend- Forwards decisions to the waiting graph via
HumanDecisionqueue - Supports actions:
search,synthesize,modify_questions
-
Shared Event Stream:
AGUIEmitteris shared between agent and graph- Events from both flow through a single stream to the frontend
STATE_DELTAevents sync research state to frontend in real-time
Components
-
Backend (Python):
- Uses published
ghcr.io/ggozad/haiku.rag:latestDocker image as base agent.py: Pydantic AI agent withrun_researchtool, managesActiveResearchregistrymain.py: Custom AG-UI streaming endpoint, decision endpoint for human input- Real-time event forwarding from emitter to SSE stream
- Uses published
-
Frontend (Next.js/React):
- CopilotKit for AG-UI protocol integration
- Split-pane UI: chat on left, live research state on right
- Decision UI: question editor with add/remove, search and generate report buttons
- Real-time state synchronization via Server-Sent Events (SSE)
Configuration
Configuration is done through haiku.rag.yaml (see haiku.rag.yaml.example):
research.provider: LLM provider (default:ollama)research.model: Model name (default:gpt-oss:latest)research.max_iterations: Maximum research iterations (default:3)research.confidence_threshold: Confidence threshold for completion (default:0.8)research.max_concurrency: Parallel sub-question processing (default:1)providers.ollama.base_url: Ollama endpoint (default:http://host.docker.internal:11434)
Environment variables (see .env.example):
DB_PATH: Path to haiku.rag database (default:haiku_rag.lancedb)OPENAI_API_KEY,ANTHROPIC_API_KEY: API keys for cloud providers
For full configuration options, see haiku.rag configuration docs.