Event-driven subscriber system for agent lifecycle and event handling
AgentSubscriber
interface provides a comprehensive event-driven system for
handling agent lifecycle events, message updates, and state mutations during
agent execution. It allows you to hook into various stages of the agent’s
operation and modify its behavior.
AgentSubscriber
defines a collection of optional event handlers and lifecycle
hooks that can respond to different stages of agent execution. All methods in
the interface are optional, allowing you to implement only the events you need
to handle.
All subscriber methods can be either synchronous or asynchronous - if they
return a Promise, the agent will await their completion before proceeding.
subscribe()
method to add a subscriber that will persist across
multiple agent runs:
runAgent()
for one-time use:
AgentStateMutation
object to modify the agent’s
state and control event processing:
true
, prevents subsequent subscribers from handling
the event (useful for overriding default behavior)