Hooks — extension

Hooks implemented outside the core. For a list of all hooks, see 06-hooks-reference.


6.21 script_hook

A script hook in Rhai or JavaScript: implements any lifecycle point in a script. Syntax and helpers — 07-scripts.


agent_events

A native (non-script) agent action log. Keeps events in an in-memory ring buffer (no disk) at selected lifecycle points; the paired route GET /v1/events exposes the log externally with long-poll and cursor drain. Implementation — module agent_os_events (hook::EventsFactory).

Process memory: events do not survive a restart and do not allow a disconnected consumer to "catch up" — for a live stream/dashboard this is sufficient and cheaper (a durable log is a separate task).

# config/agents/<agent>/hooks/events.yaml
kind: agent_events
name: agent_events
agent: <agent>                          # по умолчанию — name хука
on: [after_tool_result, after_turn]     # по умолчанию [after_tool_result]
ignore: [settings_get]                  # не логировать эти инструменты
mutating: [order_create, order_cancel]  # пометить как изменение состояния
capacity: 5000                          # размер кольцевого буфера
show_notice: false                      # notice в чат-UI на каждое событие
Field Description
agent agent label in the event; by default — the hook's name
on points: after_tool_result, after_turn, after_loop, on_terminate, on_error, on_budget_threshold
watch / ignore tool filter (empty = all except ignore)
mutating tools marked as state-changing
capacity size of the in-memory ring buffer (events)
show_notice / notice notification to the chat UI on each event

A minimum is written: seq, ts, agent, session, user_id, tool, kind, mutating, success, args_fp, detail (args_fp — a non-cryptographic fingerprint of the arguments, FNV-1a; the arguments themselves and the result are not stored). Externally, the log exposes GET /v1/events (admin): ?mode=drain|wait|events|version, a batch of events seq > since, has_more/dropped_window. The full contract and client loop — in Event subscriptions.


dll_hook

A hook from a native Rust DLL (C ABI). The plugin implements any lifecycle point of the core; JSON arguments (before_tool_call args, after_tool_result data/visual, before_inference request) are passed as UTF-8 JSON.

# config/agents/<name>/hooks/audit.yaml
kind: dll_hook
path: plugins/echo.dll
hook: audit               # имя kind, зарегистрированного плагином

Lifecycle points — Basics; build and C ABI — 20-native-plugins.