Creating an Agent
The recommended way to create a new agent is using the artisan command:App\AiAgents directory with all the necessary boilerplate:
App/AiAgents/MyAgent.php
Core Methods
Override these methods to customize your agent’s behavior:instructions()
The system prompt that shapes how your agent responds. This defines the agent’s personality, role, and guidelines.prompt()
Process or augment the user’s message before sending it to the LLM. Useful for adding context, formatting, or implementing RAG patterns.model()
Dynamically determine which model to use based on custom logic:API Key and URL
Override these methods to dynamically set API credentials:Configuration Properties
Model & Provider
| Property | Type | Description |
|---|---|---|
$model | string | The LLM model to use (e.g., gpt-4o-mini, gpt-4o) |
$provider | string | Provider configuration name from config/laragent.php |
$driver | string | Driver class for LLM communication |
Response Settings
Control how the LLM generates responses:$temperature — Control creativity
$temperature — Control creativity
Controls randomness in responses. Range:
0.0 (focused/deterministic) to 2.0 (creative/random).$maxCompletionTokens — Limit response length
$maxCompletionTokens — Limit response length
Maximum number of tokens in the AI’s response.
$n — Multiple responses
$n — Multiple responses
Generate multiple completion choices. Note: You’ll be charged for all generated tokens.
$topP — Nucleus sampling
$topP — Nucleus sampling
Alternative to temperature. The model considers tokens with top_p probability mass.
$frequencyPenalty — Reduce repetition
$frequencyPenalty — Reduce repetition
Penalizes tokens based on their frequency in the text. Range:
-2.0 to 2.0.$presencePenalty — Encourage new topics
$presencePenalty — Encourage new topics
Penalizes tokens based on whether they’ve appeared. Range:
-2.0 to 2.0.All configuration properties can also be set via the provider settings in
config/laragent.php.History & Tools
| Property | Type | Description |
|---|---|---|
$history | string | Chat history storage: in_memory, session, cache, file |
$tools | array | Array of tool classes the agent can use |
Both Context (chat history, data models) and Tools are core features of LarAgent with extensive configuration options. The properties shown here are just the basics.
- Learn about context management, storage drivers, and truncation strategies in the Context page
- Explore tool creation, parameters, and execution in the Tools Section
Arbitrary Configuration
Pass custom configuration values to the driver for provider-specific settings or experimental features:Custom configurations are passed directly to the driver, allowing you to leverage provider-specific features without modifying the agent’s core properties.
Runtime Configuration
Override any configuration at runtime using chainable methods:$temperature→temperature(float $temp)$maxCompletionTokens→maxCompletionTokens(int $tokens)$topP→topP(float $value)- And so on…

