dspy

Build AI pipelines with declarative signatures and automated prompt optimization.

1|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/cryptopafi/nexusos-skills --skill dspy-cryptopafi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/cryptopafi/nexusos-skills/tree/main/mlops/research/dspy
Command: npx skills add https://github.com/cryptopafi/nexusos-skills --skill dspy-cryptopafi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Building robust, modular AI systems often requires brittle manual prompt engineering, ad-hoc chains, and time-consuming tuning; dspy provides a declarative layer and automated optimization to make LM-based pipelines predictable, maintainable, and improvable with data.

Core Features & Use Cases

  • Declarative Signatures & Modules: Define tasks as signatures and compose reusable modules such as Predict, ChainOfThought, ReAct, and ProgramOfThought to express complex workflows.
  • Automatic Prompt & Few-Shot Optimization: Improve prompts and demonstrations programmatically using optimizers like BootstrapFewShot, MIPRO, and BootstrapFinetune.
  • RAG, Agents, and Pipelines: Build retrieval-augmented systems, tool-using agents, multi-stage pipelines, reranking, and verification loops for production reliability.
  • Evaluation and Integration: Includes evaluation utilities, custom metrics, LM provider configuration (OpenAI, Anthropic, local models), saving/loading optimized modules, and patterns for batching, caching, and monitoring.
  • Use Case: Create an optimized RAG question-answering system that retrieves documents, reranks passages, and iteratively improves prompts from labeled QA data.

Quick Start

Use dspy to define a signature and assemble a RAG pipeline that retrieves documents, composes context, and returns concise answers.

Frequently Asked Questions about dspy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize prompts programmatically instead of manual tuning?

Programmatic prompt optimization uses automated optimizers like BootstrapFewShot and MIPRO to iteratively improve prompts and demonstrations from data. This replaces manual tuning by compiling declarative signatures into optimized instructions and few-shot examples.

What is declarative LM programming for building AI pipelines?

Declarative LM programming defines AI tasks as signatures and composes reusable modules like Predict and ChainOfThought. This approach abstracts brittle prompt engineering, allowing developers to build maintainable and predictable multi-stage language model pipelines.

Can I build retrieval-augmented generation agents with this approach?

Retrieval-augmented generation agents are supported through modular primitives like ReAct and ProgramOfThought. You can assemble pipelines that retrieve documents, rerank passages, and generate answers with integrated evaluation utilities for production reliability.

Does this framework support local models and Anthropic integrations?

Local models, Anthropic, and OpenAI integrations are fully supported through native LM provider configurations. You can switch between providers by configuring the language model client, enabling flexible deployment for research and product teams.

When should I use automated few-shot optimization for my classifiers?

Automated few-shot optimization should be used when building classifiers or pipelines that require predictable, data-driven improvements. Optimizers like BootstrapFinetune generate reliable demonstrations from labeled data, eliminating ad-hoc prompt chains and manual tuning.

What is the best way to structure multi-stage AI workflows without ad-hoc chains?

The best way to structure multi-stage AI workflows is using declarative modules to compose tasks. By defining signatures and applying automated optimizers, you replace brittle ad-hoc chains with maintainable, improvable pipelines that include batching, caching, and monitoring.