Skip to main content
Hooks let you log, time, or measure agent execution without touching the agent logic itself. Pass a Hooks object to the agent constructor.

Lifecycle events

Example

Common uses

  • Logging: print events or ship them to your logger.
  • Timing: add up duration_ms per tool to find bottlenecks (see 05_hooks_timing).
  • Custom metrics: push counters or histograms to your metrics backend.
  • Span enrichment: attach extra metadata to the trace span the SDK already creates.
Hooks sit on top of built-in tracing. Every run, LLM call, and tool execution already lands in the Opper dashboard without any setup.