Hooks are eve’s authored extension points for the runtime event stream. A hook subscribes to stream events and runs side effects after each event is durably recorded — audit logging, metrics, alerting, or persisting every session and message to your own database. Reach for a hook to observe what the agent does without writing a tool, a context provider, or a channel adapter handler.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/eve/llms.txt
Use this file to discover all available pages before exploring further.
Define a hook
Hook files live underagent/hooks/. The slug is the path-relative basename: agent/hooks/audit.ts becomes "audit", and agent/hooks/auth/load-profile.ts becomes "auth/load-profile".
agent/hooks/audit.ts
defineHook, HookDefinition, and HookContext all live on eve/hooks.
Declare stream-event subscribers under the events map, keyed by event type. Use * to match every event. You can subscribe to any event in the runtime stream vocabulary — including lifecycle events like session.started, turn.started, turn.completed, message.completed, and action.result.
Hook handlers are observe-only. They cannot inject model context. To contribute runtime model messages, use
defineDynamic and defineInstructions in agent/instructions/.Hook context
Every handler receives the sameHookContext as its second argument:
Lifecycle events
Common events to subscribe to in hooks:| Event | When it fires |
|---|---|
session.started | A new session begins. |
turn.started | A new turn begins within the session. |
turn.completed | A turn finishes successfully. |
turn.failed | A turn finishes with an error. |
message.completed | The model completes a message. |
action.result | A tool call returns a result. |
actions.requested | The model requests tool calls. |
input.requested | A tool or the model requests human input. |
session.completed | The session ends successfully. |
session.failed | The session ends with a terminal failure. |
* | Every event in the stream. |
Narrowing tool results
toolResultFrom narrows an action.result event to a specific authored tool or MCP connection and returns typed output. Import it from eve/tools:
agent/hooks/log-results.ts
toolResultFrom returns undefined when the result doesn’t match, or when isError is true. For authored tools, the return includes { output, toolName, callId } with output typed as the tool’s TOutput. For connections, it includes { output, toolName, connectionToolName, callId } with output as unknown.
A complete observability example
agent/hooks/observability.ts
Execution order
When a stream event fires, three things happen in order:- Emit. The channel adapter handler runs, then the event is written to the durable stream.
- Hooks. Stream-event hooks fire (typed handlers first, then the
*wildcard). Return values are ignored. - Dynamic tool resolvers. Resolvers subscribed to the event type run and update the tool set.
Error handling
A thrown handler propagates through the emit composer and surfaces asturn.failed. If a hook subscribed to a failure-cascade event also throws, it escalates to session.failed. For belt-and-suspenders semantics inside a hook, wrap the body in try/catch — eve treats a thrown hook as a real failure.
Subagent isolation
Subagents may carry their ownagent/hooks/ directory. Subagent hooks fire only inside the subagent scope. Parent-agent hooks do not fire for subagent turns, and subagent hooks see only the subagent’s own context.
Hook vs tool vs context provider
| Need | Use |
|---|---|
| Observe runtime events (audit, metrics, alerting) | events.<type> hook (or a channel adapter handler) |
| Provide structured input to the model on demand | A tool |
| Make a value available across the entire step | A context provider |
| Subscribe to platform-specific events | A channel adapter handler |
events.* when authoring agent-level behavior that should fire across every channel.
File structure
What to read next
State
Read and write durable per-session state from inside hooks
Tools
The surface most hooks observe through action.result events
Schedules
Use hooks to observe lifecycle events from scheduled sessions
Sessions & Streaming
The full event stream vocabulary hooks subscribe to