prompt-engineering-dspy
できること
このスキルは、AIのタスクを手書きのプロンプトではなくコードとして記述できるフレームワークのDSPyを教えます。AIパイプライン、RAGシステム、エージェントを作り、より安定した結果を求める開発者に向けたものです。
使う場面
- ✓長い手書きのプロンプトを、構造化された保守しやすいプログラムに置き換えたいとき。
- ✓一連の例からプロンプトを自動で調整させたいとき。
- ✓言語モデルで、RAGシステム、エージェント、または分類器を作っているとき。
スキルのリンク
https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/ai-research/prompt-engineering-dspy/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“DSPyを使って、例から自動的に改善する質問応答のパイプラインを作る手伝いをしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
入力と出力をシグネチャとして定義し、それをモジュールにまとめます。その後、オプティマイザーを実行してデータを使いプロンプトを改善します。結果は、再実行や調整ができるプログラムになります。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
DSPy: Declarative Language Model Programming
When to Use This Skill
Use DSPy when you need to:
- Build complex AI systems with multiple components and workflows
- Program LMs declaratively instead of manual prompt engineering
- Optimize prompts automatically using data-driven methods
- Create modular AI pipelines that are maintainable and portable
- Improve model outputs systematically with optimizers
- Build RAG systems, agents, or classifiers with better reliability
GitHub Stars: 22,000+ | Created By: Stanford NLP
Installation
# Stable release
pip install dspy
# Latest development version
pip install git+https://github.com/stanfordnlp/dspy.git
# With specific LM providers
pip install dspy[openai] # OpenAI
pip install dspy[anthropic] # Anthropic Claude
pip install dspy[all] # All providers
Quick Start
Basic Example: Question Answering
import dspy
# Configure your language model
lm = dspy.Claude(model="claude-sonnet-4-5-20250929")
dspy.settings.configure(lm=lm)
# Define a signature (input → output)
class QA(dspy.Signature):
"""Answer questions with short factual answers."""
question = dspy.InputField()
answer = dspy.OutputField(desc="often between 1 and 5 words")
# Create a module
qa = dspy.Predict(QA)
# Use it
response = qa(question="What is the capital of France?")
print(response.answer) # "Paris"
Chain of Thought Reasoning
import dspy
lm = dspy.Claude(model="claude-sonnet-4-5-20250929")
dspy.settings.configure(lm=lm)
# Use ChainOfThought for better reasoning
class MathProblem(dspy.Signature):
"""Solve math word problems."""
problem = dspy.InputField()
answer = dspy.OutputField(desc="numerical answer")
# ChainOfThought generates reasoning steps automatically
cot = dspy.ChainOfThought(MathProblem)
response = cot(problem="If John has 5 apples and gives 2 to Mary, how many does he have?")
print(response.rationale) # Shows reasoning steps
print(response.answer) # "3"
Core Concepts
1. Signatures
Signatures define the structure of your AI task (inputs → outputs):
# Inline signature (simple)
qa = dspy.Predict("question -> answer")
# Class signature (detailed)
class Summarize(dspy.Signature):
"""Summarize text into key points."""
text = dspy.InputField()
summary = dspy.OutputField(desc="bullet points, 3-5 items")
summarizer = dspy.ChainOfThought(Summarize)
When to use each:
- Inline: Quick prototyping, simple tasks
- Class: Complex tasks, type hints, better documentation
2. Modules
Modules are reusable components that transform inputs to outputs:
dspy.Predict
Basic prediction module:
predictor = dspy.Predict("context, question -> answer")
result = predictor(context="Paris is the capital of France",
question="What is the capital?")
dspy.ChainOfThought
Generates reasoning steps before answering:
cot = dspy.ChainOfThought("question -> answer")
result = cot(question="Why is the sky blue?")
print(result.rationale) # Reasoning steps
print(result.answer) # Final answer
dspy.ReAct
Agent-like reasoning with tools:
from dspy.predict import ReAct
class SearchQA(dspy.Signature):
"""Answer questions using search."""
question = dspy.InputField()
answer = dspy.OutputField()
def search_tool(query: str) -> str:
"""Search Wikipedia."""
# Your search implementation
return results
react = ReAct(SearchQA, tools=[search_tool])
result = react(question="When was Python created?")
dspy.ProgramOfThought
Generates and executes code for reasoning:
pot = dspy.ProgramOfThought("question -> answer")
result = pot(question="What is 15% of 240?")
# Generates: answer = 240 * 0.15
3. Optimizers
Optimizers improve your modules automatically using training data:
BootstrapFewShot
Learns from examples:
from dspy.teleprompt import BootstrapFewShot
# Training data
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"),
]
# Define metric
def validate_answer(example, pred, trace=None):
return example.answer == pred.answer
# Optimize
optimizer = BootstrapFewShot(metric=validate_answer, max_bootstrapped_demos=3)
optimized_qa = optimizer.compile(qa, trainset=trainset)
# Now opt
よくある質問
DSPyのシグネチャとは何ですか?
一つのAIステップの入力と出力を記述するもので、フレームワークがそのためのプロンプトを組み立てられるようにします。
インストールはどうしますか?
pip install dspyを実行し、必要に応じてanthropicやopenaiなどのプロバイダーのエクストラを追加します。
誰が作りましたか?
スキルは、DSPyがStanford NLPによって作られたと述べています。
詳細
作者による元の説明
Build complex AI systems with declarative programming, optimize prompts automatically, create modular RAG systems and agents with DSPy - Stanford NLP's framework for systematic LM programming
人気
- GitHubのスター
- 33k
- ランキング
- #9122
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
owasp-security
33kエージェントがWebアプリ、API、モバイル、コンテナ、AIエージェント向けの OWASP のセキュリティ指針を理解し、よくある弱点を見つけて修正案を出せるよう支援します。
agent-management
33kエージェントが、AI Maestro のコマンドラインを使って AI エージェントを作成、一覧表示、休止、再開、名前変更、削除できるよう支援します。各エージェントのライフサイクルを管理します。
agent-messaging
33kエージェントが、主に自分のマシン上で Agent Messaging Protocol を使い、AIエージェント同士の署名付きメッセージを送信、受信、返信できるよう支援します。
docs-search
33kエージェントが、自動生成されたコードのドキュメントから関数の署名、クラスの定義、コメントを検索できるよう支援します。コードを変更する前に、実際のAPIを確認できます。
似ているスキル
writing-skills
311k新しいスキルを書き、それぞれをまず試すようエージェントに教えます。そのスキルが実際にエージェントの動作を変えることを確認します。
writing-for-agents
310kスキル、AGENTS.md、CLAUDE.mdを含め、AIエージェントのための明確な指示の書き方を説明し、エージェントが予測可能に動くようにします。
bengali-nlp
280kエージェントがベンガル語のテキストを処理できるようにします。テキストの正規化など、ベンガル語特有の性質に対応しながら、言語を理解して扱えるようにします。