dspy-ai-apps

Comprehensive guide for building AI applications using the DSPy framework with Google's Gemini API. This skill enforces strict rate limit management for the 'gemini-3-flash-preview' model (20 RPD) and provides best practices for "Intent-Oriented Programming", decomposition, agents, and optimization. Use this skill when you need to: (1) Create new DSPy programs, (2) Integrate Gemini with DSPy, (3) Optimize DSPy signatures for Google models, (4) Build Agents/RAG/Tools, or (5) Debug DSPy pipelines.

65 stars

Best use case

dspy-ai-apps is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Comprehensive guide for building AI applications using the DSPy framework with Google's Gemini API. This skill enforces strict rate limit management for the 'gemini-3-flash-preview' model (20 RPD) and provides best practices for "Intent-Oriented Programming", decomposition, agents, and optimization. Use this skill when you need to: (1) Create new DSPy programs, (2) Integrate Gemini with DSPy, (3) Optimize DSPy signatures for Google models, (4) Build Agents/RAG/Tools, or (5) Debug DSPy pipelines.

Teams using dspy-ai-apps should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/dspy-ai-apps/SKILL.md --create-dirs "https://raw.githubusercontent.com/One-Man-Company/Skills-ContextManager/main/MySkillsHUB/skills/dspy-ai-apps/skill.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/dspy-ai-apps/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How dspy-ai-apps Compares

Feature / Agentdspy-ai-appsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Comprehensive guide for building AI applications using the DSPy framework with Google's Gemini API. This skill enforces strict rate limit management for the 'gemini-3-flash-preview' model (20 RPD) and provides best practices for "Intent-Oriented Programming", decomposition, agents, and optimization. Use this skill when you need to: (1) Create new DSPy programs, (2) Integrate Gemini with DSPy, (3) Optimize DSPy signatures for Google models, (4) Build Agents/RAG/Tools, or (5) Debug DSPy pipelines.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# DSPy AI Applications with Gemini

This skill guides you through building robust, self-optimizing AI applications using **DSPy** (Declarative Self-improving Python) and the **Gemini API**. It emphasizes **Intent-Oriented Programming**: defining *what* you want (Signatures) rather than *how* to prompt it.

> [!WARNING]
> **STRICT RATE LIMITS**: The `gemini-3-flash-preview` model has extremely strict rate limits:
> - **5 Requests Per Minute (RPM)**
> - **20 Requests Per Day (RPD)**
> - **250,000 Tokens Per Minute (TPM)**
>
> You MUST enable caching and use "Dry Runs" to avoid exhaustion.

## 1. Core Philosophy: Intent-Oriented Programming

DSPy shifts focus from "hand-crafting prompts" to "programming architectures".

1.  **Decomposition**: Break complex tasks (Translation, RAG, Agents) into small, optimizable specific programs. Do not build monolithic "God Prompts".
2.  **Signatures**: Declare input/output specs (including types like `list[dict]`, `float`, `Pydantic`).
3.  **Optimization**: Use data (synthetic or real) to compiling programs into effective prompts automatically.
4.  **Modularity**: Swap backends (e.g., Gemini -> Local) or optimization strategies without rewriting code.

## 2. Quick Start (Safe Mode)

To start a new project without hitting rate limits immediately:

1.  **Install Dependencies**:
    ```bash
    pip install dspy-ai google-generativeai
    ```

2.  **Use the Safe Boilerplate**:
    Always start with the provided boilerplate which includes caching and rate limit handling.
    See [assets/boilerplate.py](assets/boilerplate.py).

3.  **Configure Environment**:
    Ensure `GOOGLE_API_KEY` is set in your environment variables.

## 3. Workflow

### Step 1: Define Typed Signatures
Define explicit intents. Be specific with types.
*See [references/cheat_sheet.md](references/cheat_sheet.md) for examples (Invoice Parsing, Entity Extraction).*

### Step 2: Build Modular Programs
Connect modules like `dspy.Predict`, `dspy.ChainOfThought`, or `dspy.ReAct`.
For Agents, expose these programs as tools.

### Step 3: Run Once & Cache
Run your module on a single example.
- **ALWAYS** use `dspy.configure(experimental=True)` or standard settings to enable file-based caching.
- Verify the cache file was created before proceeding.

### Step 4: Synthetic Data & Optimization (Advanced)
**CRITICAL WARNING**: Optimization loops (BootstrapFewShot, MIPRO) consume massive RPD.
- **Strategy**: Use a "Teacher" model (stronger/different quota) to generate synthetic data if possible.
- **Micro-Optimization**: If you must optimize on Gemini Flash, use a tiny trainset (2-3 examples) and `BootstrapFewShot` with `max_bootstrapped_demos=1`.

## 4. Advanced Patterns

### A. Agents & MCP
DSPy programs can be exposed as MCP (Model Context Protocol) tools.
1. Define a `dspy.Signature` for the tool.
2. Wrap it in a `dspy.Predict`.
3. Serve it via an MCP server (e.g., using `mcp2py`).

### B. Fine-Tuning Flow
1. Define Signature.
2. Optimize a Teacher program (strong model) to get high-quality traces.
3. Generate synthetic data.
4. Fine-tune a smaller Student model (e.g., Gemma 2B) using `BootstrapFinetune`.

### C. RAG (Retrieval Augmented Generation)
Combine `dspy.Retrieve` (e.g., ColBERTv2, VectorDB) with `dspy.ChainOfThought`.
Optimize the *entire pipeline* to improve retrieval queries and answer generation simultaneously.

## 5. Troubleshooting

- **429 Errors**: You hit the rate limit. Stop immediately.
- **Empty Responses**: Check API key and safety settings.
- **"Context too long"**: Use `dspy.Retrieve` or decompose the task.

## 6. Artifacts & Resources

- `assets/boilerplate.py`: **MANDATORY** starting point (includes Pydantic/Typed examples).
- `references/cheat_sheet.md`: Signatures for Invoice Parser, RAG, Agents, Entities.

Related Skills

webapp-testing

65
from One-Man-Company/Skills-ContextManager

Web application testing principles. E2E, Playwright, deep audit strategies.

web-design-guidelines

65
from One-Man-Company/Skills-ContextManager

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

vulnerability-scanner

65
from One-Man-Company/Skills-ContextManager

Advanced vulnerability analysis principles. OWASP 2025, Supply Chain Security, attack surface mapping, risk prioritization.

ui-ux-pro-max

65
from One-Man-Company/Skills-ContextManager

UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 9 stacks.

testing-patterns

65
from One-Man-Company/Skills-ContextManager

Testing patterns and principles. Unit, integration, mocking strategies.

tdd-workflow

65
from One-Man-Company/Skills-ContextManager

Test-Driven Development workflow principles. RED-GREEN-REFACTOR cycle.

tailwind-patterns

65
from One-Man-Company/Skills-ContextManager

Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture.

systematic-debugging

65
from One-Man-Company/Skills-ContextManager

4-phase systematic debugging methodology with root cause analysis and evidence-based verification. Use when debugging complex issues.

skill-creator

65
from One-Man-Company/Skills-ContextManager

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

server-management

65
from One-Man-Company/Skills-ContextManager

Server management principles and decision-making. Process management, monitoring strategy, and scaling decisions. Teaches thinking, not commands.

seo-fundamentals

65
from One-Man-Company/Skills-ContextManager

SEO fundamentals, E-E-A-T, Core Web Vitals, and Google algorithm principles.

python-patterns

65
from One-Man-Company/Skills-ContextManager

Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Teaches thinking, not copying.