Token导航 LogoToken导航TokenDH.com
开发external-servicegithub未标认证来源可访问许可证需确认审计提醒

dspy-fundamentalsdspy 基础知识

Agent Skill

dspy-fundamentals 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

272

周安装

11

GitHub Stars

177

下载量

85
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dspy-fundamentals(dspy 基础知识)
来源仓库:https://github.com/intertwine/dspy-agent-skills
仓库路径:skills/dspy-fundamentals
安装命令:
npx skills add https://github.com/intertwine/dspy-agent-skills --skill dspy-fundamentals
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/intertwine/dspy-agent-skills --skill dspy-fundamentals

简介

dspy-fundamentals 讲解 DSPy 核心概念:签名、模块与优化器的协同工作原理。

  • 它强调 declarative 编程风格而非手动编写原始 prompt 字符串。
  • 适合初学者理解 PyTorch for Prompts 的设计哲学与基本操作流程。
  • 使用前请全局配置 LM 实例并遵循签名继承体系进行开发。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

DSPy Fundamentals (3.2.x)

DSPy is the "PyTorch for prompts" — you declare Signatures (typed I/O contracts), compose them into Modules, and let optimizers (not you) tune the instructions and few-shot examples. Never write raw prompts.

The one-paragraph model

Configure a single LM globally with dspy.configure(lm=...). Define a dspy.Signature subclass with dspy.InputField() / dspy.OutputField() (docstring becomes the instruction). Wrap it in a predictor — dspy.Predict (direct), dspy.ChainOfThought (adds reasoning), dspy.ReAct (tool-using agent), dspy.ProgramOfThought (code-executing), or dspy.RLM (long-context). Subclass dspy.Module to compose multi-step programs. For built-in providers, use dspy.LM("provider/model"); for a truly custom backend, subclass dspy.BaseLM. Optimize later with GEPA.

Canonical template

import dspy

dspy.configure(lm=dspy.LM("openai/gpt-4o"), track_usage=True)

class QuestionAnswer(dspy.Signature):
    """Answer questions with rigorous step-by-step reasoning."""
    question: str = dspy.InputField()
    answer: str = dspy.OutputField(desc="concise final answer")

class QAProgram(dspy.Module):
    def __init__(self):
        super().__init__()
        self.solve = dspy.ChainOfThought(QuestionAnswer)

    def forward(self, question: str) -> dspy.Prediction:
        return self.solve(question=question)

program = QAProgram()
pred = program(question="What is 2 + 2?")
print(pred.reasoning, pred.answer)

Predictor cheatsheet (DSPy 3.2.x)

PredictorWhen to useAdds
dspy.Predict(sig)Simple structured I/Onothing — just the signature
dspy.ChainOfThought(sig)Reasoning tasksa reasoning output field
dspy.ReAct(sig, tools=[...], max_iters=20)Tool-using agentThought/Action/Observation loop
dspy.ProgramOfThought(sig, max_iters=3)Math/data tasksgenerates & runs Python (needs Deno)
dspy.RLM(sig,...)Long context / codebasesrecursive REPL exploration (see dspy-rlm-module)

Typed outputs — use Pydantic on fields, not TypedPredictor

dspy.TypedPredictor is superseded; dspy.Predict now handles Pydantic types natively via field annotations.

from pydantic import BaseModel
from typing import Literal

class Entity(BaseModel):
    name: str
    kind: Literal["person", "org", "place"]

class ExtractEntities(dspy.Signature):
    """Extract named entities from text."""
    text: str = dspy.InputField()
    entities: list[Entity] = dspy.OutputField()

extractor = dspy.Predict(ExtractEntities)

Save & load

Two modes — know the difference:

# State-only (portable JSON; you must rebuild the architecture to load)
program.save("program.json", save_program=False)
new = QAProgram(); new.load("program.json")

# Full program (cloudpickle into a directory; restores everything)
program.save("./program_dir/", save_program=True)
restored = dspy.load("./program_dir/")

Prefer state-only for version control; full-program for deployment artifacts.

Ten anti-patterns to refuse

  1. Hard-coded prompt strings ("You are a helpful assistant...") — write a Signature.
  2. dspy.TypedPredictor(...) in new code — use dspy.Predict with Pydantic fields.
  3. dspy.OpenAI(...) / dspy.settings.configure(...) — use dspy.configure(lm=dspy.LM(...)).
  4. Provider-specific LM classes for built-in providers — use dspy.LM("provider/model"). If DSPy doesn't ship your backend, subclass dspy.BaseLM.
  5. Giant monolithic predictors that do five jobs — decompose into a Module with named sub-predictors.
  6. Mutating signature.instructions by hand — let the optimizer do it.
  7. In-lining few-shot demos in the Signature docstring — bootstrap/optimize them.
  8. Using pickle.dump(program) — use program.save(...).
  9. Setting an LM per module at construction time without reason — configure globally, override only when you need model mixing.
  10. Vague metrics (yes/no, exact-match only) when training an optimizer — see dspy-evaluation-harness.

Configuring the LM

dspy.configure(
    lm=dspy.LM("openai/gpt-4o", temperature=0.0, max_tokens=2000),
    track_usage=True,        # accumulate token counts on predictions
    async_max_workers=4,     # for .acall / batch
)

DSPy 3.2.x warns by default when a module call passes extra input fields or values that don't match the signature's declared types. Treat those warnings as a callsite bug first; if you're intentionally passing pre-serialized values, disable them with dspy.configure(warn_on_type_mismatch=False).

Common provider prefixes: openai/, anthropic/, azure/, vertex_ai/, bedrock/, ollama/. For local Ollama: dspy.LM("ollama_chat/llama3.1:8b", api_base="http://localhost:11434").

Where to go next

  • Measuring quality → dspy-evaluation-harness
  • Automatic optimization → dspy-gepa-optimizer
  • Context >100k tokens → dspy-rlm-module
  • Full pipeline → dspy-advanced-workflow
  • Full API reference → reference.md
  • Runnable example → example_qa.py

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.57%
按下载量换算31

Claude

28.8%
按下载量换算24

Cursor

18.38%
按下载量换算16

Gemini CLI

9.38%
按下载量换算8

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills