A collection of multi-agent systems implemented with the DSPy framework.
- Python 3.12 or higher
- Git
-
Clone the repository:
git clone https://github.com/Archelunch/awesome-dspy-agents cd awesome-dspy-agents -
Install Poetry (if not already installed):
pip install poetry
-
Install dependencies:
poetry install
-
Set up environment variables: Set your API keys for the language model providers you want to use:
export GEMINI_API_KEY=your_gemini_api_key_here export OPENAI_API_KEY=your_openai_api_key_here # Add other provider keys as needed
-
Verify installation:
poetry run dspy-agents --help
-
Optional: Install shell completion:
poetry run dspy-agents --install-completion
-
Arachne - DSPy-native autonomous agent runtime with graph weaving, parallel wave execution, triangulated evaluation, and self-healing.
These are the built-in patterns. Use the CLI to explore and run them.
| Pattern | Description | Strengths | Weaknesses |
|---|---|---|---|
| debate | Multi‑Agent Debate with a Judge. Two agents argue iteratively; an optional judge evaluates progress and extracts the final answer. | Strong adversarial reasoning; adaptive early stop; ReAct tool support. | Higher token usage; needs careful judge configuration. |
| addition_by_subtraction | Addition‑by‑Subtraction collaboration. Addition expands details; Subtraction removes redundancy and feeds back; early exit when stable. | Concise refined answers; low iteration count by default (M≤2); ReAct tool support. | Can miss alternative directions; relies on good subtraction feedback. |
Related work:
Encouraging Divergent Thinking in Large Language Models through Multi-Agent Debate: https://arxiv.org/abs/2305.19118
(Perhaps) Beyond Human Translation: Harnessing Multi-Agent Collaboration for Translating Ultra-Long Literary Texts: https://arxiv.org/abs/2305.19118
Tools are available to ReAct modules across patterns via a shared registry. List tools and inspect details:
poetry run dspy-agents tools
poetry run dspy-agents tools --describe read_file_attachment- math_eval: Evaluate a simple Python math expression safely; returns string.
- word_count: Count words in text; returns string number.
- ascii_to_png: Render ASCII text into a PNG (
dspy.Image) for visual reasoning. - list_files: List absolute file paths under a directory (sandboxed).
- read_file_attachment: Return an
Attachmentsobject for a local file (sandboxed). - write_file: Write text to a local file path; returns absolute path (sandboxed).
Sandboxing: File tools are restricted to allowed directories. Use --allow-path /abs/dir to opt‑in per run (can repeat).
Install and run with Poetry:
poetry install
poetry run dspy-agents --help
poetry run dspy-agents --install-completion # optional shell completionSet provider credentials via environment variables (example):
export GEMINI_API_KEY=... # for Gemini
export OPENAI_API_KEY=... # for OpenAIDiscover:
poetry run dspy-agents list
poetry run dspy-agents describe debate
poetry run dspy-agents configs debate
poetry run dspy-agents tools
poetry run dspy-agents tools --pattern debate
poetry run dspy-agents tools --describe ascii_to_pngRun patterns:
# default config of the pattern
poetry run dspy-agents run debate "Is RLHF always beneficial?"
# custom config
poetry run dspy-agents run debate -c awesome_dspy_agents/patterns/debate/config.yaml "Debate topic"
# override nested config values at runtime (typed casting: bool/int/float)
poetry run dspy-agents run debate "Topic" --set debate.max_iterations=3 --set debate.debate_level=2 --set judge.module_type=react
# interactive guided run with arrow-key selection
poetry run dspy-agents interactiveJSON output and session save/replay:
# Emit machine-readable JSON and save the full session
poetry run dspy-agents run debate "Is RLHF always beneficial?" --json --save runs/rlhf.json
# Replay a saved session locally without model calls
poetry run dspy-agents replay runs/rlhf.jsonCompare patterns on the same topic:
poetry run dspy-agents compare debate addition_by_subtraction "What is chain-of-thought?" --metric jaccardVersion and sandbox:
poetry run dspy-agents version
poetry run dspy-agents run addition_by_subtraction "Summarize file" --allow-path . --set abs.max_iterations=2During runs you will see per-iteration exchanges (debate or addition/subtraction), optional judge evaluations, and a final decision. Tool usage is summarized under each iteration.
Configuration is layered and typed:
- Pattern default config (e.g.,
patterns/debate/config.yaml). - User-provided file via
-c/--config. - CLI overrides via
--set a.b=value(auto‑caststrue/false, integers, and floats). - Environment variable expansion inside YAML values:
${OPENAI_API_KEY}.
Minimal examples:
# debate/config.yaml (excerpt)
default_lm:
provider: gemini
model: gemini-2.5-flash-preview-09-2025
api_key_env: GEMINI_API_KEY
agents:
affirmative:
persona: "Optimistic, evidence-driven."
module_type: react
tools: ["ascii_to_png", "read_file_attachment", "list_files"]
negative:
persona: "Rigorous skeptic."
module_type: react
tools: ["ascii_to_png", "read_file_attachment", "list_files"]
judge:
module_type: react
tools: ["write_file"]
debate:
max_iterations: 5
debate_level: 2
adaptive_break: true# addition_by_subtraction/config.yaml (excerpt)
default_lm:
provider: gemini
model: gemini-2.5-flash-preview-09-2025
api_key_env: GEMINI_API_KEY
agents:
addition:
persona: "Expand relevant information and synthesize details."
module_type: react
tools: ["ascii_to_png", "read_file_attachment", "list_files", "math_eval", "word_count"]
subtraction:
persona: "Remove redundancy and provide clear feedback."
module_type: react
tools: ["ascii_to_png", "read_file_attachment", "list_files", "math_eval", "word_count"]
abs:
max_iterations: 2
early_exit: trueTips:
- Point to a custom config:
-c path/to/config.yaml. - Override nested values at runtime (typed):
--set debate.max_iterations=3 --set judge.module_type=react. - Per‑agent LM: set
agents.<name>.lmblock withprovider/model/api_base/api_key(_env). - File tools are sandboxed; add
--allow-path /abs/dirto enable local file access.
Run Debate with a custom judge and fewer iterations:
poetry run dspy-agents run debate "When to use CoT?" \
--set debate.max_iterations=3 \
--set judge.module_type=reactRun ABS with early exit disabled and save JSON:
poetry run dspy-agents run addition_by_subtraction "Summarize the paper" \
--set abs.early_exit=false --json --save runs/abs.jsonUse a local file during a run (sandboxed):
poetry run dspy-agents run addition_by_subtraction "Summarize the attached doc" \
--allow-path "$PWD" \
--set agents.addition.tools="[read_file_attachment]"This collaboration uses two agents only: Addition (expands and aggregates relevant details) and Subtraction (removes redundancy and provides feedback). It iterates up to abs.max_iterations with an early-exit when no further revision is needed.
- Default config:
awesome_dspy_agents/patterns/addition_by_subtraction/config.yaml - Supports tools via ReAct (same registry as debate). Tools used are rendered in TUI under each iteration.
Examples:
poetry run dspy-agents describe addition_by_subtraction
poetry run dspy-agents configs addition_by_subtraction
poetry run dspy-agents run addition_by_subtraction "Summarize the key ideas from the attached document"
# Override ABS parameters
poetry run dspy-agents run addition_by_subtraction "Instruction" --set abs.max_iterations=2 --set abs.early_exit=trueTUI displays two columns: Addition and Subtraction, plus a Feedback panel each iteration. Tool usage events are summarized below the panels.
Note: Early exit happens when subsequent additions stabilize. Default maximum iterations M=2 (configurable via abs.max_iterations).
This section documents how to extend and maintain the CLI and pattern ecosystem.
awesome_dspy_agents/
cli.py # CLI entrypoint (Typer + Rich)
config.py # AppConfig and LM settings
tools/
registry.py # Global tool registry (shared for all patterns)
ascii_to_png.py # Example image tool
patterns/
interface.py # AgentPattern protocol and discovery
debate/
pattern.py # DebatePattern + MADFramework
signatures.py # DSPy signatures
config.yaml # Default config
addition_by_subtraction/
pattern.py # Addition-by-Subtraction Pattern + ABSFramework
signatures.py # DSPy signatures
config.yaml # Default config
- Prefer typed configuration via
AppConfigand validated YAML with env-var expansion (${VAR}). - Keep tool implementations deterministic and side-effect minimal; log via
mad.tools. - Keep per-pattern logic inside
patterns/<name>/pattern.py; expose aget_pattern()factory. - Use Rich tables and panels for readable CLI output; avoid noisy logs by default.
- Support per-agent LM configuration (provider/model/api_base/api_key) per DSPy conventions.
- Create a new folder under
awesome_dspy_agents/patterns/<your_pattern>/with at least:pattern.py: implement your DSPy modules and wrap them in a class that implementsAgentPattern.config.yaml: default configuration for the pattern (agents, judge, debate params, etc.).signatures.pyas needed.
- In
pattern.py, implement:class YourPattern(AgentPattern)with:name: a unique stringdescribe(self) -> str: short Markdown descriptiondefault_config_path(self) -> Path | Noneavailable_configs(self) -> Iterable[Path]: include default + optionalscenarios/*.yamlavailable_tools(self) -> Iterable[str]: the tool names used by defaultavailable_scripts(self) -> dict[str, str]: mapping of script name to description (MIPRO/GEPA)run(self, topic, config_path, overrides=None, on_iteration=None) -> dict- Configure default LM if provided; construct your DSPy program; call
on_iterationafter each step.
- Configure default LM if provided; construct your DSPy program; call
def get_pattern() -> AgentPattern: return YourPattern()
- The CLI will discover it automatically via
find_patterns()ifpattern.pyexportsget_pattern().
Example run implementation sketch:
def run(self, topic, config_path, overrides=None, on_iteration=None):
cfg = load_config(str(config_path))
if cfg.default_lm:
dspy.configure(lm=build_lm(cfg.default_lm))
# build modules based on cfg; call on_iteration(i, exchange, history)
final = program(...)
return {"final_answer": final.final_answer, "justification": final.justification}- Implement a pure function in
awesome_dspy_agents/tools/*.py. - Register it in
awesome_dspy_agents/tools/registry.py:
from awesome_dspy_agents.tools.registry import registry
def my_tool(arg1: str) -> str:
return arg1.upper()
registry.register("my_tool", my_tool)- Reference the tool by name in pattern configs (for ReAct tools) or in code:
agents:
affirmative:
module_type: react
tools: ["my_tool"]Guidelines:
- Keep tool I/O small; return primitives,
dspy.Imagefor images orAttachmentsfor other files.
- Layering: default pattern config -> user-provided file (
-c) -> CLI overrides (--set a.b=val). - Use env var placeholders in YAML (
${GEMINI_API_KEY}) to avoid committing secrets. - For local models (Ollama, vLLM), set
api_baseandapi_keyin the config.
- LLM calls are logged under
mad.llmrotating files inpatterns/logs/. - Tool calls are logged under
mad.toolsrotating files in the same directory.
- Add Addition-by-Subtraction pattern
- Add tools
- Add MAPS pattern
- Optional token streaming via
dspy.streamifywith a--streamflag. - Built-in optimization scripts (MIPRO/GEPA) surfaced in
scriptscommand. - Integration with MLFlow
- Session profiles (token counts, latency) and
--profileflag. - Batch runs (
run-batch --topics file.txt --concurrency N). - Add tests
- More examples
- More tools
- Improve agents communication