Gemini models, Fallback provider & per-agent configuration

Gemini models, Fallback provider & per-agent configuration

LarAgent brings more flexibility, reliability, and control to your AI agent in Laravel!

This update introduces support for Gemini models, per-agent API configuration, and a robust fallback mechanism for enhanced fault tolerance — plus a handy event to help you monitor failures in real time.

Let’s break it down 👇

🔹 Gemini Driver Support

You can now use Google’s Gemini models via:

LarAgent\Drivers\OpenAi\GeminiDriver::class

Whether you’re looking for an alternative to OpenAI or want to test Gemini’s capabilities in your agent workflows, this driver makes the switch effortless.

🔹 Per-Agent $apiKey & $apiUrl

Configure your agents independently, each with their own API key and endpoint.

You can now override these per agent:

protected $apiKey;
protected $apiUrl;

Or use custom logic by overriding:

public function getApiKey(): string {
  return auth()->user()->OpenAiApiKey;
}

public function getApiUrl(): string {
  return $this->fineTunedModelUrl;
}

You can fetch from the database based on tenant ID, user preferences, etc.
This makes multi-tenant setups and dynamic changes a breeze!

🔹 Fallback Provider

Introducing automatic fallback when your primary LLM provider fails.

If a call fails (e.g. rate limit, network error), LarAgent will now retry the same call using your defined fallback provider before throwing an error.

This ensures higher reliability in production environments.

Check it in config/laragent.php

/**
 * Fallback provider to use when any provider fails
 * Fallback currently works only for respond method
 * In case of streaming, No auto switch to fallback
 */
'fallback_provider' => 'default',

You can set it to null or remove completely to disable the fallback feature.

🔹 onEngineError Event

Get notified when your provider fails!

This new event is triggered if a provider doesn’t return a response, right before the fallback provider runs, giving you a hook to log, alert, or adapt in real time. Hook into from your agent class:

//...

protected function onEngineError(\Throwable $th)
{
    // Your custom logic here
}

🧪 These features are already merged and will be available in the upcoming v0.4 release.

We're building LarAgent to be the most developer-friendly AI agent framework in the Laravel ecosystem — and we're just getting started.

Stay tuned, and happy building! 🚀

Read more