Agent skill

Dspy

by magnus919 in magnus919/agent-skills

Optimize and build programmatic prompt systems with Stanford DSPy.

MITAuto-check passedAI & LLM Engineering

Install Dspy

skills CLI
$ npx skills add magnus919/agent-skills --skill dspy -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install magnus919/agent-skills dspy --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/magnus919/agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/dspy .claude/skills/dspy && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
dspy
GitHub stars
115
Token cost
~2k tokens
SKILL.md length
696 words
Files
16 (incl. scripts, references)
Skills in repo
131
Repo updated
First seen
Licence
MIT

At a glance

Optimize and build programmatic prompt systems with Stanford DSPy.

  • Works in 6 steps: DSPy is a compiler, not a chain… → Signatures define the task. Input/output… → Modules are program components.… → …
  • Doing programmatic prompt optimization
  • SKILL.md covers Core Paradigm, Core Principles, Where to Start and Quick Reference, plus 6 more sections
  • Runs Python scripts from its folder

What it does

Dspy is an agent skill from magnus919/agent-skills. Optimize and build programmatic prompt systems with Stanford DSPy. Signatures, modules (Predict, ChainOfThought, ReAct), optimizer/teleprompter selection, compilation, caching, evaluation. Use when doing programmatic prompt optimization or building compiled prompt programs. Do not use this skill for unrelated requests; route to the nearest named specialist.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 19 other files, including scripts and reference files (for example `README.md`, `evals/evals.json` and `references/agent-patterns.md`).

It sits in AI & LLM Engineering, covering Prompt engineering and Caching. It works with React and Python. The repository describes itself as: Curated collection of AI agent skills for Hermes and other agent frameworks. The licence is MIT.

When your agent uses it

  • Doing programmatic prompt optimization
  • Building compiled prompt programs
  • Unrelated requests
  • Route to the nearest named specialist

Example prompts

  • “/dspy”

Requirements

  • Python 3

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. DSPy is a compiler, not a chain framework. You define the program structure with Python control flow and typed signatures. The compiler…
  2. Signatures define the task. Input/output field pairs with optional descriptions are the task definition. The syntax is input1, input2 ->…
  3. Modules are program components. dspy.Predict (direct), dspy.ChainOfThought (reasoning), dspy.ReAct (tool-use), and custom dspy.Module…
  4. Optimizers tune prompts, not weights. A dozen optimizers (teleprompters) tune instructions, few-shot demos, or both. Selection depends on…
  5. Compile once, serve many. Compilation is expensive ($3-$300+). The output is a portable artifact via program.save(path). Inference is cheap.
  6. Cache aggressively. DSPy caches all LM calls by default. Set DSPY_CACHEDIR for the current client. Disable with dspy.LM(..., cache=False).

What it can do on your machine

Read from SKILL.md and the folder at commit 22b4723. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Dspy loads about 2k tokens when it runs, and up to ~7.3k if it reads all its reference files. Until then it costs about 91 tokens; SKILL.md has 696 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~91
When it runs · the whole SKILL.md, loaded when a task matches
~2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~7.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from magnus919/agent-skills at commit 22b4723, republished under its MIT licence (© magnus919). 696 words, ~1,966 tokens.

Download SKILL.mdSave it as .claude/skills/dspy/SKILL.md (or your agent's skills folder). This skill also uses 15 other files; get the full folder from GitHub.
name
dspy
description
Optimize and build programmatic prompt systems with Stanford DSPy. Signatures, modules (Predict, ChainOfThought, ReAct), optimizer/teleprompter selection, compilation, caching, evaluation. Use when doing programmatic prompt optimization or building compiled prompt programs. Do not use this skill for unrelated requests; route to the nearest named specialist.
license
MIT
metadata.author
Magnus Hedemark
metadata.version
1.1.0
metadata.source
https://dspy.ai

DSPy Expert Skill

DSPy is a compiler for prompt programs, not a chain or RAG framework. You write Python programs with typed signatures and DSPy optimizes the prompts automatically.

⚠️ DSPy is NOT a chain framework. It does not use prompt | model | parser. It does not have LCEL. DSPy operates at a different layer: you define a program with Python control flow and typed signatures, then the compiler optimizes the prompts against a metric. If you reach for DSPy expecting LangChain-style composition, you are reaching for the wrong tool.

Think of it as PyTorch for LMs — you define the architecture, the compiler tunes the weights (prompts).

Core Paradigm

Read this first. It is the most important thing to understand about DSPy.

python
import dspy

# 1. Configure the LM
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)

# 2. Define a signature (input/output schema)
class QASignature(dspy.Signature):
    """Answer questions concisely."""
    question: str = dspy.InputField()
    answer: str = dspy.OutputField()

# 3. Build a program using modules
qa = dspy.ChainOfThought(QASignature)

# 4. Compile against a metric
optimizer = dspy.MIPROv2(metric=dspy.answer_exact_match)
compiled_qa = optimizer.compile(qa, trainset=trainset, num_trials=25)

# 5. Use the compiled program (portable artifact)
answer = compiled_qa(question="What is DSPy?").answer

Core Principles

  1. DSPy is a compiler, not a chain framework. You define the program structure with Python control flow and typed signatures. The compiler optimizes the prompts. This is fundamentally different from LangChain's explicit prompt composition.

  2. Signatures define the task. Input/output field pairs with optional descriptions are the task definition. The syntax is input1, input2 -> output1, output2.

  3. Modules are program components. dspy.Predict (direct), dspy.ChainOfThought (reasoning), dspy.ReAct (tool-use), and custom dspy.Module subclasses. Compose them with Python control flow (if/for/while).

  4. Optimizers tune prompts, not weights. A dozen optimizers (teleprompters) tune instructions, few-shot demos, or both. Selection depends on bottleneck and budget. See the optimizer cheat sheet.

  5. Compile once, serve many. Compilation is expensive ($3-$300+). The output is a portable artifact via program.save(path). Inference is cheap.

  6. Cache aggressively. DSPy caches all LM calls by default. Set DSPY_CACHEDIR for the current client. Disable with dspy.LM(..., cache=False).

Where to Start

You already have...Start here
Nothing — exploring DSPyUnderstand the paradigm (read this page first), then build a simple Predict program
A working prompt you want to optimizePort to a DSPy Signature, add ChainOfThought, compile with BootstrapFewShot
A multi-step pipelineBuild as a custom dspy.Module with Python control flow, compile with MIPROv2
An agent/tool-use taskUse dspy.ReAct with tools, compile with GEPA or AvatarOptimizer
Comparing frameworksSee the Framework Routing Guide

Quick Reference

TaskApproachReference
Basic predictiondspy.Predict(signature)references/core-modules.md
With reasoningdspy.ChainOfThought(signature)references/core-modules.md
With toolsdspy.ReAct(tools=tools)references/agent-patterns.md
Custom programclass MyProgram(dspy.Module)references/program-patterns.md
Quick optimizationdspy.BootstrapFewShot(metric)references/optimizer-guide.md
Full optimizationdspy.MIPROv2(metric, auto="medium")references/optimizer-guide.md
Evaluationdspy.Evaluate(metric=fn, devset=examples)references/evaluation.md
Save/loadprogram.save(path) / program.load(path)references/compilation-guide.md
Retrievaldspy.Retrieve(k=5)references/program-patterns.md
Show full SKILL.md (311 more words)Show less

Framework Routing Guide

ScenarioReach forWhy
Prompt optimization / compiled programsDSPyOnly framework that auto-optimizes prompts against a metric
Documents to query / RAGLlamaIndexData ingestion and retrieval are first-class primitives
Chain/agent compositionLangChainLCEL is the cleanest pipe-based composition model
State-machine multi-agentLangGraphGraph topology, subgraphs, human-in-the-loop
Search pipelinesHaystackPipeline model is more mature for search workloads
Role-based teamsCrewAIHigher-level agent abstraction

Reference Files

ReferenceLoad whenFile
Core ModulesBuilding with Predict, ChainOfThought, ReActreferences/core-modules.md
Optimizer GuideChoosing and configuring an optimizerreferences/optimizer-guide.md
Program PatternsRAG, classification, multi-step, tool-usereferences/program-patterns.md
EvaluationMetrics, evaluation loop, dataset creationreferences/evaluation.md
Compilation GuideCaching, cost management, save/loadreferences/compilation-guide.md
Agent PatternsReAct agent, tool-use, AvatarOptimizerreferences/agent-patterns.md
FAQ & TroubleshootingCommon errors and fixesreferences/faq-and-troubleshooting.md
Validation AuditResearch validation of all API claimsreferences/validation-audit.md
Worked RAG ExampleFull RAG compilation with expected outputreferences/example-rag-compilation.md

Template Files

TemplateWhen to useFile
ClassificationText classification with BootstrapFewShottemplates/classification.py
RAG ProgramRAG with ColBERT retrieval and ChainOfThoughttemplates/rag-program.py
Multi-Step ReasoningMulti-step program with tool-usetemplates/multi-step.py

Scripts

ScriptPurposeFile
check-setupVerify DSPy installation and configurationscripts/check-setup.py

Troubleshooting

SymptomLikely causeFixReference
Compilation too slowToo many candidates/threadsReduce num_candidates or use auto="light"references/optimizer-guide.md
Compilation too expensiveNo cachingEnable DSPY_CACHEDIRreferences/compilation-guide.md
Context too longToo many demosReduce max_bootstrapped_demos and max_labeled_demosreferences/faq-and-troubleshooting.md
Low quality after compileWrong optimizer for bottleneckCheck cheat sheet: instructions vs demos vs weightsreferences/optimizer-guide.md
Program is not improvingMetric not discriminatingUse a metric that returns float, not boolreferences/evaluation.md
Sub-module not updating_compiled flag setSet module._compiled = False before recompilingreferences/compilation-guide.md

When NOT to Use DSPy

  • Simple single-prompt application — raw API calls are simpler
  • Need pre-built application modules (PDF Q&A, text-to-SQL) — use LlamaIndex or LangChain
  • One-shot task with no optimization budget — DSPy's compiler overhead won't amortize
  • Real-time latency-critical — compilation happens at development time but adds no inference overhead

© magnus919, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 15 other files (scripts, references) in dspy of magnus919/agent-skills.

  • SKILL.md
  • README.md
  • evals/evals.json
  • references/agent-patterns.md
  • references/compilation-guide.md
  • references/core-modules.md
  • references/evaluation.md
  • references/example-rag-compilation.md
  • references/faq-and-troubleshooting.md
  • references/optimizer-guide.md
  • references/program-patterns.md
  • references/validation-audit.md
  • scripts/check-setup.py
  • templates/classification.py
  • templates/multi-step.py
  • templates/rag-program.py

Open the folder on GitHubat commit 22b4723

Compare with similar skills

Dspy next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Dspy compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Dspy this skillmagnus919/agent-skills115—~2kAutomated safety check: PassMIT
Claude Cookbooks Reference2025Emma/vibe-coding-cn23k1 repos~2.2kAutomated safety check: PassMIT
Prompt Engineering Patternswshobson/agents40k—~1.3kAutomated safety check: PassMIT
Opikcomet-ml/opik-mcp220—~2.1kAutomated safety check: PassApache-2.0
Flowfile AI Subsystem GuideEdwardvaneechoud/Flowfile385—~9.1kAutomated safety check: NotesMIT
Guidance Constrained GenerationOrchestra-Research/AI-Research-SKILLs13k5 repos~3.6kAutomated safety check: PassMIT

Similar skills

  • Claude Cookbooks Reference

    2025Emma/vibe-coding-cn

    Reference of Claude API examples and guides covering tool use, vision, RAG, classification, summarization, text-to-SQL, prompt caching and agent patterns.

    23k GitHub starsUsed in 1 repo~2.2k tokens
    AI & LLM EngineeringAuto-check passed
  • Reference for designing and tuning production LLM prompts: few-shot examples, chain-of-thought, structured outputs, templates and system prompts.

    40k GitHub stars~1.3k tokensUpdated 5 days ago
    AI & LLM EngineeringAuto-check passed
  • Opik

    comet-ml/opik-mcp

    Reference for the Opik SDK — tracing, span types, framework integrations, threads, and the prompt library (Python, TypeScript, REST).

    220 GitHub stars~2.1k tokensUpdated 2 days ago
    AI & LLM EngineeringAuto-check passed
  • Flowfile AI Subsystem Guide

    Edwardvaneechoud/Flowfile

    Maps the /ai/ subsystem of flowfile_core, its three agent tiers, litellm seam, BYOK keys and rate limits, and sets rules for extending or debugging it safely.

    385 GitHub stars~9.1k tokensUpdated today
    AI & LLM EngineeringAuto-check: notes
  • Guidance Constrained Generation

    Orchestra-Research/AI-Research-SKILLs

    Constrains language model output with regex, selections and grammars using the Guidance library, so JSON, XML, code or formatted fields come out valid.

    13k GitHub starsUsed in 5 repos~3.6k tokens
    AI & LLM EngineeringAuto-check passed
  • Lintlang Audit

    hermes-labs-ai/lintlang

    Audit a named AI agent config, system prompt, tool-definition or instruction file (YAML, JSON, Markdown, text, or Python) with the released LintLang CLI, on request.

    140 GitHub stars~1.8k tokensUpdated today
    AI & LLM EngineeringAuto-check passed

More from magnus919/agent-skills

All 131 skills in this repo
  • Artifact Pyramids

    magnus919/agent-skills

    Organize durable agent research outputs as summaries, analysis, and evidence dossiers.

    115 GitHub stars~2.7k tokensUpdated today
    Auto-check passed
  • Ascii City Engine

    magnus919/agent-skills

    Build portable, first-person colored ASCII city engines and small GIS-derived city packs.

    115 GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Color Management

    magnus919/agent-skills

    Manage color workflows with ICC profiles, working spaces, gamut mapping, and color science.

    115 GitHub stars~2.6k tokensUpdated today
    Auto-check: notes
  • Data Scientist

    magnus919/agent-skills

    A skill your agent uses for PhD-level expertise in data science, statistics, and machine learning: rigorous statistical analysis, experimental design, causal inference, advanced modeling, research…

    115 GitHub stars~4.1k tokensUpdated today
    Auto-check passed
  • Docker Compose

    magnus919/agent-skills

    Use Docker Compose to define, run, debug, and harden multi-container applications.

    115 GitHub stars~2k tokensUpdated today
    Auto-check: notes
  • Fpga Development

    magnus919/agent-skills

    Design, review, simulate, and verify FPGA logic using explicit RTL contracts, clock and reset models, CDC analysis, timing constraints, and reproducible implementation evidence.

    115 GitHub stars~2.7k tokensUpdated today
    Auto-check passed

Works with

Questions about Dspy

What does Dspy do?

Optimize and build programmatic prompt systems with Stanford DSPy. Dspy is an agent skill from magnus919/agent-skills. Optimize and build programmatic prompt systems with Stanford DSPy.

When should I use Dspy?

Dspy fits situations like: doing programmatic prompt optimization; building compiled prompt programs; unrelated requests; route to the nearest named specialist.

How do I install Dspy in Claude Code?

Run `npx skills add magnus919/agent-skills --skill dspy -a claude-code`. Or copy the skill folder (dspy in magnus919/agent-skills) into .claude/skills/dspy in your project. Claude Code loads it when a task matches its description.

How do I install Dspy in Codex?

Run `npx skills add magnus919/agent-skills --skill dspy -a codex`. Or copy the skill folder (dspy in magnus919/agent-skills) into .agents/skills/dspy in your project. Codex loads it when a task matches its description.

Can I use Dspy in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add magnus919/agent-skills --skill dspy -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/dspy, .gemini/skills/dspy, .github/skills/dspy and .opencode/skills/dspy in your project.

What does Dspy need to run?

Going by SKILL.md and its folder, Dspy needs Python for the scripts in its folder. Our summary lists: Python 3.

Does Dspy access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Dspy safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Dspy use?

Dspy is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Dspy use?

About 2k tokens (SKILL.md is roughly 7.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 5.3k tokens, read only when the agent opens those files.

What are the alternatives to Dspy?

Skills that share tags, products or a category with Dspy: Claude Cookbooks Reference (2025Emma/vibe-coding-cn, 23k stars), Prompt Engineering Patterns (wshobson/agents, 40k stars), Opik (comet-ml/opik-mcp, 220 stars) and Flowfile AI Subsystem Guide (Edwardvaneechoud/Flowfile, 385 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Dspy?

magnus919 (a GitHub user) maintains it in magnus919/agent-skills, which has 115 GitHub stars. The repository holds 131 skills in this directory. The repository was last updated on October 10, 2026.

Source: magnus919/agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.