Skip to content

ACP host hooks — permission, updates, cancel, stream

Python · package toolnexus · SPEC §8

Opt-in hooks on an ACP model source: choose the permission option, watch every session/update, cancel a turn, and stream through an in-process client.

Python ships the ACP model source itself — load_acp(ACPOptions(command=..., args=[...])) returns a warm ACPClient whose generate you hand to create_in_process_client(model=..., generate=acp.generate) — but not the four host hooks. Today, in Python:

  • Permissions are answered by the client with the first option whose kind starts with allow; there is no on_permission callback. To gate what the agent may do, start it in a restricted mode (ACPOptions(mode=...), sent as session/set_mode) or a sandboxed cwd. permission_timeout (default 5 s) bounds a turn.
  • Updates: only agent_message_chunk text forms the reply; thoughts, tool calls and plans are not surfaced (no on_update).
  • Cancel and streaming are not available: generate is synchronous and a client built on it runs non-streaming only. Use client.run and show the final text.

The Go port has all four (Go reference); the other ports are tracked in openspec/changes/add-go-host-asks task 2.6d.

  • create_client — The unified client: system prompt, skills injection, parallel and chained tool calls, retries, memory.
  • Client.run — Send a prompt, let the loop call tools until the model stops, get a RunResult.
  • Client.stream — The streaming loop: text deltas, tool-call events, and suspension events as they happen.
  • Hooks — Intercept before/after model calls and tool calls: audit, redact, veto, or rewrite.