Extend the runtime#
Reach for an extension when behavior belongs inside the request lifecycle:
restoring history, reshaping context, adding tools, asking the user, or emitting
UI events. For display-only callbacks, use an
AgentEventDispatcher instead. You never subclass
Agent or write a second model loop.
Register a tool, transform input, emit an event, and clean up.
Sessions, compaction, subagents, approvals, skills, MCP, and more.
Every hook boundary and which one to override for a given job.
Wrap each provider request or tool call, in a documented order.
Publish notifications and route responses back into a running request.
Keep per-request data safe when one instance serves many sessions.
Add a provider or normalize a protocol the built-ins do not cover.
Declare provider-hosted tools such as web search or code execution.
Persist raw history and compaction checkpoints in your own store.
Suggested path: build your first extension, learn the event channels, then add state and cancellation handling. Implement a new provider or storage adapter only when an existing one cannot satisfy your application boundary.