mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
The loop logs the assistant/message (carrying tool-call blocks) BEFORE running the tools, so a crash mid-tool leaves durable tool calls with no matching tool/result. interruptedTurnClosers only added step/end + turn/end, so a resumed session's deriveMessages() replayed a dangling assistant tool-call — which every provider rejects as an invalid transcript on the next request. interruptedTurnClosers now scans the interrupted turn for tool-call blocks without a matching tool/result and synthesizes an error tool/result for each (before the step/end), so the rehydrated history is a valid transcript. Adds a dedicated repair.spec.ts and a shared-contract case proving both backends pair every orphaned call with a result. Docs (ADR 0018, both persistence READMEs, load() JSDoc) updated. Also fixes the echo-agent README session-cleanup path: demo:echo runs from the repo root, so sessions land in <repo-root>/.sessions/_no-cwd/, not examples/echo-agent/.sessions/ (review #33).
2.1 KiB
2.1 KiB
echo-agent
Runnable demo: stdin chat with a scripted mock model and an echo tool.
What it shows
- A complete Cordis app loaded from
cordis.yml— the standard "stack of plugins" pattern mock-llm.ts— a mockLlmAdapterthat streams scripted responses and calls theechotool when the user types "echo "echo-tool.ts— a tool registered viactx.tools.register()that echoes text back uppercased@deepseek-ai/dsh-session-persistence-jsonl— the durable JSONL persistence backend (loaded fromcordis.yml,root: ./.sessions): append-only event log per session with crash-safe atomic writes, replacing the old write-only example pluginstdio-chat.ts— a minimal UI plugin: reads stdin lines andsend/steers the agent, renders stream deltas, tool calls, and tool results
Plugin files
| File | Role | Key patterns demonstrated |
|---|---|---|
mock-llm.ts |
LlmAdapter registration |
ctx.llm.registerAdapter(['mock-echo'], …), streaming chunks with proper block-start/block-end protocol |
echo-tool.ts |
Tool registration | ctx.tools.register(defineTool(…)) with typed execute args, tool execution returning ContentBlock[] |
stdio-chat.ts |
UI | agent/stream-chunk, session/event (tool/*), stdin→send/steer |
start.ts |
Bootstrap | Context + Loader + plugin-include wired to cordis.yml |
Persistence is the shared @deepseek-ai/dsh-session-persistence-jsonl plugin (not a per-example file).
Run
pnpm run demo:echo
# or:
node --expose-internals --import tsx examples/echo-agent/start.ts
Type a message and press Enter. "echo " triggers a tool call round-trip (the mock model requests the echo tool, which echoes the text uppercased, and the next model step acknowledges it).
The session is persisted under .sessions/ relative to the directory you launch the demo from. pnpm run demo:echo runs from the repo root, so the logs land in <repo-root>/.sessions/ (a session with no cwd goes in the _no-cwd/ bucket, one .jsonl log per session). Clean up with: rm -rf .sessions