Quickstart
Start with creation of the listener:Name
AgentListener is used as example, you can name it as you wishapp\Providers\AppServiceProvider.php and register event with listener:
handle method will be executed.
Available Events
AgentDTO Structure
Each event that includes
agentDto uses the following Data Transfer Object
structure:Lifecycle Events
These events track the main lifecycle stages of an agent conversation.AgentInitialized
Dispatched when the agent completes its initialization process and is ready to handle conversations. Namespace:Complete agent configuration including provider, tools, instructions, and
response schema.
ConversationStarted
Dispatched when therespond() method begins execution, marking the start of a new conversation turn.
Namespace:
Current agent configuration at the start of the conversation.
ConversationEnded
Dispatched when therespond() method completes execution, indicating the end of a conversation turn.
Namespace:
Final agent configuration at the end of the conversation.
The final response message or null if no response was generated.
ToolChanged
Dispatched when tools are dynamically added to or removed from the agent during runtime. Namespace:Current agent configuration.
The tool instance that was added or removed.
true if the tool was added, false if it was removed.AgentCleared
Dispatched when the agent’s state is cleared, typically resetting conversation history and context. Namespace:Agent configuration at the time of clearing.
EngineError
Dispatched when an error occurs in the LLM engine during processing. Namespace:Agent configuration when the error occurred.
The exception that was thrown by the LLM engine.
Hook Events (Before/After)
These events provide hooks before and after critical operations, allowing you to modify behavior or track execution flow.BeforeReinjectingInstructions
Dispatched before instructions are reinjected into the conversation history. Namespace:Current agent configuration.
The chat history interface before instruction reinjection.
BeforeSend
Dispatched just before adding message in chat history Namespace:Current agent configuration.
The complete conversation history being sent.
The message about to be sent, or null if sending history only.
AfterSend
Dispatched immediately after adding LLM response to Chat history. Namespace:Current agent configuration.
The conversation history that was sent.
The message that was successfully sent.
BeforeSaveHistory
Dispatched before persisting the conversation history to storage. Namespace:Current agent configuration.
The conversation history about to be saved.
BeforeResponse
Dispatched before sending message to LLM Namespace:Current agent configuration.
Current conversation history including the new response.
The message that is about to sent to the LLM API or
null.AfterResponse
Dispatched right after receiving a message from LLM API Namespace:Current agent configuration.
The response message.
BeforeToolExecution
Dispatched just before a tool is executed by the agent. Namespace:Current agent configuration.
The tool instance about to be executed.
The tool call instance is going to be executed. Get details with
getId,
getToolName, & getArguments methodsAfterToolExecution
Dispatched immediately after a tool completes execution. Namespace:Current agent configuration.
The tool instance that was executed.
The tool call instance is going to be executed. Get details with
getId,
getToolName, & getArguments methodsThe result returned by the tool execution.
BeforeStructuredOutput
Dispatched before processing structured output from the LLM response. Namespace:Current agent configuration including the response schema.
The raw structured response array before processing.

