Skip to main content
LarAgent dispatches Laravel events at key points during agent execution. This allows you to hook into the agent lifecycle using Laravel’s native event system for logging, monitoring, analytics, and more.

Quickstart

1

Create a listener

2

Import the event and implement the handler

3

Register the event listener

Open app/Providers/AppServiceProvider.php and register the event with its listener:
Now whenever an agent is initialized, your handle method will be executed.

AgentDTO Structure

Each event that includes agentDto uses the following Data Transfer Object structure:

Available Events

LarAgent provides events across different categories:

Agent Events

Lifecycle events for agent initialization, conversation flow, and termination.

Context Events

Events for context storage operations and state changes.

History Events

Events for chat history operations and message handling.

Events vs Agent Hooks

LarAgent provides two ways to customize behavior:
Use agent hooks for agent-specific customizations that need to modify behavior. Use Laravel events for logging, monitoring, analytics, and other cross-cutting concerns that should be decoupled from your agent classes.

Queueable Listeners

For heavy processing, implement ShouldQueue to handle events asynchronously: