Pattern B: Agent as Workflow Trigger
The agent operates as a smart ingestion layer. It receives unstructured input, reasons about it, and triggers the appropriate workflow with structured parameters. You don't know upfront which workflow to run ā the agent decides.
flowchart LR
Input["Unstructured Input<br/>(email, document, webhook)"] --> Agent["ReAct Agent"]
Agent -->|"invoice detected"| W1["Invoice Processing<br/>Workflow"]
Agent -->|"support request"| W2["Support Ticket<br/>Workflow"]
Agent -->|"vendor inquiry"| W3["Vendor Onboarding<br/>Workflow"]
style Agent fill:#f3e8ff,stroke:#9333ea
When to Use
- Input arrives in unstructured form (emails, documents, free-text)
- You don't know upfront which workflow to run
- Classification and extraction are required before processing
- The agent acts as an intelligent router ā analyzing input and dispatching
Complete Example: Document Classifier and Router
A standalone agent that receives a document, classifies it, extracts relevant fields, and triggers the correct processing workflow.
json
{
"objective": "Classify this incoming document and route it to the correct processing workflow.\n\nDocument content:\n{{input.document_text}}\n\nSender: {{input.sender_email}}\nReceived: {{input.received_at}}",
"tools": [
{ "type": "action", "name": "document_classifier" },
{ "type": "action", "name": "field_extractor" },
{ "type": "workflow", "name": "invoice_processing" },
{ "type": "workflow", "name": "purchase_order_processing" },
{ "type": "workflow", "name": "support_ticket_handler" },
{ "type": "workflow", "name": "contract_review" }
],
"config": {
"model": "gpt-4",
"max_iterations": 8,
"on_stuck": { "iterations": 3, "action": "escalate" }
}
}
Execute via the standalone agent API:
bash
curl -X POST http://localhost:3009/agents/execute \
-H "X-Org-Id: acme-corp" \
-H "Content-Type: application/json" \
-d '{
"objective": "Classify this incoming document and route it...",
"tools": [ ... ],
"config": { "model": "gpt-4", "max_iterations": 8 }
}'
Sample Reasoning Trace
text
Iteration 1:
Thought: "I need to classify this document first."
Action: classify_document
Input: { "text": "Invoice #INV-2024-0891..." }
Observation: { "category": "invoice", "confidence": 0.97 }
Iteration 2:
Thought: "It's an invoice with high confidence. Let me extract the key fields."
Action: extract_fields
Input: { "text": "Invoice #INV-2024-0891...", "document_type": "invoice" }
Observation: {
"invoice_number": "INV-2024-0891",
"vendor": "Acme Supplies",
"amount": 4250.00,
"due_date": "2026-03-15"
}
Iteration 3:
Thought: "I have the classification and extracted fields. Let me log progress and trigger the invoice workflow."
Action: __log_progress__
Input: { "message": "Document classified as invoice", "milestone": "classified" }
Iteration 4:
Thought: "Now I'll trigger the invoice processing workflow with the extracted fields."
Action: __run_workflow__
Input: {
"workflow_name": "invoice_processing",
"input": {
"invoice_number": "INV-2024-0891",
"vendor": "Acme Supplies",
"amount": 4250.00,
"due_date": "2026-03-15",
"sender_email": "[email protected]",
"source": "email_ingestion"
},
"wait": false
}
Observation: { "workflow_run_id": "run_def456", "status": "running" }
Iteration 5:
Thought: "Invoice workflow triggered. I'm done."
Action: __complete__
Input: {
"answer": "Document classified as invoice (97% confidence). Triggered invoice_processing workflow (run_def456) with extracted fields.",
"confidence": 0.97
}
Key Properties
- Workflow tools are essential ā declaring
{ "type": "workflow", "name": "..." }gives the agent the ability to dispatch to specialized workflows wait: falseon the workflow trigger ā the agent doesn't need to wait for invoice processing to complete. It classifies and routes- Standalone execution ā this agent runs via
POST /agents/execute, not inside a workflow. It is the entry point - Implicit tools ā
__log_progress__,__complete__, and__pause_for_human__are auto-injected; no need to declare them
Scaling the Pattern
For high-volume ingestion, combine with a foreach loop in a wrapper workflow:
json
{
"name": "batch_document_processor",
"definition": {
"actions": [
{
"type": "loop",
"properties": {
"mode": "foreach",
"items_path": "@input.documents",
"item_variable_name": "doc",
"actions_to_execute": [
{
"type": "loop",
"properties": {
"mode": "react",
"objective": "Classify and route: {{doc.text}}",
"tools": [
{ "type": "action", "name": "classify_document" },
{ "type": "action", "name": "extract_fields" },
{ "type": "workflow", "name": "invoice_processing" },
{ "type": "workflow", "name": "support_ticket_handler" }
],
"max_iterations": 6
}
}
],
"max_concurrency": 5,
"failure_strategy": "continue_on_error"
}
}
]
}
}
ā Next: Pattern C: Agent as Orchestrator