DSPyDSPy
DSPy 把「调提示词」变成编程问题(MIT,Stanford NLP/Databricks):签名声明输入输出, 优化器把提示当参数训练。用它的分水岭一句话:有没有评估指标——有指标它是杠杆,没指标它无从下手。
DSPy turns 'tuning prompts' into a programming problem (MIT, Stanford NLP/Databricks): signatures declare inputs/outputs, optimizers train prompts as parameters. The dividing line in one sentence: do you have an evaluation metric — with one it is a lever, without one it has nothing to optimize.
适合与不适合When to use it, when not to
适合:可复现的提示优化流程、多模型可换管线、有 metric 的成熟任务。 不适合:开箱 agent 运行时;无指标的探索期任务。
Fits: reproducible prompt-optimization flows, multi-model swappable pipelines, mature tasks with metrics. Not a fit: out-of-the-box agent runtimes; exploratory tasks without metrics.
中文生态China availability 国产 / 国内可直接用 / 备案状态 · 快照domestic / direct access / CAC filing · snapshot 2026-10-21
- 出品属地Origin
- 国外出品foreign-made Stanford NLP 起源,现与 Databricks 有官方投入线。Stanford NLP origin, with official Databricks investment lines.
- 国内使用Direct access
- 大陆可直连direct OK dspy.ai 直连实测 200(2026-10-21)。dspy.ai measured 200 direct (2026-10-21).
- 备案状态CAC filing
- 未见于备案名单not in filing list:未见于网信办公示名单(2026-10-21 检索);开源项目未面向大陆公众提供服务,备案不适用。not in the CAC public registry (searched 2026-10-21); the open-source project does not serve the mainland public, so filing does not apply.
备案信息以网信办《生成式人工智能服务已备案信息》公示名单为准(按批次滚动更新,本站只抄编号不解读);「大陆可直连」是本站从大陆网络直连实测的结果,不是厂商承诺。GitHub 类站点当日实测有波动,口径写在依据里。Filing status is quoted from the CAC public registry (updated batch by batch; this site copies the number and does not interpret it). "Direct access" is this site's own reachability measurement from a mainland network, not a vendor promise. GitHub-hosted sites fluctuated on the measurement day — the note says so.
固定坐标系Fixed coordinate system
8 个维度dimensions, 与同分区其他对象逐项可比each comparable item by item against others in the same section.
- 模型与开放条件Model & openness
各家 LM 通过 dspy.LM 统一接入(OpenAI/Anthropic/Gemini/本地 vLLM 等, 以官方 docs 的 LM 集成线为准,未逐条清点);它的差异点是把提示词当可编程参数—— 签名(signature)声明输入输出,优化器自动调提示与权重示例。
Each vendor's LM connects uniformly through dspy.LM (OpenAI/Anthropic/Gemini/local vLLM etc., following the official docs' LM-integration line, not enumerated item by item); its differentiator is treating prompts as programmable parameters — signatures declare inputs and outputs, and optimizers automatically tune prompts and few-shot examples.
- 运行位置Where it runs
Python 库(pip 装进你的进程);GitHub 38,850★,最近推送 2026-10-29(API 核验)。 学术出身(Stanford NLP),工业侧 Databricks 投入(官方叙事口径)。
A Python library (pip-installed into your process); GitHub 38,850★, last push 2026-10-29 (API verified). Academic origin (Stanford NLP), with industrial-side Databricks investment (per the official narrative).
- 本地文件Local files
库形态跑在你进程里;优化产物(program 状态/示例)落你指定路径——数据不出你侧。
The library form runs inside your process; optimization artifacts (program state/examples) land at paths you specify — data never leaves your side.
- 关机后的任务Tasks after shutdown
库无常驻语义;优化(teleprompting)是离线批任务,跑完即止。
A library has no resident semantics; optimization (teleprompting) is an offline batch task that ends when it finishes.
- 工具与扩展Tools & extensions
ReAct 类 agent 模块与工具调用在官方模块族内;MCP 支持状态未核验到官方主线声明。
ReAct-style agent modules and tool calling are within the official module family; MCP support status has no verified official mainline statement.
- 上下文与记忆Context & memory
状态管理跟着你的 program 走;跨会话记忆不是它的叙事——它的「记忆」是优化出来的示例与权重。
State management follows your program; cross-session memory is not part of its narrative — its "memory" is the optimized examples and weights.
- 权限与限制Permissions & limits
无账号体系;权限面=你接的各家 API key。优化过程会大量调模型(token 成本面), 预算控制参数在官方文档线,细节未逐条核验。
No account system; the permission surface is whatever vendors' API keys you connect. The optimization process calls models heavily (a token-cost surface); budget-control parameters are in the official docs line, details not verified item by item.
- 适合什么任务Best for
适合:把「调提示词」变成可复现的优化流程(有指标、有训练集)、多模型可换的管线。 不适合:要开箱 agent 运行时;小样本没指标时(优化器吃指标,没指标没意义)。
Fits: turning "prompt tuning" into a reproducible optimization process (with metrics, with a training set); pipelines where models are swappable. Does not fit: wanting an out-of-the-box agent runtime; small samples without metrics (optimizers consume metrics — without metrics there is nothing to optimize).
头号误解Top misconception
- 把 DSPy 当「又一个 prompt 模板库」——它的核心是优化器(把提示当参数训练),不用优化器等于白用Treating DSPy as 'yet another prompt template library' — the core is the optimizer (prompts trained as parameters); skipping it wastes the tool
- 没有评估指标就上优化器——优化器需要 metric,没指标时它无从优化Running optimizers without an evaluation metric — optimizers need a metric; without one there is nothing to optimize
- 优化期 token 成本不设上限——先设预算参数再跑(官方文档有控制面)Leaving optimizer token budgets uncapped — set budget parameters before running (the official docs have controls)
未知项清单Known unknowns
- LM 集成全目录(未逐条清点)
- MCP 支持状态(未核验到官方主线声明)
- 各优化器的样本量经验值(官方有指引,未逐条核验)
- The full LM-integration catalog (not enumerated item by item)
- MCP support status (no verified official mainline statement)
- Sample-size rules of thumb per optimizer (the official docs have guidance; not verified item by item)
证据来源Evidence sources
判断可回到以下一手源复核。本站核验日Every judgement can be rechecked against the primary sources below. Verified on 2026-10-30,内容更新日content updated on 2026-10-21。
| 类型Type | 名称Name | 链接Link |
|---|---|---|
| repo | stanfordnlp/dspy · 仓库(MIT;38,850★,最近推送 2026-10-29,GitHub API 核验)stanfordnlp/dspy · repository (MIT; 38,850★, last push 2026-10-29, GitHub API verified) | https://github.com/stanfordnlp/dspy |
| docs | DSPy · 官方文档DSPy · official docs | https://dspy.ai |
| changelog | stanfordnlp/dspy · Releases(changelog)stanfordnlp/dspy · Releases (changelog) | https://github.com/stanfordnlp/dspy/releases |
实测记录Measured runs
本档未跑集成与性能实测;结论只覆盖 API 与官方文档披露的能力面。
This site has not completed measured runs.
The test protocol is at protocols/framework/_protocol.md.
相关条目Related entries
- LangChainLangChain同层对照:LangChain 编排组件,DSPy 优化提示——一个管接线一个管调教。same-layer contrast: LangChain orchestrates components, DSPy optimizes prompts — one handles wiring, the other handles training
- Pydantic AIPydantic AI同为「类型/结构优先」路线:Pydantic 管输出结构,DSPy 管提示质量。both on the "types/structure first" route: Pydantic governs output structure, DSPy governs prompt quality
- CursorCursor另一层 · AI 编程Other layer · AI coding
- Claude Code IDE 扩展Claude Code (IDE extension)另一层 · AI 编程Other layer · AI coding
本页由This page is generated from the ai-handbook 数据层生成(CC BY 4.0)。data layer (CC BY 4.0).
方法论与坐标系定义见仓库内For the methodology and coordinate definitions, see METHODOLOGY.md.