ds4-agent setup
A cautious native-agent setup path for local and Spark-hosted DeepSeek V4 Flash experiments, kept separate from your default coding-agent profiles.
Last updated
Local Inference Alpha Agent1. Where it fits
ds4-agent is the native agent shipped by antirez/ds4. It is different from ds4-server: the agent, tool loop, model runtime, and session state live in one local process instead of a Claude/Codex/Pi client talking to an OpenAI- or Anthropic-compatible HTTP endpoint.
Start with it as a benchmark target. Keep your existing claude-ds4, codex-ds4, pi-ds4, and Spark profiles intact until native ds4-agent wins real repo-editing tests.
| Use it for | Do not use it for yet |
|---|---|
| Disposable local coding-agent experiments | Your only production coding-agent path |
| DeepSeek V4 Flash native-agent testing | Unreviewed edits in important repos |
| Pass-per-minute benchmark runs | Unreviewed CI automation or important repos |
| Private local loops with trace files kept local | Public trace sharing |
2. Build ds4-agent
Build from source in a normal user directory. This keeps the install easy to delete and avoids changing global agent behavior.
mkdir -p ~/src-repo
git clone https://github.com/antirez/ds4.git ~/src-repo/ds4
cd ~/src-repo/ds4
make ds4-agent ds4-server
./ds4-agent --help
If you already cloned ds4, update intentionally and rebuild:
cd ~/src-repo/ds4
git pull --ff-only
make clean
make ds4-agent ds4-server
3. Model path
Use the same DeepSeek V4 Flash q2-imatrix model you use for ds4-server. On 96GB and 128GB Apple Silicon machines, q2-imatrix is the practical starting point. Do not start with q4 on a 128GB Mac unless you are deliberately testing memory failure behavior.
cd ~/src-repo/ds4
./download_model.sh q2-imatrix
# Pick the downloaded GGUF without hard-coding private paths.
export DS4_MODEL="$(find "$PWD" -name '*.gguf' | head -1)"
test -n "$DS4_MODEL" && ls -lh "$DS4_MODEL"
DS4_MODEL in your shell or wrapper. Do not let a benchmark accidentally switch models because find returned a different file.
4. Smoke tests
First verify the binary without loading a model, then run a tiny prompt. Keep context moderate for smoke tests; long context belongs in the benchmark step.
cd ~/src-repo/ds4
./ds4-agent --help
./ds4-agent \
-m "$DS4_MODEL" \
--ctx 32768 \
--nothink \
--non-interactive \
-p "reply with exactly OK"
A passing smoke test only proves that the binary and model load. It does not prove the agent can edit a repo reliably.
5. Local wrapper
Create a named command instead of replacing claude, codex, or pi. This keeps native ds4-agent experiments opt-in.
mkdir -p ~/.local/bin
cat > ~/.local/bin/ds4-agent-local <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
repo="${DS4_REPO:-$HOME/src-repo/ds4}"
cd "$repo"
model="${DS4_MODEL:-}"
if [ -z "$model" ]; then
model="$(find "$repo" -name '*.gguf' | head -1)"
fi
if [ -z "$model" ] || [ ! -f "$model" ]; then
echo "DS4_MODEL is not set and no GGUF model was found under $repo" >&2
exit 1
fi
exec "$repo/ds4-agent" \
-m "$model" \
--ctx "${DS4_CTX:-32768}" \
--nothink \
"$@"
EOF
chmod +x ~/.local/bin/ds4-agent-local
Make sure ~/.local/bin is on your PATH, then test:
ds4-agent-local --non-interactive -p "reply with exactly OK"
6. Spark wrapper
If the model lives on a DGX Spark, run ds4-agent on the Spark over SSH instead of trying to mount your workstation filesystem into the remote box. Keep this as a separate command from server-backed profiles.
| Command | Meaning |
|---|---|
xds4 / codex-ds4 | Codex-style client to a running ds4-server through an SSH tunnel. |
cds4 / claude-ds4 | Claude-style client to a running ds4-server through an SSH tunnel. |
spark-dsa | SSH into Spark and start native ds4-agent; no server tunnel required. |
Remote launcher:
cat > ~/spark-ds4-agent.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
DS4_DIR="${DS4_DIR:-$HOME/src-repo/ds4}"
MODEL="${DS4_MODEL:-$DS4_DIR/ds4flash.gguf}"
MTP="${DS4_MTP:-$DS4_DIR/gguf/DeepSeek-V4-Flash-MTP-Q4K-Q8_0-F32.gguf}"
CTX="${DS4_CTX:-100000}"
cd "$DS4_DIR"
if pgrep -x ds4-server >/dev/null || pgrep -x ds4-agent >/dev/null || pgrep -x ds4 >/dev/null; then
echo "A ds4 process is already running; stop ds4-server before ds4-agent." >&2
exit 1
fi
args=(./ds4-agent --cuda -m "$MODEL" --ctx "$CTX")
if [[ -s "$MTP" ]]; then
args+=(--mtp "$MTP")
fi
exec "${args[@]}" "$@"
EOF
chmod +x ~/spark-ds4-agent.sh
Workstation shortcut:
spark-dsa() {
ssh -t "${SPARK_SSH_HOST:-spark}" '~/spark-ds4-agent.sh' "$@"
}
Before starting native mode, stop any server mode that already owns the model:
ssh spark 'pkill -f "[/]ds4-server"'
spark-dsa
spark or placeholders like $SPARK_HOST, never a real LAN IP, Tailscale IP, serial number, account name, or host-key fingerprint.
7. Disposable repo test
Run first edits in a throwaway repo. Do not point a new native-agent profile at an important working tree until it can pass this level of test without stalls or stale edits.
rm -rf /tmp/ds4-agent-fixture
mkdir -p /tmp/ds4-agent-fixture
cd /tmp/ds4-agent-fixture
git init
cat > README.md <<'EOF'
# Fixture
Write a short setup note in docs/setup.md.
EOF
ds4-agent-local \
--trace /tmp/ds4-agent-fixture.trace \
-p "Create docs/setup.md with three concise setup steps, then stop."
Inspect the result manually:
git status --short
find . -maxdepth 3 -type f -not -path './.git/*' -print
sed -n '1,120p' docs/setup.md
8. Benchmark path
Benchmark native ds4-agent against ds4-server, Codex frontier, and Spark profiles with the same fixture tasks. Score pass/fail first, then wall time. A useful result row includes model, quantization, context, thinking mode, prompt kind, pass/fail, median wall time, total wall time, and whether the final repo state is correct.
For one-shot benchmark prompts, use --non-interactive -p. For interactive repo-editing sessions, record the final repository state and trace location separately from token-speed logs. See ds4-agent vs Codex frontier and the benchmark registry before publishing claims.
If the target task is LLM Wiki work, keep a separate ds4 wiki profile that injects the wiki instructions and tests against a disposable local .wiki/ first.
9. Privacy and gotchas
- Trace files can contain prompts, file contents, tool outputs, and generated text. Keep them out of public repos.
- Use placeholders in public docs. Do not publish local usernames, hostnames, LAN IPs, known-host fingerprints, or absolute private paths.
- Keep native
ds4-agentas a named side command until it passes real tool-use tests. - Native
ds4-agentloads the model directly. Stopds4-serverfirst, or use a server-backed client instead. - For long-context work, increase context gradually. If you see KV-cache or decode failures, lower client context before changing models.
- Do not compare raw token speed to agent productivity. Promote only after correct edits, valid tool behavior, and no stalls.