MyClaw
HomeProductsUse CasesPricingSkillsResourcesCompany
HomeUse CasesPricingSkills
Sign In
Home
ProductsOpenClaw HostingHermes Agent Hosting
Use CasesPricingSkills
ResourcesCompareTutorialLearnBlogUpdatesResourcesCommunity
CompanyAboutSupport
Sign In
MyClaw.ai

Your AI agent, already running.

Product

OpenClaw HostingHermes Agent HostingUse CasesPricingCompareAlibaba Cloud

Resources

BlogUpdatesSkillsModelsSupportCommunityCapybara

Legal

TermsPrivacyCookieGDPRContact

© 2023 Cubo World Inc. All rights reserved.

← Back to Skills
AI & LLMs
🧩

DSPy

Build and auto-optimize declarative LM programs, RAG pipelines, and AI agents using DSPy — no manual prompt engineering required.

by NousResearchv1.0.0
Connecting to VM...
Connecting to VM...
npx clawhub@latest install dspy
1Current Installs
📦
v1.0.0Version
View Source

DSPy Skill Overview

DSPy is a Stanford NLP framework for building AI systems as declarative programs rather than hand-crafted prompts. Instead of manually tuning prompt text, you define typed signatures and compose modules — then let DSPy optimizers tune everything automatically using your data and a metric. It supports RAG pipelines, multi-step agents, structured extraction, and works across OpenAI, Anthropic, and local LMs.

How to Use It

Step 1: Run in your terminal or install this skill on MyClaw

npx clawhub@latest install dspy
or

Click the Install button at the top of this page for one-click setup

When to Use DSPy

Best Fit

  • You are building a multi-stage AI pipeline (e.g. retrieve → reason → answer) and want maintainable, modular code instead of a wall of prompt strings.
  • You have training examples and a metric, and want to systematically improve model outputs without manual prompt iteration.
  • You need to swap LM providers (e.g. from GPT-4 to Claude) without rewriting your pipeline logic.
  • You are building RAG systems or tool-using agents and want a structured, testable approach.

When Not to Use

  • You need a one-off, single-turn prompt with no optimization loop — plain API calls are simpler.
  • You have no training data or metric and are purely prototyping; DSPy's value compounds with data.
  • Your team is unfamiliar with Python and cannot run a pip-based install environment.

Key Features

Declarative Signatures

Define task inputs and outputs as typed Python classes. DSPy constructs and manages prompts from these signatures automatically, keeping your code readable and independent of prompt wording.

Composable Modules

Predict, ChainOfThought, ReAct, and ProgramOfThought are drop-in building blocks. Combine them into custom dspy.Module subclasses to express multi-step reasoning pipelines cleanly.

Automatic Prompt Optimization

Optimizers like BootstrapFewShot and MIPRO use your labeled examples and a metric function to iteratively improve prompts and few-shot demonstrations — replacing manual trial-and-error with a data-driven loop.

Multi-Provider LM Support

Configure OpenAI, Anthropic Claude, or local Ollama models with a single dspy.settings.configure(lm=...) call. You can even use different models for different stages of the same pipeline via context managers.

RAG and Agent Pipelines

Built-in dspy.Retrieve integrates with vector stores like ChromaDB. ReAct enables tool-using agents. Both patterns compose naturally with optimizers for end-to-end improvement.

Structured Output with Pydantic

TypedPredictor accepts Pydantic models as output fields, giving you schema-validated, strongly-typed responses from any LM — no post-processing parsing required.

Use Cases

Optimized Question Answering

Wrap a ChainOfThought module in BootstrapFewShot, supply a small labeled dataset, and get a prompt-optimized QA system that measurably outperforms its untuned baseline.

Retrieval-Augmented Generation

Combine dspy.Retrieve with ChromaDB and a ChainOfThought answer generator. Optimize the full RAG pipeline end-to-end using training examples and an F1 or exact-match metric.

Tool-Using Agents

Use ReAct to build agents that call external tools (search, calculators, APIs) in a structured reasoning loop, with DSPy managing the think-act-observe cycle.

Structured Information Extraction

Define a Pydantic model for the fields you need (names, dates, amounts) and use TypedPredictor to extract validated structured data from unstructured text reliably.

Requirements

  • Python 3.9+ environment (Linux, macOS, or Windows)
  • pip install dspy — core library
  • Provider extras: pip install dspy[openai], dspy[anthropic], or dspy[all]
  • API key for your LM provider (OPENAI_API_KEY or ANTHROPIC_API_KEY environment variable)
  • Optional: ChromaDB (pip install chromadb) for RAG retrieval pipelines
  • Optional: Ollama running locally for open-weight model support
Connecting to VM...
npx clawhub@latest install dspy
1Current Installs
📦
v1.0.0Version
View Source

Reviews

0 reviews

Log in to write a review

No reviews yet. Be the first to share your experience!