|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
English | [中文](python-sdk.zh.md)
|
|
|
|
|
|
-This tutorial is the programmatic alternative to the Web UI. It installs the published Python SDK, runs a checked-in agent composition, and shows how to call the same API from your own program.
|
|
|
+This tutorial installs the published Python SDK, runs the checked-in minimal profile overlay, and shows how to customize the same `dsh` profile from your own program.
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
|
@@ -10,12 +10,10 @@ This tutorial is the programmatic alternative to the Web UI. It installs the pub
|
|
|
- Git
|
|
|
- Linux x64, Linux arm64, or macOS 14 or newer on arm64
|
|
|
- A DeepSeek-compatible API endpoint and credential
|
|
|
-- An isolated workspace that the agent may modify
|
|
|
+- An isolated workspace and an isolated Harness home
|
|
|
|
|
|
## Install the SDK
|
|
|
|
|
|
-Clone the repository for its runnable example, create a virtual environment, and install the SDK with its same-version bundled runtime:
|
|
|
-
|
|
|
```sh
|
|
|
git clone https://github.com/deepseek-ai/deepseek-harness.git
|
|
|
cd deepseek-harness
|
|
|
@@ -24,51 +22,48 @@ python -m venv .venv
|
|
|
python -m pip install deepseek-harness-sdk
|
|
|
```
|
|
|
|
|
|
-The installed runtime needs no system Node.js. Repository contributors who need to build the runtime or wheels from source should use the [Python contributor workflows](../../../python/development.md).
|
|
|
+The installation includes a matching native runtime wheel and the `dsh` command. Normal SDK execution needs no system Node.js. Repository contributors who build the artifacts should use the [Python contributor workflow](../../../python/development.md).
|
|
|
|
|
|
## Run the checked-in example
|
|
|
|
|
|
-Set the credential in the environment. Set `DEEPSEEK_BASE_URL` as well when the model is served by an OpenAI-compatible proxy rather than the default DeepSeek endpoint.
|
|
|
+Export the credential and, when needed, a compatible proxy endpoint:
|
|
|
|
|
|
```sh
|
|
|
export DEEPSEEK_API_KEY=sk-your-key-here
|
|
|
# export DEEPSEEK_BASE_URL=http://127.0.0.1:8000/v1
|
|
|
-# export DSH_MODEL=deepseek-v4-flash
|
|
|
-# export DSH_SYSTEM_PROMPT='You are a helpful software engineer assistant.'
|
|
|
```
|
|
|
|
|
|
-Run one task against an isolated workspace and session directory:
|
|
|
+Run one task with explicit workspace and home paths:
|
|
|
|
|
|
```sh
|
|
|
python examples/python-sdk-agent/minimal.py \
|
|
|
- --workspace /absolute/path/to/workspace \
|
|
|
- --session-root /absolute/path/to/sessions \
|
|
|
+ --workspace /absolute/path/to/disposable-workspace \
|
|
|
+ --dsh-home /absolute/path/to/example-dsh-home \
|
|
|
--session-id example-001 \
|
|
|
"Inspect the repository and fix the failing tests."
|
|
|
```
|
|
|
|
|
|
-The script prints the final assistant response. The session directory receives a JSONL log containing the assembled model requests and tool calls.
|
|
|
-
|
|
|
-## Use the SDK in your own program
|
|
|
+The script prints the final assistant response. The selected home receives the generated `sdk` profile, settings, credentials if you add them, installed plugins, and Zstandard session logs under `sessions/`. The example and SDK never silently read `~/.dsh`.
|
|
|
|
|
|
-The checked-in example is a thin wrapper around this SDK call:
|
|
|
+## Use the SDK in your program
|
|
|
|
|
|
```python
|
|
|
from pathlib import Path
|
|
|
|
|
|
from deepseek_harness import DeepSeekHarness
|
|
|
|
|
|
-config = Path("examples/python-sdk-agent/minimal.cordis.yml").resolve()
|
|
|
-workspace = Path("/absolute/path/to/workspace").resolve()
|
|
|
-sessions = Path("/absolute/path/to/sessions").resolve()
|
|
|
+workspace = Path("/absolute/path/to/disposable-workspace").resolve()
|
|
|
+dsh_home = Path("/absolute/path/to/example-dsh-home").resolve()
|
|
|
+patch = Path("examples/python-sdk-agent/minimal.patch.yml").resolve()
|
|
|
|
|
|
with DeepSeekHarness(
|
|
|
provider="deepseek-official",
|
|
|
model="deepseek-v4-flash",
|
|
|
max_tokens=49_152,
|
|
|
cwd=str(workspace),
|
|
|
- session_root=str(sessions),
|
|
|
- cordis=str(config),
|
|
|
+ dsh_home=str(dsh_home),
|
|
|
+ profile="sdk",
|
|
|
+ patches=(str(patch),),
|
|
|
) as harness:
|
|
|
result = harness.run(
|
|
|
"Inspect the repository and fix the failing tests.",
|
|
|
@@ -78,9 +73,23 @@ with DeepSeekHarness(
|
|
|
print(result.final_response)
|
|
|
```
|
|
|
|
|
|
-`DeepSeekHarness` starts the bundled runtime lazily and reuses it until the context manager exits. Reusing the same harness and session id preserves the session-owned Bash process, including its working directory, exported variables, and shell functions. Use a fresh session id for an independent task; reuse an id only when the next call should continue the same durable conversation.
|
|
|
+The SDK starts the bundled `dsh --profile sdk` process lazily and reuses it until context-manager exit. The profile, its persistent patch, the home patch, and the ordered `patches` tuple form the application configuration. There is no separate Python runtime bin or complete-config option.
|
|
|
+
|
|
|
+## Install or define plugins
|
|
|
|
|
|
-## Understand the example composition
|
|
|
+Use `dsh plugin` for dependencies and bundle layers that should persist in this home:
|
|
|
+
|
|
|
+```sh
|
|
|
+export DSH_HOME=/absolute/path/to/example-dsh-home
|
|
|
+dsh --profile sdk --dump-default-config >/dev/null
|
|
|
+dsh plugin --profile sdk add file:/absolute/path/to/my-plugin-bundle
|
|
|
+```
|
|
|
+
|
|
|
+The first command initializes the shipped SDK profile. The second forwards package management to `pnpm`, then records any installed package that exports a `dsh.bundle` layer. Install `pnpm` only for this management command; launching the installed SDK does not need it. Edit `$DSH_HOME/profiles/sdk/cordis.patch.yml` for persistent row changes, or pass patch files from Python for per-launch changes.
|
|
|
+
|
|
|
+Another `profile` is valid when it includes `@deepseek-ai/dsh-sdk-app` or another JSON-RPC server row. Missing server rows, unresolved plugins, and invalid patches fail during startup instead of falling back to another composition.
|
|
|
+
|
|
|
+## Understand the minimal overlay
|
|
|
|
|
|
| Property | Value |
|
|
|
|---|---|
|
|
|
@@ -90,15 +99,10 @@ print(result.final_response)
|
|
|
| Bash timeout | 300 seconds |
|
|
|
| Editor output limit | 16,000 characters |
|
|
|
| Context compaction | Disabled |
|
|
|
-| Filesystem | Bare local backend; absolute editor paths may address any path visible to the runtime process |
|
|
|
-| Session persistence | Uncompressed JSONL under `DSH_SESSION_ROOT` |
|
|
|
-
|
|
|
-The composition omits harness identity, workspace prompt text, skills, one-shot Bash, task tools, compaction, and every other model-facing plugin. Sandbox-policy facts are logged as runtime user context rather than appended to the system prompt.
|
|
|
-
|
|
|
-## Choose workspace and session IDs
|
|
|
+| Session persistence | Zstandard JSONL under `<dsh_home>/sessions` |
|
|
|
|
|
|
-`cwd` selects the workspace available to the agent, while `session_root` stores session logs and state. Use a fresh session id for an independent task; reuse an id only when the next call should continue the same conversation and persistent shell state.
|
|
|
+The overlay removes runtime-context prompt messages and most default tools while retaining the SDK application's protocol and persistence. Persistent Bash and the editor can modify any path visible to the runtime, so use a disposable checkout or container. The PTY implementation makes this example POSIX-only.
|
|
|
|
|
|
-The composition uses `danger-full-access`. Run it only inside a disposable checkout or container: Bash and the editor can modify any path allowed to the runtime process. The persistent PTY backend requires a POSIX terminal substrate, so this composition does not support Windows agents.
|
|
|
+Use a fresh home when profiles, plugins, credentials, settings, and sessions must be isolated. Use a fresh session id for independent work; reuse a harness, home, and id only to continue the same durable conversation and session-owned resources.
|
|
|
|
|
|
-The [`python-sdk-agent` example reference](../../../examples/python-sdk-agent/README.md) owns the exact composition. The [Python SDK reference](../../../python/sdk/README.md) covers lifecycle, results, notifications, runtime selection, and configuration; the [Cordis primer](../../cordis-primer.md) covers composition syntax.
|
|
|
+The [example reference](../../../examples/python-sdk-agent/README.md) owns the checked-in overlay. The [Python SDK reference](../../../python/sdk/README.md) covers lifecycle, results, notifications, and low-level behavior; the [dsh CLI reference](../../../apps/cli/reference/README.md) covers profile layering.
|