Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/configuration/agents/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ agents:
| `add_prompt_files` | array | ✗ | List of file paths whose contents are appended to the system prompt. Useful for including coding standards, guidelines, or additional context. |
| `add_prompt_files_depth` | int | ✗ | Also list, by path only, the `add_prompt_files` names found up to this many directory levels below the working directory (`1` = direct subdirectories). Contents are not loaded — the agent reads the ones it needs. Useful in monorepos. Default: `0` (no scan). See [Prompt Files](#prompt-files) below. |
| `add_description_parameter` | boolean | ✗ | When `true`, adds agent descriptions as a parameter in tool schemas. Helps with tool selection in multi-agent scenarios. |
| `redact_secrets` | boolean | ✗ | Enabled by default; set `false` to opt out. Scrubs detected secrets (API keys, tokens, private keys, etc.) out of tool-call arguments, outgoing chat messages, and tool output before they reach a tool, the model, or downstream consumers. See [Redacting Secrets](#redacting-secrets) below. |
| `redact_secrets` | boolean | ✗ | Enabled by default; set `false` to opt out. Scrubs detected secrets (API keys, tokens, private keys, etc.) out of tool-call arguments, outgoing chat messages, and tool output — including inline document attachments — before they reach a tool, the model, or downstream consumers. See [Redacting Secrets](#redacting-secrets) below. |
| `code_mode_tools` | boolean | ✗ | When `true`, replaces the agent's individual tools with a single tool that runs a JavaScript script calling as many of them as needed in one turn. See [Code Mode](../../features/code-mode/index.md). |
| `max_iterations` | int | ✗ | Maximum number of tool-calling loops. Default: unlimited (0). Set this to prevent infinite loops. |
| `max_consecutive_tool_calls` | int | ✗ | Maximum consecutive identical tool calls before the agent is terminated, preventing degenerate loops. Default: `5`. |
Expand Down Expand Up @@ -320,7 +320,7 @@ Secret redaction is enabled by default. The `redact_secrets` field controls scru

1. A `tool_input_transform` built-in hook that scrubs detected secrets from the **arguments of every tool call**, before the tool sees them.
2. A `before_llm_call` built-in hook that scrubs the same patterns from **outgoing chat messages** — message content, multi-part text content, prior reasoning content, and the JSON-encoded arguments of any tool call still in the conversation — before they reach the model provider.
3. A `tool_response_transform` built-in hook that scrubs **tool output at the source**, so the secret never reaches event consumers, the persisted session file, the `post_tool_use` hook input, or the next LLM call.
3. A `tool_response_transform` built-in hook that scrubs **tool output, its display metadata, and its inline document attachments at the source**, so the secret never reaches event consumers, the persisted session file, the `post_tool_use` hook input, or the next LLM call. When other `tool_response_transform` hooks are configured, the auto-injected redactor runs once **before** them — command hooks receive the whole hook input as JSON on stdin, so they never see raw tool results — and once **after** them, so a later rewrite cannot reintroduce a secret.

```yaml
agents:
Expand Down
24 changes: 18 additions & 6 deletions docs/configuration/hooks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Built-ins are typically zero-config and faster than equivalent shell hooks becau
| `add_recent_commits` | `session_start` | _none_, or `["<N>"]` | Adds `git log --oneline -n N`. `N` defaults to 10; pass a positive integer to override. |
| `max_iterations` | `before_llm_call` | `["<N>"]` (required) | Hard-stops the agent after `N` model calls. Stateless: the runtime supplies the iteration counter on every dispatch. |
| `snapshot` | `session_start`, `turn_start`, `turn_end`, `pre_tool_use`, `post_tool_use`, `session_end` | _none_ | Records filesystem snapshots in a shadow git repo under the Docker Agent data directory. No-op outside git repos; respects the source repo's ignore rules and skips newly-added files larger than 2 MiB. |
| `redact_secrets` | `tool_input_transform`, `before_llm_call`, `tool_response_transform` | _none_ | Scrubs detected secrets (API keys, tokens, private keys, …) out of tool call arguments, outgoing chat content, and tool output. The same builtin handles all three events and dispatches on the event name. Auto-registered on all three events by `redact_secrets: true` on the agent — see [`examples/redact_secrets_hooks.yaml`](https://github.com/docker/docker-agent/blob/main/examples/redact_secrets_hooks.yaml) for the manual wiring. |
| `redact_secrets` | `tool_input_transform`, `before_llm_call`, `tool_response_transform` | _none_ | Scrubs detected secrets (API keys, tokens, private keys, …) out of tool call arguments, outgoing chat content, and tool output, including the text of inline document attachments and the result metadata. The same builtin handles all three events and dispatches on the event name. Auto-registered on all three events by `redact_secrets: true` on the agent — see [`examples/redact_secrets_hooks.yaml`](https://github.com/docker/docker-agent/blob/main/examples/redact_secrets_hooks.yaml) for the manual wiring. |
| `transform_json` | `tool_response_transform` | JSON field names | Keeps only the named top-level fields of a JSON object. Nested values are preserved; missing fields are omitted. No expression language or domain validation. |
| `limit_large_tool_results` | `tool_response_transform`, `session_end` | _none_ | **Always-on safety hook** — automatically injected by the runtime, no configuration required. When a tool result from the `filesystem`, `shell`, `background_jobs`, `mcp`, or `a2a` categories exceeds 2,000 lines or 50 KiB, the full payload is written to a per-session temp file and replaced in the conversation with a notice plus a bounded excerpt (up to 2,000 excerpt lines; 50 KiB including the notice): the tail for most tools, but the head for the built-in filesystem `read_file`, whose notice suggests a follow-up call with `line`/`limit` to continue reading. If saving the payload fails, a bounded inline excerpt is returned without a file reference. Background-job excerpts retain status metadata before the log tail. The `session_end` leg deletes the temp directory. Internal toolsets (`memory`, `plan`, `tasks`, `think`, …) are not affected. |
| `keep_awake` | `session_start`, `session_end` | _none_ | CLI-owned sleep inhibitor, controlled by the disabled-by-default `settings.keep_awake` preference. |
Expand Down Expand Up @@ -427,8 +427,8 @@ In addition to the common fields, each event ships its own payload:
| `tool_input_transform` | `agent_name`, `tool_name`, `tool_use_id`, `tool_category`, `tool_input`, `safety_policy` |
| `tool_guard` | `agent_name`, `tool_name`, `tool_use_id`, `tool_category`, `tool_input`, `safety_policy` |
| `pre_tool_use` | `agent_name`, `tool_name`, `tool_use_id`, `tool_input` |
| `tool_response_transform` | `tool_name`, `tool_use_id`, `tool_input`, `tool_response`, `tool_result_meta` |
| `post_tool_use` | `agent_name`, `tool_name`, `tool_use_id`, `tool_input`, `tool_response`, `tool_error`, `tool_result_meta` |
| `tool_response_transform` | `tool_name`, `tool_use_id`, `tool_input`, `tool_response`, `tool_result_meta`, `tool_documents` |
| `post_tool_use` | `agent_name`, `tool_name`, `tool_use_id`, `tool_input`, `tool_response`, `tool_error`, `tool_result_meta`, `tool_documents` |
| `permission_request` | `agent_name`, `tool_name`, `tool_use_id`, `tool_input` |
| `session_start` | `source` — `startup` for each run stream |
| `user_prompt_submit` | `prompt` — the text the user just submitted |
Expand Down Expand Up @@ -659,9 +659,14 @@ The `hook_specific_output` for `tool_response_transform` supports:
| ----------------------- | ------ | --------------------------------------------- |
| `updated_tool_response` | string | Rewritten tool output (replaces the original) |
| `updated_tool_result_meta` | JSON | Replacement for the tool result's display metadata (for example, the recorded diff of an `edit_file` call). A JSON value replaces the metadata, `null` clears it, and omitting the field leaves it unchanged |
| `updated_tool_documents` | array | Replacement for the tool result's inline document attachments, in the `tools.DocumentContent` shape (`name`, `uri`, `mimeType`, `data`, `text`). MCP servers return text resources as documents with `text` set; they are emitted and persisted with the response, so scrub them here too. A present list replaces the attachments (an empty list drops them); omitting the field leaves them unchanged |

This is the symmetric counterpart of `tool_input_transform`'s `updated_input`, applied to tool **results** instead of tool **arguments**. The rewrite reaches every downstream consumer — event subscribers, the persisted session file, the `post_tool_use` hook input, and the next LLM call. Use it to truncate excessive output, scrub PII, or normalise tool dialects. The built-in `redact_secrets` registers itself on this event as the third leg of the redact_secrets feature.

Hooks on `tool_response_transform` and `post_tool_use` also receive `tool_documents`, the inline document attachments the tool returned. MCP servers return text resources this way (the payload is in `text`), and those documents are emitted to event subscribers and persisted in the session next to the textual output. Only `tool_response_transform` hooks can rewrite the list, with `updated_tool_documents`; the rewritten attachments are what gets emitted and persisted, and `post_tool_use` hooks receive the already-transformed list. `redact_secrets` scrubs each attachment's name, URI, MIME type, and text, so a secret carried in an MCP inline-text resource never reaches the session file or the event stream.

When the agent-level `redact_secrets` flag is on (the default) and other `tool_response_transform` hooks are configured, the auto-injected redactor runs both **before** and **after** them. The leading pass matters because command hooks receive the whole hook input as JSON on stdin: without it, a hook that archives its input would record the raw tool output, display metadata, and inline document attachments. The trailing pass is the final scrub, so a later rewrite that reintroduces a secret is still caught. Configured hooks therefore observe the already-redacted values, with detected secrets replaced by markers.

Hooks on `tool_response_transform` and `post_tool_use` also receive `tool_result_meta`, the structured display metadata a tool recorded alongside its text output (the TUI renders completed `edit_file` diffs from it). Only `tool_response_transform` hooks can rewrite it, with `updated_tool_result_meta` (independently of `updated_tool_response`); the rewritten metadata is what gets emitted and persisted. `post_tool_use` hooks receive the already-transformed metadata and cannot change it. `redact_secrets` also scrubs this metadata, and clears it when it cannot be serialized safely.

### Composing transformations
Expand All @@ -673,19 +678,26 @@ Hooks for the following events run **sequentially in configuration order**:
| `tool_input_transform` | `updated_input` | `tool_input` with the patch applied |
| `pre_tool_use` (default lane) | `updated_input` | `tool_input` with the patch applied |
| `before_llm_call` | `updated_messages` | The rewritten `messages` array |
| `tool_response_transform` | `updated_tool_response`, `updated_tool_result_meta` | The rewritten `tool_response` string and `tool_result_meta` |
| `tool_response_transform` | `updated_tool_response`, `updated_tool_result_meta`, `updated_tool_documents` | The rewritten `tool_response` string, `tool_result_meta`, and `tool_documents` list |

Every matching hook on these events participates in the sequence, whether it
rewrites, observes, or returns a verdict. Each hook sees the most recent
successful rewrite. Hooks that return no rewrite leave the current value
unchanged; the runtime receives the final result of the sequence.
unchanged; the runtime receives the final result of the sequence. The
runtime's auto-injected defaults respect that order: the always-on
`limit_large_tool_results` runs last, and when `redact_secrets` is enabled it
runs both ahead of the configured transforms (so command hooks never receive
raw tool results on stdin) and after them (so a later rewrite is still
scrubbed).

`updated_input` patches replace only the top-level keys they supply. Other
arguments are preserved; nested objects are replaced, not deep-merged. An empty
patch does not clear the arguments. Omitting a key no longer removes it; this
patch protocol does not support key deletion. `updated_messages` replaces the entire
message array, with an empty array treated as no rewrite. An explicit empty
`updated_tool_response` **does** clear the response.
`updated_tool_response` **does** clear the response. A present
`updated_tool_documents` list, including an empty one, replaces the
attachments; omitting the field keeps the current list.

Verdicts still aggregate across all matching hooks: a later allow cannot undo
a denial, and `pre_tool_use` keeps `deny > ask > allow` precedence. Blocking
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/secrets/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Secret redaction is enabled by default as a defense in depth. Set `redact_secret

- the arguments of every outgoing tool call (before the tool sees them),
- every outgoing chat message (before the model provider sees them), and
- every tool's output (before it reaches event consumers, the persisted session file, the `post_tool_use` hook input, or the next LLM call).
- every tool's output, including the text of the inline document attachments it returns (before they reach event consumers, the persisted session file, the `post_tool_use` hook input, or the next LLM call).

```yaml
agents:
Expand Down
43 changes: 39 additions & 4 deletions pkg/hooks/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ type AutoInjector interface {
AutoInject(cfg *hooks.Config)
}

// ApplyAgentDefaults appends the stock builtin hook entries implied by
// d to cfg. A nil cfg is treated as empty. Returns nil iff no hook
// ApplyAgentDefaults adds the stock builtin hook entries implied by d to
// cfg, appending them after any user-configured hooks. There is one
// deliberate exception: when d.RedactSecrets is set and cfg already
// carries configured tool_response_transform hooks, a named redaction
// pass is inserted ahead of them so command hooks cannot observe raw
// tool output, display metadata, or inline document attachments on
// stdin. A nil cfg is treated as empty. Returns nil iff no hook
// (user-configured or auto-injected) is present.
//
// Snapshot auto-injection is handled separately via [SnapshotController]
Expand Down Expand Up @@ -201,10 +206,40 @@ func ApplyAgentDefaults(cfg *hooks.Config, d AgentDefaults) *hooks.Config {
Hooks: []hooks.Hook{builtinHook(RedactSecrets)},
})
cfg.BeforeLLMCall = append(cfg.BeforeLLMCall, builtinHook(RedactSecrets))
cfg.ToolResponseTransform = append(cfg.ToolResponseTransform, hooks.MatcherConfig{

// tool_response_transform carries the tool's textual output, its
// display metadata, and (since attachments became part of the hook
// protocol) the inline document attachments MCP servers return as
// text resources. Configured transforms must not see those fields
// unredacted: command hooks receive the whole hook input as JSON on
// stdin, so a hook that archives its input would record credentials
// that redact_secrets is supposed to keep out of downstream
// consumers. Run the redactor ahead of the configured transforms,
// and keep the trailing entry as the final pass so a later rewrite
// that reintroduces a secret is scrubbed before emission,
// persistence, and the next LLM call.
//
// The preamble is only injected when there are configured
// transforms to protect; with none there is no hook to leak to and
// a single pass keeps the per-tool-result cost unchanged. It also
// carries its own Name: the executor deduplicates identical hooks,
// and without the name it would collapse into the trailing pass.
responseRedactor := hooks.MatcherConfig{
Matcher: "*",
Hooks: []hooks.Hook{builtinHook(RedactSecrets)},
})
}
if len(cfg.ToolResponseTransform) > 0 {
preamble := hooks.MatcherConfig{
Matcher: "*",
Hooks: []hooks.Hook{{
Name: "redact_secrets (before configured hooks)",
Type: hooks.HookTypeBuiltin,
Command: RedactSecrets,
}},
}
cfg.ToolResponseTransform = append([]hooks.MatcherConfig{preamble}, cfg.ToolResponseTransform...)
}
cfg.ToolResponseTransform = append(cfg.ToolResponseTransform, responseRedactor)
}
// Redact before the limiter writes oversized responses to disk.
cfg.ToolResponseTransform = append(cfg.ToolResponseTransform, hooks.MatcherConfig{
Expand Down
Loading