Agent classes are the foundation of everything in LarAgent. They define how your AI assistants behave, what capabilities they have, and how they process information.
Other LarAgent features like Tools, Storage, Prompts, etc all revolve around agents.
What are Agents?
In LarAgent, an Agent is a PHP class that represents an AI-powered assistant. Each agent encapsulates:- Instructions — The system prompt that defines the agent’s personality, role, and behavior
- Model configuration — Which LLM to use and how it should respond
- Tools — Functions the agent can call to perform actions or retrieve information
- Context — How conversations (chat history) and other data models are stored and retrieved
CustomerSupportAgent for handling support tickets, a DataAnalysisAgent for processing reports, or a SchedulingAgent for managing appointments.
Or one agent that ochestrates all mentioned above!
Why Agents?
LarAgent’s agent-centric architecture provides several benefits:Reusability
Define an agent once and use it across your application with different chat sessions.
Encapsulation
Keep all AI-related configuration in one place — instructions, tools, and settings.
Testability
Test your agents in isolation with predictable inputs and outputs.
Flexibility
Override any configuration at runtime for specific use cases.
Agent Lifecycle
When you interact with an agent, here’s what happens:1
Initialization
The agent is created with its configured instructions, model, and tools.
2
Message Processing
Your message passes through the
prompt() method, where you can add context or transform the input.3
LLM Request
The agent sends the conversation history and your message to the configured LLM.
4
Tool Execution
If the LLM requests tool calls, the agent executes them and continues the conversation.
5
Response
The final response is returned and stored in the chat history.

