‹ 首页

dspy-reasoning-modules

@omidzamani · 收录于 1 周前

Use for DSPy reasoning modules including RLM, ProgramOfThought, CodeAct, Parallel, sandboxed execution, and long-context workflows.

适合你,如果正在用DSPy开发复杂推理链或Agent

/ 下载安装
dspy-reasoning-modules.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add omidzamani/dspy-skills/dspy-reasoning-modules
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- omidzamani/dspy-skills/dspy-reasoning-modules
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify omidzamani/dspy-skills/dspy-reasoning-modules
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
113GitHub stars
~702最小装载
~702含声明引用
~756文本包总量
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · f5db3b7

DSPy Reasoning Modules

Goal

Choose the appropriate DSPy reasoning module for long-context exploration, code-assisted reasoning, or parallel execution.

Module Selection

| Module | Use it for | Important constraint | |--------|------------|----------------------| | dspy.RLM | Exploring very large contexts with iterative REPL code and recursive sub-LM calls | Experimental; requires Deno by default | | dspy.ProgramOfThought | Solving tasks by generating and executing Python | Requires Deno by default | | dspy.CodeAct | Combining generated Python with predefined tool functions | Functions only; requires Deno | | dspy.Parallel | Running (module, example) pairs concurrently | Tune threads and error handling |

RLM for Large Contexts

RLM treats long inputs as external data in a sandbox rather than placing the full context in each LM prompt.

import dspy

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

rlm = dspy.RLM(
    "document, question -> answer",
    max_iterations=12,
    max_llm_calls=30,
    sub_lm=dspy.LM("openai/gpt-4o-mini"),
)

result = rlm(
    document=very_long_document,
    question="What were the main revenue drivers?",
)
print(result.answer)

Use max_iterations, max_llm_calls, and max_output_chars as explicit cost and output bounds.

Sandboxed Execution

The default dspy.PythonInterpreter uses Deno and Pyodide. It denies host filesystem, environment, and network access unless explicitly enabled.

from pathlib import Path
import dspy

with dspy.PythonInterpreter(
    enable_read_paths=[Path("./inputs")],
    enable_network_access=["api.example.com"],
) as interpreter:
    print(interpreter.execute("print('ready')"))

Grant only the minimum paths, environment variables, and network hosts needed by the task.

ProgramOfThought and CodeAct
import dspy

dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"))

math = dspy.ProgramOfThought("question -> answer")
print(math(question="What is the sum of the first 100 integers?").answer)

Use CodeAct when generated code also needs curated host-side tools:

def lookup_rate(currency: str) -> float:
    """Return a trusted exchange rate from the application service."""
    return rates[currency]

agent = dspy.CodeAct("amount, currency -> converted", tools=[lookup_rate])
Parallel Execution
parallel = dspy.Parallel(num_threads=8, return_failed_examples=True)
results, failed_examples, exceptions = parallel(
    [(program, {"question": question}) for question in questions]
)
Best Practices
  1. Prefer Predict or ChainOfThought until code execution or long-context exploration is justified.
  2. Treat RLM as experimental and load-test before production deployment.
  3. Bound loops and sub-LM calls.
  4. Keep sandbox permissions narrow.
  5. Create separate interpreters for concurrent custom-interpreter use.
Official Documentation
  • RLM API: https://dspy.ai/api/modules/RLM/
  • ProgramOfThought API: https://dspy.ai/api/modules/ProgramOfThought/
  • CodeAct API: https://dspy.ai/api/modules/CodeAct/
  • Parallel API: https://dspy.ai/api/modules/Parallel/
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。