What is LarAgent?

What if you can create AI agents just like you create any other Eloquent model?

Why not?! 👇

php artisan make:agent YourAgentName

And it looks familiar, isn’t it?

namespace App\AiAgents;

use LarAgent\Agent;

class YourAgentName extends Agent
{
    protected $model = 'gpt-4';

    protected $history = 'in_memory';

    protected $provider = 'default';

    protected $tools = [];

    public function instructions()
    {
        return "Define your agent's instructions here.";
    }

    public function prompt($message)
    {
        return $message;
    }
}

And you can tweak the configs, like history

// ...
protected $history = \LarAgent\History\CacheChatHistory::class;
// ...

Or add temperature:

// ...
protected $temperature = 0.5;
// ...

Oh, and add a new tool:

// ...
#[Tool('Get the current weather in a given location')]
public function exampleWeatherTool($location, $unit = 'celsius')
{
    return 'The weather in '.$location.' is '.'20'.' degrees '.$unit;
}
// ...

And run it, per user:

Use App\AiAgents\YourAgentName;
// ...
YourAgentName::forUser(auth()->user())->respond($message);

Or use your custom name for the chat history:

Use App\AiAgents\YourAgentName;
// ...
YourAgentName::for("custom_history_name")->respond($message);

Let’s check the quickstart page 👍