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
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