Pass a Laravel Authenticatable object directly to create user-specific sessions:
$response = WeatherAgent::forUser(auth()->user())->respond('What is the weather like?');// Or with any Authenticatable model$response = WeatherAgent::forUser($customer)->respond('Check my order status');
This automatically uses the user’s identifier to create a unique session, making it easy to maintain per-user conversation history.
Learn more about session management and history storage options in Context & History.
Pass image URLs or base64-encoded images for vision-capable models:
// URL-based images$response = VisionAgent::for('analysis') ->withImages([ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg', ]) ->respond('What do you see in these images?');// Base64-encoded images$base64Image = base64_encode(file_get_contents('photo.jpg'));$response = VisionAgent::for('analysis') ->withImages(['data:image/jpeg;base64,' . $base64Image]) ->respond('Describe this image');
For predictable, type-safe responses, you can define a response schema. The agent will return data matching your defined structure instead of free-form text.
class ProductExtractor extends Agent{ protected $responseSchema = ProductInfo::class;}$product = ProductExtractor::ask('Extract: iPhone 15 Pro costs $999');// Returns a ProductInfo instanceecho $product->name; // 'iPhone 15 Pro'echo $product->price; // 999
Structured Output
Learn how to define schemas and work with DataModels for type-safe responses.