> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laragent.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get started with LarAgent in minutes

## Requirements

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

* Laravel 10.x or higher
* PHP 8.3 or higher
* OpenAI API key or other [supported LLM provider](/core-concepts/llm-drivers#available-drivers) API key

## Installation

You can install LarAgent via Composer:

```bash theme={null}
composer require maestroerror/laragent
```

After installing the package, publish the configuration file:

```bash theme={null}
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
```

### Configuration file

The published configuration file contains the following settings and default providers:

<Warning>
  Configuration file provided below is an example, please refer to the [latest version](https://github.com/MaestroError/LarAgent/blob/main/config/laragent.php) of config file.
</Warning>

```php theme={null}
// config for Maestroerror/LarAgent
return [
    'default_driver' => \LarAgent\Drivers\OpenAi\OpenAiCompatible::class,
    'default_chat_history' => \LarAgent\History\InMemoryChatHistory::class,

    'namespaces' => [
        'App\\AiAgents\\',
        'App\\Agents\\',
    ],

    'providers' => [
        'default' => [
            'label' => 'openai',
            'api_key' => env('OPENAI_API_KEY'),
            'driver' => \LarAgent\Drivers\OpenAi\OpenAiDriver::class,
            'default_truncation_threshold' => 50000,
            'default_max_completion_tokens' => 10000,
            'default_temperature' => 1,
        ],

        'gemini' => [
            'label' => 'gemini',
            'api_key' => env('GEMINI_API_KEY'),
            'driver' => \LarAgent\Drivers\OpenAi\GeminiDriver::class,
            'default_truncation_threshold' => 1000000,
            'default_max_completion_tokens' => 10000,
            'default_temperature' => 1,
        ],

        'gemini_native' => [
            'label' => 'gemini',
            'api_key' => env('GEMINI_API_KEY'),
            'driver' => \LarAgent\Drivers\Gemini\GeminiDriver::class,
            'default_truncation_threshold' => 1000000,
            'default_max_completion_tokens' => 10000,
            'default_temperature' => 1,
        ],

        'groq' => [
            'label' => 'groq',
            'api_key' => env('GROQ_API_KEY'),
            'driver' => \LarAgent\Drivers\Groq\GroqDriver::class,
            'default_truncation_threshold' => 131072,
            'default_max_completion_tokens' => 131072,
            'default_temperature' => 1,
        ],

        'claude' => [
            'label' => 'claude',
            'api_key' => env('ANTHROPIC_API_KEY'),
            'model' => 'claude-3-7-sonnet-latest',
            'driver' => \LarAgent\Drivers\Anthropic\ClaudeDriver::class,
            'default_truncation_threshold' => 200000,
            'default_max_completion_tokens' => 8192,
            'default_temperature' => 1,
        ],

        'openrouter' => [
            'label' => 'openrouter',
            'api_key' => env('OPENROUTER_API_KEY'),
            'model' => 'openai/gpt-oss-20b:free',
            'driver' => \LarAgent\Drivers\OpenAi\OpenRouter::class,
            'default_truncation_threshold' => 200000,
            'default_max_completion_tokens' => 8192,
            'default_temperature' => 1,
        ],

        'ollama' => [
            'label' => 'ollama',
            'driver' => \LarAgent\Drivers\OpenAi\OllamaDriver::class,
            'default_truncation_threshold' => 131072,
            'default_max_completion_tokens' => 131072,
            'default_temperature' => 0.8,
        ],
    ],

    'fallback_provider' => null,
];

```

### Custom Providers

You can configure additional providers with custom settings:

```php theme={null}
// 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_truncation_threshold' => 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:

```bash theme={null}
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

<CodeGroup>
  ```php with chat name theme={null}
  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..."

  ```

  ```php with random chat theme={null}
  use App\AiAgents\WeatherAgent;

  // Create instance with random chat history name
  $response = WeatherAgent::make()
      ->withTemperature(0.7)
      ->message("What's the weather like in Boston?")
      ->respond();

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

  ```

  ```php shorthand theme={null}
  use App\AiAgents\WeatherAgent;

  // Create instance with random chat history name
  $response = WeatherAgent::ask("What's the weather like in Boston?");

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

  ```
</CodeGroup>

### Adding Tools

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

```php theme={null}
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:

<CardGroup>
  <Card title="Agents" icon="user-robot" href="/v1/agents/overview">
    Learn more about creating and configuring agents
  </Card>

  <Card title="Tools" icon="screwdriver-wrench" href="/v1/tools/overview">
    Discover how to create powerful tools for your agents
  </Card>

  <Card title="Structured Output" icon="brackets-curly" href="/v1/responses/structured-output">
    Get responses in structured formats like JSON
  </Card>

  <Card title="Streaming" icon="wave-sine" href="/v1/responses/streaming">
    Stream responses in real-time for better UX
  </Card>
</CardGroup>
