Requirements

Before installing LarAgent, make sure your environment meets the following requirements:

Installation

You can install LarAgent via Composer:

composer require maestroerror/laragent

After installing the package, publish the configuration file:

php artisan vendor:publish --tag="laragent-config"

This will create a config/laragent.php file in your application.

Configuration

OpenAi

If you are using OpenAI API, just set your API key in your .env file and you are good to go:

OPENAI_API_KEY=your-openai-api-key

Basic Configuration

The published configuration file contains the following default settings:

return [
    'default_driver' => \LarAgent\Drivers\OpenAi\OpenAiDriver::class,
    'default_chat_history' => \LarAgent\History\InMemoryChatHistory::class,

    'providers' => [
        'default' => [
            'label' => 'openai',
            'api_key' => env('OPENAI_API_KEY'),
            'default_context_window' => 50000,
            'default_max_completion_tokens' => 10000,
            'default_temperature' => 1,
        ],
    ],
];

Custom Providers

You can configure additional providers with custom settings:

// Example custom provider with all possible configurations
'custom_provider' => [
    // Just name for reference, changes nothing
    'label' => 'custom',
    'api_key' => env('PROVIDER_API_KEY'),
    'api_url' => env('PROVIDER_API_URL'),
    // Defaults (Can be overriden per agent)
    'model' => 'your-provider-model',
    'driver' => \LarAgent\Drivers\OpenAi\OpenAiDriver::class,
    'chat_history' => \LarAgent\History\InMemoryChatHistory::class,
    'default_context_window' => 15000,
    'default_max_completion_tokens' => 100,
    'default_temperature' => 0.7,
    // Enable/disable parallel tool calls
    'parallel_tool_calls' => true,
    // Store metadata with messages
    'store_meta' => true,
    // Save chat keys to memory via chatHistory
    'save_chat_keys' => true,
],

Creating Your First Agent

Using Artisan Command

The quickest way to create a new agent is using the provided Artisan command:

php artisan make:agent WeatherAgent

This will create a new agent class in the App\AiAgents directory with all the necessary boilerplate code.

Basic Usage

Simple Response

use App\AiAgents\WeatherAgent;

// Create an instance for a specific user or chat session
$agent = WeatherAgent::for('user-123');

// Get a response
$response = $agent->respond('What\'s the weather like in Boston?');

echo $response; // "The weather in Boston is currently..."

Adding Tools

Tools allow your agent to perform actions and access external data:

namespace App\AiAgents;

use LarAgent\Agent;
use LarAgent\Attributes\Tool;

class WeatherAgent extends Agent
{
    // ... other properties

    #[Tool('Get the current weather in a given location')]
    public function getCurrentWeather($location, $unit = 'celsius')
    {
        // Call a weather API or service
        return "The weather in {$location} is 22 degrees {$unit}.";
    }
}

Next Steps

Now that you have LarAgent set up, you can explore more advanced features: