intertwine/dspy-agent-skills/dspy-fundamentals
Claude Code and agent skill by intertwine/dspy-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Write idiomatic DSPy 3.2.x programs — typed Signatures, dspy.Module subclasses, Predict/ChainOfThought/ReAct/ProgramOfThought, and save/load. Use this when starting any new DSPy project or when fixing non-idiomatic DSPy code (hard-coded prompts, ad-hoc string templates, untyped outputs, non-serializable classes).
Install
npx vskill@latest install intertwine/dspy-agent-skills/dspy-fundamentalsSKILL.md
DSPy Fundamentals (3.2.x)
DSPy is the "PyTorch for prompts" — you declare Signatures (typed I/O contracts), compose them into Modules, and let optimizers (not you) tune the instructions and few-shot examples. Never write raw prompts.
The one-paragraph model
Configure a single LM globally with dspy.configure(lm=...). Define a dspy.Signature subclass with dspy.InputField() / dspy.OutputField() (docstring becomes the instruction). Wrap it in a predictor — dspy.Predict (direct), dspy.ChainOfThought (adds reasoning), dspy.ReAct (tool-using agent), dspy.ProgramOfThought (code-executing), or dspy.RLM (long-context). Subclass dspy.Module to compose multi-step programs. For built-in providers, use dspy.LM("provider/model"); for a truly custom backend, subclass dspy.BaseLM. Optimize later with GEPA.
Canonical template
Predictor cheatsheet (DSPy 3.2.x)
| Predictor | When to use | Adds | |
|---|---|---|---|
dspy.Predict(sig) | Simple structured I/O | nothing — just the signature | |
dspy.ChainOfThought(sig) | Reasoning tasks | a reasoning output field | |
dspy.ReAct(sig, tools=[...], max_iters=20) | Tool-using agent | Thought/Action/Observation loop | |
dspy.ProgramOfThought(sig, max_iters=3) | Math/data tasks | generates & runs Python (needs Deno) | |
dspy.RLM(sig, ...) | Long context / codebases | recursive REPL exploration (see dspy-rlm-module) |
Typed outputs — use Pydantic on fields, not TypedPredictor
dspy.TypedPredictor is superseded; dspy.Predict now handles Pydantic types natively via field annotations.
Save & load
Two modes — know the difference:
Prefer state-only for version control; full-program for deployment artifacts.
Ten anti-patterns to refuse
- Hard-coded prompt strings (
"You are a helpful assistant...") — write a Signature. dspy.TypedPredictor(...)in new code — usedspy.Predictwith Pydantic fields.dspy.OpenAI(...)/dspy.settings.configure(...)— usedspy.configure(lm=dspy.LM(...)).- Provider-specific LM classes for built-in providers — use
dspy.LM("provider/model"). If DSPy doesn't ship your backend, subclassdspy.BaseLM. - Giant monolithic predictors that do five jobs — decompose into a
Modulewith named sub-predictors. - Mutating
signature.instructionsby hand — let the optimizer do it. - In-lining few-shot demos in the Signature docstring — bootstrap/optimize them.
- Using
pickle.dump(program)— useprogram.save(...). - Setting an LM per module at construction time without reason — configure globally, override only when you need model mixing.
- Vague metrics (yes/no, exact-match only) when training an optimizer — see
dspy-evaluation-harness.
Configuring the LM
DSPy 3.2.x warns by default when a module call passes extra input fields or values that don't match the signature's declared types. Treat those warnings as a callsite bug first; if you're intentionally passing pre-serialized values, disable them with dspy.configure(warn_on_type_mismatch=False).
Common provider prefixes: openai/, anthropic/, azure/, vertex_ai/, bedrock/, ollama/. For local Ollama: dspy.LM("ollama_chat/llama3.1:8b", api_base="http://localhost:11434").
Where to go next
- Measuring quality →
dspy-evaluation-harness - Automatic optimization →
dspy-gepa-optimizer - Context >100k tokens →
dspy-rlm-module - Full pipeline →
dspy-advanced-workflow - Full API reference → reference.md
- Runnable example → example_qa.py
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/dspy-fundamentals/SKILL.md
Popularity
- Repository stars
- 246
- Repository forks
- 22
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 7 Jun 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/intertwine/dspy-agent-skills/dspy-fundamentals)