This document explains how we use DSPy here, how to run it, and how to extend it.
DSPy is the primary runtime for all agents in this repo (Clarifier → Visualizer). The OpenAI Agent SDK path remains available, but DSPy can be enabled per-agent or for the entire pipeline via environment flags.
DSPy runs are evaluated via the same local eval harness (JSONL datasets + metrics) used by the rest of the repo.
pip install -r requirements.txt
pip install -r requirements-dev.txtrequirements-dev.txt includes dspy so the base install stays lightweight.
Required:
OPENAI_API_KEY
DSPy enablement:
USE_DSPY_ALL(set to1/true/yesto run the full pipeline on DSPy)USE_DSPY_CLARIFIERUSE_DSPY_PLANNERUSE_DSPY_SEARCHERUSE_DSPY_EXTRACTORUSE_DSPY_VERIFIERUSE_DSPY_WRITERUSE_DSPY_VISUALIZER
DSPy settings (global defaults):
DSPY_MODEL(defaults toOPENAI_MODELorgpt-4o-mini)DSPY_TEMPERATURE(defaults toOPENAI_TEMPERATUREor0.2)DSPY_MAX_TOKENS(defaults to1024)
Per-agent overrides (optional):
DSPY_<AGENT>_MODELDSPY_<AGENT>_TEMPERATUREDSPY_<AGENT>_MAX_TOKENS
Optimization loop bounds:
DSPY_TRAIN_SAMPLES(default: 4)DSPY_EVAL_SAMPLES(default: 6)DSPY_OPT_MAX_ROUNDS(default: 2)DSPY_OPT_MAX_LABELED_DEMOS(default: 4)DSPY_OPT_MAX_BOOTSTRAPPED_DEMOS(default: 4)DSPY_SHUFFLE_SEED(default: 42)
Clarifier:
python3 -m dspy_integration.clarifier_cli --query "AI alignment"Planner (input is clarifier context JSON):
python3 -m dspy_integration.planner_cli --input path/to/clarifier_context.jsonSearcher:
python3 -m dspy_integration.searcher_cli --input path/to/search_context.jsonExtractor:
python3 -m dspy_integration.extractor_cli --input path/to/search_output.jsonVerifier:
python3 -m dspy_integration.verifier_cli --input path/to/extract_output.jsonWriter:
python3 -m dspy_integration.writer_cli --input path/to/writer_input.jsonVisualizer (input must be report JSON):
python3 -m dspy_integration.visualizer_cli --report-json '{"title":"Demo","executive_summary":"...","key_findings":["A"],"limitations":["L"],"citations":["https://example.com"]}'export USE_DSPY_ALL=1
python3 main.py --query "Investigate RAG and hallucination in legal QA"python3 evals_cli.py --agent clarifier --engine dspy --dataset evals/datasets/clarifier.jsonl
python3 evals_cli.py --agent planner --engine dspy --dataset evals/datasets/planner.jsonl
python3 evals_cli.py --agent searcher --engine dspy --dataset evals/datasets/searcher.jsonl
python3 evals_cli.py --agent extractor --engine dspy --dataset evals/datasets/extractor.jsonl
python3 evals_cli.py --agent verifier --engine dspy --dataset evals/datasets/verifier.jsonl
python3 evals_cli.py --agent writer --engine dspy --dataset evals/datasets/writer.jsonl
python3 evals_cli.py --agent visualizer --engine dspy --dataset evals/datasets/visualizer.jsonlThis compiles an optimized DSPy module using the dataset and reports baseline vs optimized scores.
python3 -m dspy_integration.optimize_cli --agent clarifier --dataset evals/datasets/clarifier.jsonl
python3 -m dspy_integration.optimize_cli --agent visualizer --dataset evals/datasets/visualizer.jsonlArtifacts are written to evals/_artifacts/ by default (override with EVAL_ARTIFACT_DIR).
Use docs/dspy-report-template.md to record baseline/optimized deltas and action items.
evals/datasets/visualizer_components.jsonl focuses on component ordering and prop normalization.
- Add a DSPy module in
dspy_integration/<agent>.pywith arun()that returns the dataclass output. - Add a JSONL dataset in
evals/datasets/<agent>.jsonl. - Add an eval spec in
evals/<agent>_eval.pyand register it inevals/registry.py. - Update
dspy_integration/agents.pyto route the new agent. - Add a unit test in
tests/to validate the eval harness for the new agent.