A multi-agent document processing system built with DSPy. Partitions documents into per-document agents that independently evaluate and answer queries, coordinated by a master agent with query planning and reranking.
User query
-> QueryPlanner (selects relevant document agents)
-> DocumentAgents (evaluate relevance, extract answers in parallel)
-> RerankModule (reorders results by score)
-> MasterAgent (returns top answer with citations)
| Component | Description |
|---|---|
MasterAgent |
Orchestrates query flow across document agents |
QueryPlanner |
DSPy ChainOfThought module that selects which agents to involve |
DocumentAgent |
Per-document agent that evaluates queries, extracts answers, and generates responses via Claude |
RerankModule |
Reranks initial retrieval scores using Qdrant context |
RerankingOptimizer |
Uses DSPy's BootstrapFewShotWithRandomSearch to optimize reranking |
| Dependency | Purpose |
|---|---|
| DSPy | LLM orchestration and prompt optimization |
| Qdrant | Vector database for document embeddings |
| LlamaIndex | Document loading and vector store indexing |
| sentence-transformers (all-MiniLM-L6-v2) | Query encoding |
| Anthropic Claude (claude-3-haiku) | LLM for query planning, evaluation, answer generation |
| unstructured | Document parsing |
- Python >= 3.8
- Running Qdrant instance (default: localhost:6333)
ANTHROPIC_API_KEYenvironment variable
git clone https://github.com/jmanhype/DSPy-Multi-Document-Agents.git
cd DSPy-Multi-Document-Agents
pip install -r requirements.txt
# Start Qdrant (e.g., via Docker)
docker run -p 6333:6333 qdrant/qdrant
export ANTHROPIC_API_KEY="your-key"
python main.pyBy default, main.py loads documents from docs/latest.md (configurable via DOCUMENT_PATH env var).
- Documents are loaded, partitioned, embedded, and stored in Qdrant
- A
DocumentAgentis created for each document partition QueryPlanneruses ChainOfThought to select relevant agents- Selected agents evaluate the query against their content
RerankModuleadjusts scores using retrieved contextMasterAgentpicks the top-scoring agent and asks it to generate a full answer with citations
- The reranking logic is simplistic (adds context length to initial score)
- Relevance scoring uses keyword heuristics ("not relevant" / "partially relevant" string matching), not a trained classifier
- Query decomposition splits on "and"/"or" keywords only
- Similarity search uses Jaccard similarity, not semantic embeddings
- No web UI; runs as a CLI script
- The Nextra documentation site (
pages/) describes the architecture but the docs app requires separatenpm install && npm run dev
The pages/ directory contains a Nextra (Next.js) documentation site:
npm install
npm run dev
# Open http://localhost:3000MIT