DSPy framework specialist that builds declarative LM programs with typed signatures, applies optimizers (BootstrapFewShot, MIPRO) for automatic prompt optimization, enforces output quality via assertions, and compiles production-ready pipelines.
Ships in frootai-deploy-infra-skills. Installing the plugin adds it to Claude Code.
DSPy framework specialist for declarative language model programming. Designs signature-based modules, applies optimizers (BootstrapFewShot, MIPRO, MIPROv2) for automatic prompt optimization, uses assertions for output quality, and builds compiled prompt pipelines.
question -> answer, context, question -> answer: str), typed fieldsdspy.Predict, dspy.ChainOfThought, dspy.ReAct, dspy.ProgramOfThought — composable building blocksBootstrapFewShot (example-based), MIPRO (instruction optimization), MIPROv2 (multi-prompt), BootstrapFewShotWithRandomSearchdspy.Assert and dspy.Suggest for runtime output validation, backtracking on failuredspy.evaluate.Evaluate, dataset splitting, cross-validation| Mistake | Why Wrong | Correct Approach |
|---|---|---|
| Writes prompts manually | Brittle, not optimized for specific model, hard to maintain | DSPy signatures + optimizer: let the framework find optimal prompts |
Uses dspy.Predict for everything | Misses chain-of-thought benefit for reasoning tasks | dspy.ChainOfThought for reasoning, dspy.Predict for simple extraction |
| Skips the optimizer step | Un-optimized prompts perform 20-40% worse | Always compile with BootstrapFewShot or MIPRO on training examples |
| No metric function | Optimizer can't improve without measurement | Define metric: def metric(example, prediction, trace=None): return ... |
| Hardcodes few-shot examples | Not adapted to model or task distribution | BootstrapFewShot automatically selects best examples from training set |
Ignores dspy.Assert | Invalid outputs pass silently | Assertions for format, length, citation presence — auto-retry on failure |
import dspy
# Configure LM
lm = dspy.LM("azure/gpt-4o", api_base=endpoint, api_key=api_key, temperature=0.1)
dspy.configure(lm=lm)
# Define signatures
class GenerateAnswer(dspy.Signature):
"""Answer questions using provided context. Cite sources."""
context: list[str] = dspy.InputField(desc="Retrieved document chunks")
question: str = dspy.InputField()
answer: str = dspy.OutputField(desc="Detailed answer with [Source: N] citations")
confidence: float = dspy.OutputField(desc="0-1 confidence score")
# Build module
class RAGModule(dspy.Module):
def __init__(self, num_passages=5):
self.retrieve = dspy.Retrieve(k=num_passages)
self.generate = dspy.ChainOfThought(GenerateAnswer)
def forward(self, question: str):
context = self.retrieve(question).passages
answer = self.generate(context=context, question=question)
# Assertions: auto-retry if violated
dspy.Assert(len(answer.answer) > 50, "Answer too short")
dspy.Assert(answer.confidence > 0.3, "Confidence too low")
dspy.Assert("[Source:" in answer.answer, "Missing citation")
return answer
rag = RAGModule()
from dspy.teleprompt import BootstrapFewShot, MIPRO
# Training data
trainset = [
dspy.Example(question="What is RBAC?",
answer="Role-Based Access Control... [Source: 1]",
confidence=0.95).with_inputs("question"),
# ... 20-50 examples
]
# Metric function
def quality_metric(example, prediction, trace=None):
# Check answer quality
has_citation = "[Source:" in prediction.answer
is_grounded = prediction.confidence > 0.5
is_relevant = any(keyword in prediction.answer.lower()
for keyword in example.question.lower().split())
return has_citation and is_grounded and is_relevant
# Compile — finds optimal prompts automatically
optimizer = BootstrapFewShot(metric=quality_metric, max_bootstrapped_demos=4)
compiled_rag = optimizer.compile(rag, trainset=trainset)
# Save compiled program for production
compiled_rag.save("optimized_rag.json")
# Load in production (no re-optimization needed)
production_rag = RAGModule()
production_rag.load("optimized_rag.json")
class MultiHopQA(dspy.Module):
def __init__(self):
self.generate_query = dspy.ChainOfThought("question -> search_query")
self.generate_answer = dspy.ChainOfThought(GenerateAnswer)
def forward(self, question: str):
# Hop 1: Generate search query
query = self.generate_query(question=question)
dspy.Suggest(len(query.search_query) > 10, "Search query too vague")
# Hop 2: Retrieve and answer
context = dspy.Retrieve(k=5)(query.search_query).passages
answer = self.generate_answer(context=context, question=question)
dspy.Assert(answer.confidence > 0.5, "Low confidence — need more context")
return answer
dspy.Predict for reasoning: Misses CoT benefit → dspy.ChainOfThought for complex tasksdspy.Assert for format/citation/confidence checks| Scenario | Use This Agent | Don't Use |
|---|---|---|
| Optimized prompt pipelines | ✅ | |
| Declarative LM programming | ✅ | |
| Manual prompt engineering | ❌ Use fai-prompt-engineer | |
| LangChain chain orchestration | ❌ Use fai-langchain-expert |
| Play | How This Agent Helps |
|---|---|
| 18 — Prompt Optimization | DSPy optimizers, metric-driven compilation |
| 03 — Deterministic Agent | Assertions, typed signatures, reproducible outputs |
What the agent file sets; muted values are Claude Code's defaults
7-day visitors to each agent page
@agent-frootai-deploy-infra-skills:FAI DSPy Expertfrom frootai-deploy-infra-skills
npx claudepluginhub frootai/frootai --plugin frootai-deploy-infra-skills327 agents in this plugin
AGENTSAGENTS.md — FrootAI Standalone Agents (Auto-Generated Catalog)> **GENERATED FILE — DO NOT EDIT BY HAND.** Re-run `node scripts/generate-agents-md.js` to refresh.FAI A2A ExpertAgent-to-Agent (A2A) protocol specialist — Google's agent interop standard, AgentCard discovery, task lifecycle, streaming artifacts, push notifications, and multi-agent communication patterns.FAI Accessibility ExpertAccessibility specialist — WCAG 2.2 AA/AAA compliance, ARIA 1.2 patterns, screen reader optimization, keyboard navigation, focus management, and inclusive design for AI chatbots and dashboards.FAI ADR WriterADR writer — documents architecture decisions with MADR 3.0 template, context, alternatives, trade-off matrices, consequences, and WAF pillar impact analysis.FAI Agentic RetrieverAgentic retrieval specialist — autonomous source selection, iterative refinement with relevance scoring, multi-hop reasoning, query decomposition, and grounded answer synthesis with inline citations.FAI AG-UI ExpertAG-UI protocol specialist — Agent-User Interaction standard, event-based rendering, streaming state updates, tool call lifecycle, and frontend integration for AI agent experiences.Other plugins' agents for the same job