Vizra.ai |

Documentation

⚑

Agent Execution Modes

Turn your agents into automation powerhouses! πŸš€ Six incredible ways to execute AI agents beyond simple chat - from event-driven workflows to continuous monitoring. Your agents are about to get superpowers!

🎯 Beyond Simple Chat

While chatbots are cool, Vizra agents are absolute game-changers! πŸ’ͺ Imagine agents that wake up when orders arrive, analyze data while you sleep, and monitor your systems 24/7. Welcome to the future of intelligent automation!

🌟 Why Multiple Execution Modes Rock

Real businesses need more than chatbots - they need intelligent automation! Here's what your agents can do when you unleash their full potential:

🎯

React to Events

Orders, payments, user actions - your agents spring into action instantly!

πŸ“Š

Process Data

Daily reports, weekly analysis - all automated with AI intelligence

πŸ‘οΈ

Monitor 24/7

Security, performance, health - your AI never sleeps!

πŸ”„

Trigger Workflows

Notifications, escalations, automations - all handled intelligently

🎨 The Six Superpowers

Each execution mode gives your agents a different superpower! πŸ¦Έβ€β™‚οΈ Let's explore what makes each one special:

ask() πŸ’¬ Conversational Mode

The classic! Perfect for traditional chat interactions where your agent responds to user queries with intelligence and context. It's like having a super-smart assistant that never gets tired! 🧠

// Traditional chat interaction
$response = CustomerSupportAgent::ask('Where is my order?')
    ->forUser($user)
    ->execute();

trigger() ⚑ Event-Driven Mode

Your agents become event ninjas! πŸ₯· React instantly to Laravel events and system triggers to automate workflows and responses. When something happens, your agents spring into action!

// React to Laravel events
NotificationAgent::trigger($orderCreatedEvent)
    ->forUser($order->customer)
    ->async()
    ->execute();

analyze() πŸ” Data Analysis Mode

Turn your agents into data detectives! πŸ•΅οΈβ€β™€οΈ They analyze data for insights, patterns, and actionable intelligence. It's like having a brilliant analyst working around the clock!

// Analyze data for insights
$insights = FraudDetectionAgent::analyze($paymentData)
    ->withContext(['transaction_id' => $payment->id])
    ->execute();

process() πŸ”„ Batch Operations Mode

Your agents become data processing machines! 🏭 Handle massive datasets and batch operations efficiently with background processing. Perfect for those heavy-lifting tasks!

// Handle large datasets
DataProcessorAgent::process($largeDataset)
    ->async()
    ->onQueue('data-processing')
    ->timeout(600)
    ->execute();

monitor() πŸ‘οΈ Continuous Monitoring Mode

Your agents become vigilant sentinels! πŸ›‘οΈ Monitor system health, security, and performance metrics continuously. They never sleep, so your systems are always protected!

// Monitor system health
SystemMonitorAgent::monitor($metrics)
    ->withContext(['alert_threshold' => 0.95])
    ->onQueue('monitoring')
    ->execute();

generate() πŸ“„ Report Generation Mode

Turn your agents into report wizards! πŸ“Š Create reports, summaries, and documentation automatically. Never worry about tedious reporting tasks again!

// Create reports and summaries
ReportAgent::generate('weekly_sales')
    ->withContext(['date_range' => 'last_week'])
    ->async()
    ->execute();

πŸš€ Ready to Unleash Agent Superpowers?

You've just discovered six incredible ways to make your agents work for you! From instant event reactions to continuous monitoring, your agents are now ready to transform your business operations. The future of intelligent automation starts here! ✨

Async and Queue Processing

All execution modes support asynchronous processing for non-blocking operations:

Available Methods

  • async() - Execute in the background
  • onQueue(string $queue) - Specify the queue
  • delay(int $seconds) - Delay execution
  • timeout(int $seconds) - Set maximum execution time
  • tries(int $attempts) - Set retry attempts

Example: Complex Async Processing

// Process large dataset asynchronously
$job = DataProcessorAgent::process($largeDataset)
    ->async()
    ->onQueue('heavy-processing')
    ->timeout(1800) // 30 minutes
    ->tries(3)
    ->delay(60) // Start after 1 minute
    ->execute();

// Returns immediately with job tracking info
// {
//     "job_dispatched": true,
//     "job_id": "uuid-here",
//     "queue": "heavy-processing",
//     "agent": "data_processor",
//     "mode": "process"
// }

Event-Driven Agents

Create agents that automatically respond to Laravel events:

Event Listener Example

<?php

namespace App\Listeners;

use Vizra\VizraADK\Listeners\AgentEventListener;
use App\Events\OrderCreated;
use App\Agents\OrderProcessingAgent;

class OrderCreatedListener extends AgentEventListener
{
    protected string $agentClass = OrderProcessingAgent::class;
    protected string $mode = 'trigger';
    protected bool $async = true;
    protected string $queue = 'orders';

    protected function buildContext($event): array
    {
        return [
            'order_id' => $event->order->id,
            'customer_id' => $event->order->customer_id,
            'order_total' => $event->order->total,
        ];
    }
}

Scheduled Agent Tasks

Schedule agents to run automatically at specified intervals using Laravel's scheduler:

Modern Laravel 11.x Scheduling

In Laravel 11.x, define scheduled tasks in routes/console.php:

<?php

use Illuminate\Support\Facades\Schedule;
use App\Agents\BusinessIntelligenceAgent;
use App\Agents\SecurityMonitorAgent;
use App\Agents\CustomerHealthAgent;

// Daily business intelligence report at 8 AM
Schedule::call(function () {
    BusinessIntelligenceAgent::generate('daily_report')
        ->withContext([
            'report_type' => 'daily_operations',
            'include_metrics' => ['sales', 'orders', 'customers'],
            'recipients' => ['executives', 'operations'],
        ])
        ->async()
        ->onQueue('reports')
        ->execute();
})->dailyAt('08:00')
  ->name('daily-bi-report')
  ->withoutOverlapping();

// Every 15 minutes security monitoring
Schedule::call(function () {
    SecurityMonitorAgent::monitor('system_security')
        ->withContext([
            'scan_type' => 'threat_detection',
            'severity_threshold' => 'medium',
        ])
        ->async()
        ->onQueue('security')
        ->execute();
})->everyFifteenMinutes()
  ->name('security-monitoring');

// Hourly customer health check
Schedule::call(function () {
    CustomerHealthAgent::analyze('customer_metrics')
        ->withContext([
            'check_type' => 'satisfaction_monitoring',
            'alert_threshold' => 0.7,
            'include_churn_prediction' => true,
        ])
        ->async()
        ->onQueue('monitoring')
        ->execute();
})->hourly()
  ->between('8:00', '22:00');

// Weekly comprehensive analysis (Mondays at 9 AM)
Schedule::call(function () {
    BusinessIntelligenceAgent::analyze('weekly_performance')
        ->withContext([
            'report_type' => 'weekly_comprehensive',
            'include_trends' => true,
            'include_forecasts' => true,
            'compare_previous_period' => true,
        ])
        ->async()
        ->onQueue('analytics')
        ->execute();
})->weeklyOn(1, '09:00')
  ->name('weekly-analysis');

Alternatively, use withSchedule in bootstrap/app.php:

return Application::configure(basePath: dirname(__DIR__))
    ->withSchedule(function (Schedule $schedule) {
        $schedule->call(function () {
            ReportAgent::generate('daily_summary')
                ->async()
                ->execute();
        })->daily();
    })
    ->create();

Choosing the Right Mode

Mode Selection Guide

Mode Use When Example Use Cases
ask() Interactive conversations Customer support, Q&A, chatbots
trigger() Responding to events Order processing, notifications, webhooks
analyze() Data insights needed Fraud detection, sentiment analysis, trends
process() Batch operations Data migration, bulk updates, ETL
monitor() Continuous watching Security alerts, health checks, metrics
generate() Creating content Reports, summaries, documentation

Next Steps