How do you prompt a basic agent using the AI SDK in Laravel 13?

In Laravel 13, the simplest way to prompt a basic agent is to use the agent() helper function with the fluent prompt() method. You don not need to create a dedicated class for one-off tasks.

Quick Start

First, install the SDK via Composer:

composer require laravel/ai

Then, you can prompt an agent directly in your controller or route:

use function LaravelAi{agent};

$response = agent(
   instructions: You are an expert at software development.
)->prompt( Tell me about Laravel );

return (string) $response;

Using a Dedicated Agent Class (Recommended for Reuse)

If you plan to use the same configuration multiple times, it is better to create a class. You can scaffold one using Artisan:

php artisan make:agent SalesCoach

A basic agent class looks like this :

namespace AppAiAgents;

use LaravelAiContractsAgent;
use LaravelAiPromptable;

class SalesCoach implements Agent
{
   use Promptable;

   public function instructions(): string
   {
       return You are a sales coach, analyzing transcripts and providing feedback. ;
   }
}

You can then prompt it like this :

use AppAiAgentsSalesCoach;

$response = (new SalesCoach)->prompt( Analyze this sales transcript... );

return (string) $response;

5 Views