Files
deepseek-harness/docs/tool-execution-pipeline.md
T

43 lines
2.7 KiB
Markdown
Raw Normal View History

<!-- Generated by scripts/gen-doc-graphs.ts - do not edit by hand.
Run `pnpm run gen-doc-graphs` to regenerate. -->
# Tool Execution Pipeline
This graph shows where policy, hooks, sandboxing, filesystem guards, result rewriting, and UI rendering fit without changing the loop. The key extension points are the `tools/pre-execute`, `tools/execute`, and `tools/post-execute` waterfalls.
```mermaid
flowchart TD
model["Assistant message contains tool-call block"]
2026-07-05 01:25:58 +08:00
toolCall["Session event: <code>tool/call</code><br/>logged before execution"]
2026-07-04 12:50:06 +08:00
presentCall["UI pending card<br/>presentCall(args)"]
2026-07-05 01:25:58 +08:00
pre["<code>tools/pre-execute</code> waterfall<br/>hooks, permission, sandbox"]
2026-07-04 12:50:06 +08:00
denied["deny or ask<br/>tool body skipped"]
around["<code>tools/execute</code> waterfall<br/>timeout, retry, metrics (around dispatch)"]
2026-07-03 01:32:01 +08:00
toolBody["Registered tool execute() body"]
2026-07-05 01:25:58 +08:00
fsGate["<code>fs/write-intent</code> or <code>fs/edit-intent</code><br/>tool-fs mutations only"]
owned["Tool-owned session events<br/><code>todo/write</code>, <code>fs/observed</code>, <code>hook/invoked</code>, <code>hook/result</code>, <code>tool/code-dispatch</code>"]
2026-07-05 01:25:58 +08:00
post["<code>tools/post-execute</code> waterfall<br/>accept, block, replace, add context"]
2026-07-04 12:50:06 +08:00
context["Buffered additionalContext<br/>context/message after all tool results"]
2026-07-05 01:25:58 +08:00
toolResult["Session event: <code>tool/result</code><br/>single model-facing outcome"]
2026-07-04 12:50:06 +08:00
presentResult["UI completed card<br/>presentResult(args, result)"]
model --> toolCall
toolCall --> presentCall
toolCall --> pre
pre -->|allow| around
around --> toolBody
2026-07-04 12:50:06 +08:00
pre -->|deny or ask| denied
denied --> post
toolBody --> fsGate
fsGate --> toolBody
2026-07-03 01:32:01 +08:00
toolBody --> owned
toolBody --> around
around --> post
2026-07-04 12:50:06 +08:00
post --> context
post --> toolResult
toolResult --> presentResult
```
Filesystem read-before-edit checks live below `tool-fs` on the `fs/*` event gate; hook bridges and future permission prompts live on the generic pre/post tool waterfalls; and around-dispatch concerns like the tool-call timeout policy (`@deepseek-ai/dsh-timeout-policy`) wrap core dispatch on `tools/execute`. That split lets the same hooks observe bash, fs, web, todo, and subagent calls without coupling those tools to one policy service. Code Mode rides the same pipeline twice over: `run_code` is itself a registered tool body, and each tool call its program makes re-enters `ctx.tools.execute()` through BOTH waterfalls — serialized one at a time, logged as a `tool/code-dispatch` session event, with a deny surfacing to the program as a binding rejection (a sub-call's `additionalContext` is deliberately dropped — no safe outlet mid-run preserves call/result adjacency).
2026-07-05 02:54:01 +08:00
Maintenance mode: curated Mermaid flow; exact tool schemas and event signatures live in generated catalogs.