Guide · Agent skill
How to use the DSPy agent skill: install, trigger and examples
Updated · written with AI from the project's own documentation and checked against our catalogue data
The DSPy agent skill gives an AI agent working knowledge of DSPy, Stanford NLP's Python framework for programming language models declaratively. It is for Python developers who want to build multi-step LLM pipelines, RAG systems or tool-using agents without hand-writing every prompt. After this guide you will know what the skill covers, how to install it, how to ask for DSPy help in plain language, and what to check before running the code it produces.
Quick start
- 1Download and unzip the skill. Download the ZIP from this page and unzip it so the dspy folder contains SKILL.md and the references folder.
- 2Place the folder. Move the folder into ~/.claude/skills/ for personal use or into a project's .claude/skills/ folder, or upload the ZIP under Settings → Capabilities → Skills.
- 3Install dspy. Run pip install dspy, adding the provider extra you need such as [openai] or [anthropic].
- 4Set up a language model key. Provide an OpenAI or Anthropic API key, for example through an environment variable, so the examples can call the model.
- 5Ask for what you need. Describe your task in plain language and mention DSPy, your data and any metric you have.
- 6Review and run the code. Read the generated code, run it on a small sample, and check outputs before using them in production.
What does the DSPy skill make the agent do?
An agent skill is a folder of instructions and reference files that Claude loads when a task matches it. This one teaches the agent to use DSPy. Instead of writing prompts by hand, the agent defines input/output signatures and modules such as dspy.Predict, dspy.ChainOfThought and dspy.ReAct, then uses optimizers that tune prompts or few-shot examples from a labelled training set.
The skill also covers multi-step pipelines and retrieval-augmented (RAG) systems. Its files are reference documentation and code examples; they do not contain executable scripts of their own.
- Signatures: define a task as inputs and outputs, inline or as a class.
- Modules: Predict, ChainOfThought, ReAct and ProgramOfThought.
- Optimizers: BootstrapFewShot, MIPRO, BootstrapFinetune and others described in the optimizer reference.
- Pipelines and RAG: composing modules into a custom dspy.Module with a retriever.
How do you install the DSPy skill?
Download the skill ZIP from this page and unzip it. For a personal install, place the unzipped folder in ~/.claude/skills/. To scope it to one project, place it in that project's .claude/skills/ folder.
You can also upload the ZIP in the Claude apps under Settings → Capabilities → Skills.
- Personal: ~/.claude/skills/
- Project only: .claude/skills/ inside your project
- Claude apps: Settings → Capabilities → Skills, then upload the ZIP
Install the DSPy Python package
The skill's examples need the dspy package. The source lists the stable release, the development version from GitHub, and provider extras. Install the one you need in the Python environment where you will run the code.
pip install dspy
# With specific LM providers
pip install dspy[openai] # OpenAI
pip install dspy[anthropic] # Anthropic Claude
pip install dspy[all] # All providersHow do you trigger the skill with a natural request?
You do not need a special command. Describe the task in plain language and mention DSPy or the kind of work it covers, such as optimizing prompts, building a RAG system or writing a multi-step pipeline. The agent will load the skill when the request matches its description.
Good requests name the goal, the data you have and the output you want. Include a metric if you have one, since the optimizers need it.
- Use DSPy to write a question-answering module that returns short answers.
- Optimize my existing classifier prompt with DSPy using my 80 labelled examples and accuracy as the metric.
- Build a RAG pipeline in DSPy over the documents in my ./chroma_db folder.
Example: a first DSPy program
The source's basic example defines a QA signature with a short-answer output and wraps it in dspy.Predict. It configures the language model first. The example uses Claude; you can swap in dspy.OpenAI or a local model from the provider section of the source.
Replace the placeholder API key approach with your own environment setup. The source notes that the Anthropic key can be read from the ANTHROPIC_API_KEY environment variable.
import dspy
lm = dspy.Claude(model="claude-sonnet-4-5-20250929")
dspy.settings.configure(lm=lm)
class QA(dspy.Signature):
"""Answer questions with short factual answers."""
question = dspy.InputField()
answer = dspy.OutputField(desc="often between 1 and 5 words")
qa = dspy.Predict(QA)
response = qa(question="What is the capital of France?")
print(response.answer)Optimize a program with training data
To improve a module automatically, you need a small labelled training set and a metric function that scores each prediction. The source's BootstrapFewShot example builds dspy.Example objects, marks the input field with with_inputs, and compiles the module with a metric. The optimizer reference covers the other options and their data needs.
- Labelled examples: the source's optimizer guide lists rough data sizes, such as 10-50 examples for BootstrapFewShot.
- A metric: a function that returns whether a prediction is correct.
- Compile: optimizer.compile(module, trainset=...) returns an improved module.
from dspy.teleprompt import BootstrapFewShot
trainset = [
dspy.Example(question="What is 2+2?", answer="4").with_inputs("question"),
dspy.Example(question="What is 3+5?", answer="8").with_inputs("question"),
]
def validate_answer(example, pred, trace=None):
return example.answer == pred.answer
optimizer = BootstrapFewShot(metric=validate_answer, max_bootstrapped_demos=3)
optimized_qa = optimizer.compile(qa, trainset=trainset)Safety notes before you run the code
The examples call external model providers over the network, so prompts and data you send leave your machine and go to the provider you configure. The skill does not run scripts itself, but the code it helps you write does make network calls.
The ProgramOfThought module generates and executes code for reasoning. Check its output before you rely on it, and do not point it at sensitive data without review.
- Network: yes. Model calls go to the provider you configure.
- Scripts: none bundled with the skill.
- ProgramOfThought: generated code is executed, so review outputs first.
- API keys: keep them in environment variables rather than in source files.
What people use it for
- Replacing hand-written prompts in a multi-step extraction or classification pipeline with signatures and modules.
- Tuning a prompt or few-shot examples against a labelled set using a custom accuracy metric.
- Building a RAG question-answering system that retrieves passages from a Chroma database before answering.
- Prototyping a tool-using agent with dspy.ReAct and a search function you provide.
Frequently asked questions
How do I install the DSPy agent skill?
Download the ZIP from this page and unzip it into ~/.claude/skills/ for personal use, or into a project's .claude/skills/ folder. You can also upload the ZIP in the Claude apps under Settings → Capabilities → Skills.
Do I need to install anything besides the skill?
Yes. The examples need Python and the dspy package, installed with pip install dspy. You also need an OpenAI or Anthropic API key for the language model, and ChromaDB is optional for the RAG example.
Is the DSPy skill free?
The skill is released under the MIT licence. The source does not state pricing for the language model providers, so check their terms yourself, since the examples call them.
Does the skill run code on my computer?
The skill's files are documentation and code examples, and it contains no scripts of its own. The code it helps you write can call external model providers, and ProgramOfThought executes generated code, so review that output.
What is the difference between DSPy and writing prompts by hand?
With DSPy you describe inputs and outputs as signatures and let optimizers tune prompts or examples against a metric. Hand-written prompts are simpler for one-off tasks, where DSPy adds setup overhead without much benefit.
Can I use DSPy with a local model?
The source includes an example using dspy.OllamaLocal with a local Ollama server at localhost:11434. Note that the skill's requirements list OpenAI and Anthropic keys, so confirm your setup works before relying on it.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
The DSPy skill suits Python developers who have a labelled dataset and a clear metric, or who are building multi-step LLM pipelines and RAG systems and want structured code instead of hand-written prompts. Skip it for simple one-off prompts or chat tasks, and for anyone without Python experience or an API key. Review generated code and outputs before using them with sensitive data.
Download the skill