Vizra.ai |

Documentation

๐Ÿ”„

Workflows

Orchestrate multiple agents together in powerful patterns

๐ŸŒŠ Agent Orchestration Made Simple

Workflows are special agents that conduct other agents like a symphony! ๐ŸŽผ They orchestrate multiple agents in sequential, parallel, conditional, or loop patterns - all without requiring LLM control for the workflow logic itself. Think of them as your agent choreographer!

๐ŸŽฏ Understanding Workflows

Workflows are the conductors of your agent orchestra! ๐ŸŽญ They're special agent types that bring order to complexity:

๐Ÿงฌ Built on Solid Foundation

Extend BaseWorkflowAgent which extends BaseAgent

๐ŸŽช No LLM Overhead

Orchestrate agents without using LLMs for flow control

๐ŸŽจ Multiple Patterns

Support sequential, parallel, conditional, and loop execution

๐Ÿ”— Smart Data Flow

Pass results between steps automatically

๐ŸŽจ Workflow Patterns

โžก๏ธ

Sequential

Steps execute one after another in perfect order

โšก

Parallel

Multiple agents work simultaneously

๐Ÿ”€

Conditional

Choose paths based on conditions

๐Ÿ”„

Loops

Repeat operations with while, times, or forEach

๐Ÿ› ๏ธ Creating Your First Workflow

๐ŸŽ‰ Let's build your first workflow! It's as easy as chaining methods together.

โœจ Using the Workflow Facade

app/Workflows/DataProcessingWorkflow.php
use Vizra\VizraADK\Facades\Workflow;
use App\Agents\DataCollectorAgent;
use App\Agents\DataProcessorAgent;
use App\Agents\ReportGeneratorAgent;

$workflow = Workflow::sequential()
    ->then(DataCollectorAgent::class)
    ->then(DataProcessorAgent::class)
    ->then(ReportGeneratorAgent::class);

๐Ÿš€ Sequential Workflow Class

use Vizra\VizraADK\Agents\SequentialWorkflow;
use App\Agents\AnalysisAgent;
use App\Agents\SummaryAgent;
use App\Agents\CleanupAgent;

$workflow = new SequentialWorkflow();
$workflow
    ->start(AnalysisAgent::class, 'Analyze the data')
    ->then(SummaryAgent::class, fn($previousResult) =>
        "Summarize this: " . $previousResult
    )
    ->finally(CleanupAgent::class); // Always runs

$result = $workflow->execute('Initial input');

๐ŸŽช Workflow Types in Action

โšก Parallel Workflows

Need to notify multiple channels at once? Run data processing in parallel? This is your power tool! ๐Ÿ’ช

// Using the facade
use App\Agents\EmailAgent;
use App\Agents\SmsAgent;
use App\Agents\SlackAgent;

$workflow = Workflow::parallel([
    EmailAgent::class,
    SmsAgent::class,
    SlackAgent::class
])->waitForAll();

๐Ÿ”€ Conditional Workflows

Make smart decisions in your workflow! Route to different agents based on conditions. ๐Ÿง 

use Vizra\VizraADK\Agents\ConditionalWorkflow;
use App\Agents\PremiumAgent;
use App\Agents\UrgentHandler;
use App\Agents\StandardAgent;

$workflow = Workflow::conditional()
    ->when(
        'score > 80',
        PremiumAgent::class,
        'Handle premium customer'
    )
    ->when(
        fn($input) => $input['type'] === 'urgent',
        UrgentHandler::class
    )
    ->otherwise(
        StandardAgent::class,
        'Handle standard request'
    );

๐Ÿ”„ Loop Workflows

Process lists, retry until success, or repeat operations - loops make it easy! ๐ŸŽฏ

use App\Agents\ProcessingAgent;
use App\Agents\BatchProcessor;
use App\Agents\ItemProcessor;

// While loop
$workflow = Workflow::while(
    ProcessingAgent::class,
    fn($result) => $result['continue'] === true,
    10 // max iterations
);

// Times loop
$workflow = Workflow::times(BatchProcessor::class, 5);

// ForEach loop
$items = ['item1', 'item2', 'item3'];
$workflow = Workflow::forEach(ItemProcessor::class, $items);

๐Ÿƒ Running Your Workflows

๐ŸŽฌ Basic Execution

use App\Agents\FirstAgent;
use App\Agents\SecondAgent;

// Workflows are agents, so they run like any agent
$workflow = Workflow::sequential(FirstAgent::class, SecondAgent::class);

// Execute with input
$result = $workflow->execute('Process this data',  $context = null);

๐Ÿ“Š Understanding Workflow Results

Each workflow type returns structured results so you always know what happened! ๐Ÿ“ˆ

// Sequential workflow returns
{
    'final_result': 'Last agent output',
    'step_results': {
        'App\\Agents\\FirstAgent': 'First result',
        'App\\Agents\\SecondAgent': 'Second result'
    },
    'workflow_type': 'sequential'
}

// Parallel workflow returns
{
    'results': {
        'App\\Agents\\AgentOne': 'Result 1',
        'App\\Agents\\AgentTwo': 'Result 2'
    },
    'completed': ['App\\Agents\\AgentOne', 'App\\Agents\\AgentTwo'],
    'workflow_type': 'parallel'
}

๐Ÿš€ Advanced Workflow Features

๐Ÿ›ก๏ธ Take your workflows to the next level with advanced error handling, callbacks, and dynamic parameters!

๐Ÿ›ก๏ธ Error Handling and Retries

use App\Agents\RiskyAgent;

$workflow = new SequentialWorkflow();
$workflow
    ->retryOnFailure(3, 1000) // 3 retries, 1 second delay
    ->timeout(300) // 5 minute timeout
    ->then(RiskyAgent::class, 'Process risky operation', [
        'retries' => 5, // Override for this step
        'timeout' => 60
    ]);

๐Ÿ“ž Callbacks for Workflow Events

use App\Agents\FirstAgent;
use App\Agents\SecondAgent;

$workflow = Workflow::sequential(FirstAgent::class, SecondAgent::class)
    ->onSuccess(function($result, $stepResults) {
        Log::info('Workflow succeeded', [
            'final' => $result,
            'steps' => $stepResults
        ]);
    })
    ->onFailure(function(\Throwable $e, $stepResults) {
        Log::error('Workflow failed: ' . $e->getMessage());
    })
    ->onComplete(function($result, $success, $stepResults) {
        // Always runs, regardless of success/failure
    });

๐ŸŽฏ Dynamic Parameters

Pass data between steps dynamically based on results and context! ๐Ÿ”—

use App\Agents\DataFetcher;
use App\Agents\Processor;

$workflow = new SequentialWorkflow();
$workflow
    ->then(DataFetcher::class)
    ->then(
        Processor::class,
        // Dynamic params based on previous results
        fn($input, $results, $context) => [
            'data' => $results[DataFetcher::class],
            'mode' => $context->getState('processing_mode')
        ]
    );

๐ŸŽ›๏ธ Workflow State Management

Access results from any step and manage state throughout your workflow! ๐Ÿ“Š

use App\Agents\Collector;
use App\Agents\Analyzer;

// Access results from previous steps
$workflow = new SequentialWorkflow();
$workflow
    ->then(Collector::class, 'Collect data')
    ->then(Analyzer::class, function($input, $results) {
        // Access previous step result
        $collectedData = $results[Collector::class];
        return "Analyze: " . json_encode($collectedData);
    });

// After execution, get specific results
$result = $workflow->execute('Start');
$analyzerResult = $workflow->getStepResult(Analyzer::class);
$allResults = $workflow->getResults();

๐Ÿ“‹ Creating Workflows from Arrays

Define workflows using simple arrays - perfect for dynamic or configuration-based workflows! ๐ŸŽจ

๐Ÿ“ Array Definition

use App\Agents\DataCollector;
use App\Agents\Validator;

$definition = [
    'type' => 'sequential',
    'steps' => [
        [
            'agent' => DataCollector::class,
            'params' => 'Collect user data'
        ],
        [
            'agent' => Validator::class,
            'options' => ['retries' => 3]
        ]
    ]
];

$workflow = Workflow::fromArray($definition);

๐ŸŽจ Complex Array Definitions

use App\Agents\UrgentHandler;
use App\Agents\SupportAgent;
use App\Agents\StandardHandler;

// Conditional workflow from array
$definition = [
    'type' => 'conditional',
    'conditions' => [
        [
            'condition' => 'input.priority == "high"',
            'agent' => UrgentHandler::class
        ],
        [
            'condition' => 'input.type == "support"',
            'agent' => SupportAgent::class
        ]
    ],
    'default' => [
        'agent' => StandardHandler::class
    ]
];

๐Ÿ’ก Workflow Best Practices

๐ŸŽฏ

Remember the Foundation

Workflows are agents - they extend BaseWorkflowAgent

๐ŸŽจ

Choose the Right Pattern

Use the appropriate workflow type for your use case

โฑ๏ธ

Set Smart Limits

Configure reasonable timeouts and retry limits

๐Ÿ“Š

Monitor Everything

Leverage callbacks for monitoring and debugging

๐Ÿ”—

Smart Data Flow

Pass results between steps using closures

๐Ÿงช

Test Thoroughly

Test workflows with various input scenarios