Lifecycle hooks
Hooks are methods the SDK calls for you when an agent starts or ends, around every model call, around every tool call and on a handoff. Watch them fire in order, and see the difference between run hooks and agent hooks.
10 minPro
Checking your access…
Inside this lesson
- An animation you play, pause and step through, with each part saying what it is doing.
- The real code beside it, with the lines for each step lit up.
- Practice mode, where you route each message yourself, and a short quiz.
- About 10 minutes.
Written from the official documentation
In this module: Agents in depth
- Instructions, prompt templates and cloningStatic or dynamic instructions, stored prompts and agent copies.Pro
- Output types and tool use behaviorTyped final output, forced tool calls and when a run stops.Pro
- Lifecycle hooksRun code when agents, tools and model calls start and end.Pro
- Context and RunContextWrapperPass your own data to tools and hooks without showing the model.Pro