DSPy

Active
GitHub Python MIT

Description

DSPy is a declarative LLM programming framework focused on optimizable prompts and program structure, suitable for complex agent workflows.

Key Features

  • Declarative LLM programming — Define LM call logic in Python code instead of prompts for modular AI system construction
  • Automatic prompt optimization — DSPy Compiler automatically optimizes prompts and few-shot examples without manual tuning
  • Modular pipeline composition — Freely combine ChainOfThought, ReAct, multi-hop and other modules for complex reasoning chains
  • RAG pipeline support — Built-in retrieval-augmented generation pipelines with vector retrieval, reranking components
  • Agent loop framework — Build agent loops orchestrating tool calls, reasoning, and retrieval as optimizable programs
  • Differentiable weight optimization — Fine-tune LLMs with simultaneous optimization of prompts and model weights

Use Cases

💡 Build classification and information extraction pipelines — Define classifiers declaratively and auto-optimize accuracy via Compiler
💡 Multi-step RAG systems — Orchestrate retrieval, reranking, generation steps with automatic prompt optimization per step
💡 Agent tool-calling flows — Orchestrate tool selection, parameter extraction, result integration as optimizable agent pipelines
💡 Academic research and benchmarks — Rapidly build NLP task pipelines for systematic optimization and evaluation

Strengths & Limitations

Strengths

  • Actively maintained, recent updates
  • High community interest (37.3k stars)
  • Permissive open-source license (MIT)
  • Established track record (3 years in production)

Quick Start

pip install dspy

import dspy

# Configure your LM
dspy.configure(lm=dspy.LM('openai/gpt-4o-mini'))

# Define a simple module
class RAG(dspy.Module):
    def __init__(self, passages_per_query=3):
        self.retrieve = dspy.Retrieve(k=passages_per_query)
        self.generate = dspy.ChainOfThought('context, question -> answer')

    def forward(self, question):
        context = self.retrieve(question).passages
        return self.generate(context=context, question=question)

rag = RAG()
result = rag(question='What is DSPy?')
print(result.answer)

Related Projects

forge

2.2k · Python
Active A

Forge is a self-hosted LLM tool-calling framework for function calling and multi-step agentic workflows using local models like Ollama and llamafile.

self-hostedtool-callingfunction-calling +4
  • · Proxy server mode drops guardrails into any OpenAI-compatible or Anthropic client without code changes
  • · Rescue parsing handles malformed tool calls from Mistral, Qwen, and fenced-JSON formats automatically
  • · WorkflowRunner with SlotWorker provides priority-queued GPU access for multi-agent architectures

TaskWeaver

6.2k · Python
Stale B

TaskWeaver is Microsoft's open-source code-interpreter-style agent framework, suitable for data analysis and complex task automation.

microsoftagentcode-interpreter +1
  • · Code-first agent framework: interprets user requests through code snippets with plugin-based execution
  • · Stateful execution preserving both chat history and code execution history including in-memory data
  • · Rich data structure support: works with DataFrames and complex Python data types instead of plain strings

Patchwork

1.6k · Python
Active B

Agentic AI framework for enterprise workflow automation. Uses LLM-powered pipelines for code reviews, DevOps, and other enterprise tasks.

automationworkflowagent +2
  • · Reusable atomic Steps for creating PRs, committing changes, calling LLMs, and more
  • · Customizable Prompt Templates optimized for library updates, code generation, and vulnerability remediation
  • · Patchflows combining Steps and Prompts for PR reviews, code fixing, and documentation automation

Agently

1.6k · Python
Active A

A GenAI application development framework that simplifies agent interaction with structured data and chained-calls syntax, using event-driven flow for complex logic.

agentpythonframework +1
  • · Structured output control with framework-guaranteed schemas, required field extraction, and retry validation
  • · Runtime Skills system for discovering, installing, and executing MCP/script capabilities on demand
  • · TriggerFlow event-driven workflows with fan-out, pause/resume, save/load, and sub-flow support

Related Articles