Files
deepseek-harness/examples/python-sdk-agent/README.zh.md
T
Tianyi Cui c2ad69344f fix(python-sdk): make the minimal profile an explicit allowlist
Give the SDK JSON-RPC server a per-root tool filter and let deployments mark the configured persona as the complete system prompt. The checked-in minimal overlay now names only bash and str_replace_editor, so later global tools and unrelated guidance from dsh-base cannot appear implicitly.

Keep the shared SDK host services and packaged Web capability intact. Only workspace instructions, compaction, and the conflicting one-shot Bash row remain disabled. Unit coverage pins the configuration paths, and a real dsh profile smoke proves the assembled prompt and exact two-tool request.
2026-08-24 17:28:28 +08:00

2.5 KiB
Raw Blame History

python-sdk-agent

English | 中文

基于唯一应用启动器 dsh --profile sdk 的可运行 Python SDK 示例。Python 客户端负责 JSON-RPC stdioprofile 负责 agent 组合、持久化、权限与插件。

运行极简 agent

安装 deepseek-harness-sdk、导出模型凭据,然后提供隔离的 Harness home 与 workspace

export DEEPSEEK_API_KEY=sk-your-key-here
python examples/python-sdk-agent/minimal.py \
  --dsh-home /absolute/path/to/example-dsh-home \
  --workspace /absolute/path/to/disposable-workspace \
  --session-id example-001 \
  "Inspect the repository and fix the failing tests."

兼容代理使用 DEEPSEEK_BASE_URL,默认模型使用 DSH_MODELdeployment persona 使用 DSH_SYSTEM_PROMPT--model--profile 会覆盖脚本默认值。所选 home 保存生成的 profile,并在 sessions/ 下保存 Zstandard 会话日志;脚本绝不会隐式读取 ~/.dsh

minimal.patch.yml 是随附 SDK profile 上的有序 overlay。其根 agent 工具 allow 列表只暴露:

  • agent 所有的持久 bash
  • 支持 viewcreatestr_replaceinsertstr_replace_editor

Allow 列表会排除当前及以后出现的其他所有全局工具,无需为每个基础配置项添加 disable。完整部署 persona 会抑制无关工具的引导段;运行时上下文消息、本地指令发现、compaction 与存在名称冲突的单次 Bash 配置项会分别停用。该 overlay 会插入本地 PTY 与持久 Bash provider,并将 editor 输出上限设为 16,000 字符。其他 SDK profile 服务仍保持挂载,包括持久化、策略、settings、credentials 与 provider。

此变体刻意只支持 POSIX。其持久 PTY 与 editor 可以修改运行时进程可访问的任何路径,因此只应在一次性 checkout 或容器中使用。

添加插件

对同一个显式 home 使用运行时 wheel 提供的 dsh 命令,以进行持久 profile 变更:

export DSH_HOME=/absolute/path/to/example-dsh-home
dsh plugin --profile sdk add file:/absolute/path/to/my-plugin-bundle

Python 调用也可以在 patches=(...) 中传入更多绝对 patch 路径;后面的文件优先。所选 profile 必须保留 @deepseek-ai/dsh-sdk-app 或另一个 JSON-RPC server 配置项。本目录中的完整独立 Cordis 文件仍作为底层组合测试 fixture;它们不是 Python SDK 启动接口。

另见 Python SDK 教程SDK 参考