Skip to content
Productivity
Skill

/dspy-ruby

This skill should be used when working with DSPy.rb, a Ruby framework for building type-safe, composable LLM applications. Use this when implementing predictable AI features, creating LLM signatures and modules, configuring language model providers (OpenAI, Anthropic, Gemini,

From plugin
dex
51099 skills28 agents24 commands1 MCP

Claude Code

$ npx -y skills add davekilleen/Dex --skill dspy-ruby --agent claude-code

SKILL.md

dspy-ruby.SKILL.md
name: dspy-ruby
description: This skill should be used when working with DSPy.rb, a Ruby framework for building type-safe, composable LLM applications. Use this when implementing predictable AI features, creating LLM signatures and modules, configuring language model providers (OpenAI, Anthropic, Gemini, Ollama), building agent systems with tools, optimizing prompts, or testing LLM-powered functionality in Ruby applications.

DSPy.rb Expert

Overview

DSPy.rb is a Ruby framework that enables developers to **program LLMs, not prompt them**. Instead of manually crafting prompts, define application requirements through type-safe, composable modules that can be tested, optimized, and version-controlled like regular code.

This skill provides comprehensive guidance on:

  • Creating type-safe signatures for LLM operations
  • Building composable modules and workflows
  • Configuring multiple LLM providers
  • Implementing agents with tools
  • Testing and optimizing LLM applications
  • Production deployment patterns

Core Capabilities

1. Type-Safe Signatures

Create input/output contracts for LLM operations with runtime type checking.

**When to use**: Defining any LLM task, from simple classification to complex analysis.

**Quick reference**:

class EmailClassificationSignature < DSPy::Signature
  description "Classify customer support emails"

  input do
    const :email_subject, String
    const :email_body, String
  end

  output do
    const :category, T.enum(["Technical", "Billing", "General"])
    const :priority, T.enum(["Low", "Medium", "High"])
  end
end

**Templates**: See `assets/signature-template.rb` for comprehensive examples including:

  • Basic signatures with multiple field types
  • Vision signatures for multimodal tasks
  • Sentiment analysis signatures
  • Code generation signatures

**Best practices**:

  • Always provide clear, specific descriptions
  • Use enums for constrained outputs
  • Include field descriptions with `desc:` parameter
  • Prefer specific types over generic String when possible

**Full documentation**: See `references/core-concepts.md` sections on Signatures and Type Safety.

2. Composable Modules

Build reusable, chainable modules that encapsulate LLM operations.

**When to use**: Implementing any LLM-powered feature, especially complex multi-step workflows.

**Quick reference**:

class EmailProcessor < DSPy::Module
  def initialize
    super
    @classifier = DSPy::Predict.new(EmailClassificationSignature)
  end

  def forward(email_subject:, email_body:)
    @classifier.forward(
      email_subject: email_subject,
      email_body: email_body
    )
  end
end

**Templates**: See `assets/module-template.rb` for comprehensive examples including:

  • Basic modules with single predictors
  • Multi-step pipelines that chain modules
  • Modules with conditional logic
  • Error handling and retry patterns
  • Stateful modules with history
  • Caching implementations

**Module composition**: Chain modules together to create complex workflows:

class Pipeline < DSPy::Module
  def initialize
    super
    @step1 = Classifier.new
    @step2 = Analyzer.new
    @step3 = Responder.new
  end

  def forward(input)
    result1 = @step1.forward(input)
    result2 = @step2.forward(result1)
    @step3.forward(result2)
  end
end

**Full documentation**: See `references/core-concepts.md` sections on Modules and Module Composition.

3. Multiple Predictor Types

Choose the right predictor for your task:

**Predict**: Basic LLM inference with type-safe inputs/outputs

predictor = DSPy::Predict.new(TaskSignature)
result = predictor.forward(input: "data")

**ChainOfThought**: Adds automatic reasoning for improved accuracy

predictor = DSPy::ChainOfThought.new(TaskSignature)
result = predictor.forward(input: "data")
# Returns: { reasoning: "...", output: "..." }

**ReAct**: Tool-using agents with iterative reasoning

predictor = DSPy::ReAct.new(
  TaskSignature,
  tools: [SearchTool.new, CalculatorTool.new],
  max_iterations: 5
)

**CodeAct**: Dynamic code generation (requires `dspy-code_act` gem)

predictor = DSPy::CodeAct.new(TaskSignature)
result = predictor.forward(task: "Calculate factorial of 5")

**When to use each**:

  • **Predict**: Simple tasks, classification, extraction
  • **ChainOfThought**: Complex reasoning, analysis, multi-step thinking
  • **ReAct**: Tasks requiring external tools (search, calculation, API calls)
  • **CodeAct**: Tasks best solved with generated code

**Full documentation**: See `references/core-concepts.md` section on Predictors.

4. LLM Provider Configuration

Support for OpenAI, Anthropic Claude, Google Gemini, Ollama, and OpenRouter.

**Quick configuration examples**:

# OpenAI
DSPy.configure do |c|
  c.lm = DSPy::LM.new('openai/gpt-4o-mini',
    api_key: ENV['OPENAI_API_KEY'])
end

# Anthropic Claude
DSPy.configure do |c|
  c.lm = DSPy::LM.new('anthropic/claude-3-5-sonnet-20241022',
    api_key: ENV['ANTHROPIC_API_KEY'])
end

# Google Gemini
DSPy.configure do |c|
  c.lm = DSPy::LM.new('gemini/gemini-1.5-pro',
    api_key: ENV['GOOGLE_API_KEY'])
end

# Local Ollama (free, private)
DSPy.configure do |c|
  c.lm = DSPy::LM.new('ollama/llama3.1')
end

**Templates**: See `assets/config-template.rb` for comprehensive examples including:

  • Environment-based configuration
  • Multi-model setups for different tasks
  • Configuration with observability (OpenTelemetry, Langfuse)
  • Retry logic and fallback strategies
  • Budget tracking
  • Rails initializer patterns

**Provider compatibility matrix**:

| Feature | OpenAI | Anthropic | Gemini | Ollama | |---------|--------|-----------|--------|--------| | Structured Output | ✅ | ✅ | ✅ | ✅ | | Vision (Images) | ✅ | ✅ | ✅ | ⚠️ Limited | | Image URLs | ✅ | ❌ | ❌ | ❌ | | Tool Calling | ✅ | ✅ | ✅ | Varies |

**Cost optimization strategy**:

  • Development: Ollama (free) or gpt-4o-mini (cheap)
  • Testing: gpt-4o-mini with temperature=0.0
  • Prod
Read more
@davekilleen
Ships withdex

One personal Dex, built around your work. Keep your priorities, people, meeting notes and tasks in a folder you own. Work with Dex through your AI app to plan the day, prepare for a meeting or follow through on a promise.

51099 skills28 agents1 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
510
Star history of davekilleen/Dex on GitHub, a chart by star-history.com

Other skills on dex.

agent-browser

agent-browser

Browser automation using Vercel's agent-browser CLI. Use when you need to interact with web pages, fill forms, take screenshots,…

@davekilleen@davekilleenInstall Skill
agent-native-architecture

agent-native-architect…

Build applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools,…

@davekilleen@davekilleenInstall Skill
andrew-kane-gem-writer

andrew-kane-gem-writer

This skill should be used when writing Ruby gems following Andrew Kane's proven patterns and philosophy. It applies when creating…

@davekilleen@davekilleenInstall Skill
brainstorming

brainstorming

This skill should be used before implementing features, building components, or making changes. It guides exploring user intent,…

@davekilleen@davekilleenInstall Skill
compound-docs

compound-docs

Capture solved problems as categorized documentation with YAML frontmatter for fast lookup

@davekilleen@davekilleenInstall Skill
create-agent-skills

create-agent-skills

Expert guidance for creating, writing, and refining Claude Code Skills. Use when working with SKILL.md files, authoring new…

@davekilleen@davekilleenInstall Skill

More skills from other plugins.

i-have-adhd

i-have-adhd

Shape output for a reader with ADHD: lead with the next action, number multi-step work, restate state across turns, suppress…

@ayghri@ayghriInstall Skill
ab-test-analysis

ab-test-analysis

Analyze A/B test results with statistical significance, sample size validation, confidence intervals, and ship/extend/stop…

@phuryn@phurynInstall Skill
distilly

distilly

Set up the owner profile so a personal agent knows who it works for (first-run setup, \"get to know me\"), or distill colleague,…

Questions about dspy-ruby.

Which coding agents can use dspy-ruby?
dspy-ruby installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.