Hooks let you log, time, or measure agent execution without touching the agent logic itself. Pass aDocumentation Index
Fetch the complete documentation index at: https://docs.opper.ai/llms.txt
Use this file to discover all available pages before exploring further.
Hooks object to the agent constructor.
Lifecycle events
| Hook | Fired when |
|---|---|
on_agent_start / onAgentStart | A run begins. |
on_agent_end / onAgentEnd | A run completes (or fails). |
on_iteration_start / onIterationStart | A new think→act cycle. |
on_llm_call / onLLMCall | About to send a request to the model. |
on_llm_response / onLLMResponse | Got a model response. |
on_tool_start / onToolStart | About to execute a tool. |
on_tool_end / onToolEnd | Tool finished (with duration_ms). |
Example
Common uses
- Logging — print or ship events to your logger.
- Timing — accumulate
duration_msper tool to find bottlenecks (see05_hooks_timing). - Custom metrics — push counters / histograms to your metrics backend.
- Span enrichment — attach extra metadata to the trace span the SDK already creates.