ImageAgent is a specialized media agent that generates images from text descriptions. It integrates with providers like OpenAI (DALL-E) and Google (Imagen) through Prism PHP, offering a fluent API for configuration, built-in storage, and queue support.
Multi-Provider
Works with OpenAI DALL-E, Google Imagen, and other image generation models
Fluent API
Chain methods like size(), quality(), and style() for clean configuration
Built-in Storage
Store generated images directly to Laravel’s filesystem with store() and storeAs()
Queue Support
Process image generation asynchronously with Laravel queues
use Vizra\VizraADK\Agents\ImageAgent;// Generate and store an image$image = ImageAgent::run('A sunset over the ocean') ->quality('hd') ->go();$image->storeAs('sunset.png');echo $image->url(); // URL to the stored image
The run() method returns a fluent executor - chain your configuration and call go() to execute!
// Store with auto-generated filename (ULID)$image = ImageAgent::run('An oil painting of flowers')->go();$image->store(); // Stores as e.g., 01HWXYZ123.png$image->store('s3'); // Store to a specific disk// Store with custom filename$image->storeAs('flowers.png');$image->storeAs('art/flowers.png', 's3');// Check storage statusif ($image->isStored()) { echo $image->path(); // vizra-adk/generated/images/flowers.png echo $image->disk(); // public}
Images are stored in the vizra-adk/generated/images/ directory by default. Configure this in your vizra-adk.php config file.
// Store with auto-generated name$image = ImageAgent::run('A futuristic city') ->store() ->go();// Store with specific filename$image = ImageAgent::run('A vintage car') ->storeAs('vintage-car.png') ->go();
// Use a specific provider and modelImageAgent::run('A serene lake') ->using('openai', 'dall-e-3') ->go();// Switch to Google ImagenImageAgent::run('A colorful abstract pattern') ->using('google', 'imagen-3') ->go();
ImageAgent::run('A detailed illustration') ->onQueue('media') // Specific queue name ->delay(60) // Delay execution by 60 seconds ->tries(5) // Retry up to 5 times on failure ->timeout(120) // 2-minute timeout ->then(fn($image) => $image->storeAs('illustration.png')) ->go();
The then() callback runs after generation completes - use it to store images or trigger notifications. The callback must be serializable for queue processing.
// In your EventServiceProvider or ListenerEvent::listen('media.image_agent.completed', function ($event) { $jobId = $event['job_id']; $response = $event['response']; $sessionId = $event['session_id']; // Process the completed image Log::info("Image generated: " . $response->url());});// Generic event for all media typesEvent::listen('media.job.completed', function ($event) { // Handle any media job completion});
use Vizra\VizraADK\Agents\BaseLlmAgent;use Vizra\VizraADK\Agents\ImageAgent;use Vizra\VizraADK\Tools\DelegateToMediaAgentTool;class CreativeAssistantAgent extends BaseLlmAgent{ protected string $name = 'creative_assistant'; protected string $description = 'A creative assistant that can generate images'; protected string $instructions = <<<INSTRUCTIONS You are a creative assistant. When users ask for images, use the generate_image tool to create them. Provide detailed, descriptive prompts for best results. INSTRUCTIONS; protected array $tools = [ DelegateToMediaAgentTool::class, ]; protected array $mediaAgents = [ ImageAgent::class, ];}
ImageAgent::run('A personalized avatar') ->forUser($user) // Associate with a user model ->withSession('session-123') // Custom session ID ->withContext([ // Additional context data 'source' => 'profile_editor', 'request_id' => $requestId, ]) ->go();