Agents
Agents are the core of LarAgent. They represent an AI model that can be used to interact with users, systems, or any other source of input.
Agents are the foundation of LarAgent. They define how your AI assistant behaves, what tools it can use, and how it processes information.
Creating an Agent
You can create a new agent manually by extending the LarAgent\Agent
class. This is the parent class for building your custom AI agent with specific capabilities and behaviors.
Using make:agent
command is a recommended way of creating agents.
For rapid development, you can use the artisan command to generate a new agent with a basic structure:
This will create a new agent class in the App\AiAgents
directory with all the necessary boilerplate code:
Configuring an Agent
Agents can be configured through various properties and methods to customize their behavior. Here are the core configuration options:
This property sets the system instructions for your agent, defining its behavior, personality, and capabilities.
This property sets the system instructions for your agent, defining its behavior, personality, and capabilities.
Choose from built-in chat history implementations: “in_memory”, “session”, “cache”, “file”, or “json”.
The driver class that handles communication with the AI provider.
References a provider configuration from your config file.
The specific model to use from your chosen provider.
Limits the length of the AI’s response.
Controls randomness: 0.0 for focused responses, 2.0 for creative ones.
Holds the current message that the agent is processing.
Core methods
The agent also provides three core methods that you can override to customize its behavior:
Using an Agent
There are two ways to interact with your agent: direct response or chainable methods.
Direct Response
The simplest way is to use the for()
method to specify a chat history name and get an immediate response:
Chainable Methods
For more control over the interaction, you can use the chainable syntax:
Chainable Methods Reference
Here are some chainable methods to modify the agent’s behavior on the fly:
Agent Accessors
You can access the agent’s properties using these methods on an instance of the agent: