Available Events
| Event | Description |
|---|---|
agent:start | Agent begins processing |
agent:end | Agent completes processing |
loop:start | Iteration begins |
loop:end | Iteration completes |
llm:call | LLM request sent |
llm:response | LLM response received |
think:end | Agent finished thinking |
tool:before | Before tool execution |
tool:after | After tool execution |
tool:error | Tool threw an error |
memory:read | Memory entries read |
memory:write | Memory entry written |
memory:error | Memory operation failed |
stream:start | Streaming begins |
stream:chunk | Stream chunk received |
stream:end | Streaming completes |
stream:error | Streaming encountered an error |
Registering Hooks
Python: Decorator Pattern
TypeScript: Event Emitter Pattern
In TypeScript,agent.on() and agent.registerHook() are equivalent—both use the same unified hook system and work for all 17 events.
Hook Payloads
Agent Context
All hooks receive the agent context:Tool Events
Common Use Cases
Logging
Metrics Collection
Cost Tracking
Progress Reporting
Streaming Hooks
For streaming-enabled agents:Error Handling in Hooks
Hooks are wrapped in try/catch to prevent breaking agent execution:Best Practices
- Keep hooks fast: Long-running hooks delay agent execution
- Handle errors: Don’t let hook errors crash your application
- Use async: For I/O operations in hooks
- Be selective: Only subscribe to events you need
- Avoid side effects: Hooks should observe, not modify
Next Steps
Streaming
Real-time token streaming
Execution Loop
Understand what hooks observe