Workflows: Chaining Agents
A Workflow is a multi-step sequence that combines multiple agents, tools, and logic to solve complex problems.What is a Workflow?
Instead of single agent handling everything, workflows let different agents specialize: Single agent (limited): Customer → Support Bot → Answer or Escalate Workflow (powerful):- Customer Input
- Agent 1: Classifier — Is this a FAQ question? (Yes / No)
- Workflow splits:
- Yes → FAQ Bot
- No → Support Ticket Agent
- Response
Workflow Components
Common Workflow Patterns
Sequential Workflow
Sequential Workflow
Steps run one after another:Step 1 → Step 2 → Step 3Example: Extract info → Validate → Save to database
Branching Workflow
Branching Workflow
Route based on conditions:Check type?
- If Sales → Route to Sales Agent
- If Support → Route to Support Agent
- If Admin → Route to Admin Agent
Parallel Workflow
Parallel Workflow
Run multiple steps simultaneously:Input runs in parallel across:
- Agent A (processes data)
- Agent B (checks quality)
- Agent C (generates report)
Error Handling Workflow
Error Handling Workflow
Handle failures gracefully:Try Step 1:
- Success → Continue to Step 2
- Failure →
- Run Fallback Agent
- Log error
- Alert team
Creating a Workflow
1
Define Steps
List what agents/tools will do and in what order
2
Choose Agents
Select which agents participate in the workflow
3
Define Variables
Specify what data flows between steps (input, output)
4
Set Logic
Define routing, conditions, and error handling
5
Test
Run the workflow with test data
6
Deploy
Make it available for Jobs and Triggers
Jobs: Scheduled Execution
A Job runs a workflow or agent on a schedule.Why Use Jobs?
- Recurring Tasks - Run daily, weekly, monthly
- Batch Processing - Process 1000s of records automatically
- Maintenance - Clean up data, generate reports
- Monitoring - Check status at regular intervals
Job Scheduling
Workflow: “Daily Sales Report”- Run: Every day at 2:00 AM
- Process yesterday’s sales data
- Generate report
- Email to team
- Log results
- Next run: Tomorrow 2:00 AM
- Next run: Day after 2:00 AM (continues indefinitely or until disabled)
Job Configuration
Schedule Patterns
- Recurring
- Specific Times
- Complex
- Every day
- Every Monday
- Every 2 hours
- Every 15 minutes
Job Status & Monitoring
Job: “Daily Report”- Last Run:
- Status: Success ✅
- Started: 2:00 AM
- Duration: 3 min 42 sec
- Records processed: 1,245
- Next Run:
- Scheduled: Tomorrow 2:00 AM
- History:
- Yesterday: Success (3m 15s)
- 2 days ago: Success (3m 51s)
- 3 days ago: Failed (timeout)
Triggers: Event-Based Automation
A Trigger automatically runs a workflow or agent when something happens.Types of Triggers
Webhook
Triggered by HTTP POST to an endpoint. External systems can trigger your workflows.
Schedule
Same as Jobs - run on a schedule
Manual
User manually clicks a button to run
Event
Triggered by events in PLai (agent completion, data arrival, etc.)
Webhook Trigger Example
- External System sends an HTTP POST (new customer) to PLai Framework
- PLai Framework receives it via the Webhook Trigger
- Run Workflow: “Onboard Customer”
- Agent: Send welcome email
- Agent: Create account
- Agent: Log to CRM
- Response sent back to External System: “Workflow started”
Trigger Configuration
Webhook Security
- ✅ Unique URLs (hard to guess)
- ✅ Rate limiting (prevent abuse)
- ✅ Signature verification (validate requests)
- ✅ Audit logging (track all calls)
Real-World Examples
Example 1: Lead Scoring Pipeline
Trigger: New form submission (webhook) Workflow: Lead Scoring:- Agent 1: Extract info (name, company, industry)
- Agent 2: Score lead (1-10 based on data)
- Agent 3: Route to sales rep
- Tool: Send email to sales rep
- Tool: Log to CRM
Example 2: Nightly Data Processing
Job: Daily data ETL — Schedule: Every day at 2:00 AM Workflow:- Agent 1: Extract data from API
- Agent 2: Transform/clean data
- Agent 3: Validate quality
- Tool: Load to data warehouse
- Tool: Generate report and email
Example 3: Multi-Step Support Process
Trigger: Customer submits support ticket (email or form) Workflow: Support Process:- Agent 1: Classify issue
- If FAQ → Route to FAQ Bot
- If urgent → Route to support team
- If FAQ issue:
- Agent 2: Answer from FAQ
- If urgent:
- Agent 3: Create ticket
- Tool: Send to support queue
- Tool: Notify team
Best Practices
Keep Workflows Simple
Start with 2-3 steps. Add complexity as needed. Complex workflows are harder to debug.
Test Before Scheduling
Test workflows manually before setting up automatic jobs or triggers
Monitor Execution
Check job/trigger logs regularly. Set up alerts for failures.
Document Variables
Clearly document what data flows between steps to prevent errors
Workflow Naming
✅ Good names:- “Lead Scoring Pipeline”
- “Daily Sales Report”
- “Customer Onboarding”
- “Data Quality Check”
- “Workflow 1”
- “Process”
- “Automation”
- “Run”
Monitoring & Debugging
Viewing Execution History
Workflow: “Lead Scoring”Debugging Common Issues
Workflow runs slowly
Workflow runs slowly
Check:
- Are agents doing unnecessary work?
- Can steps run in parallel instead of sequentially?
- Are tools timing out?
- Is datasource search slow?
Workflow fails intermittently
Workflow fails intermittently
Check:
- External APIs timing out?
- Rate limits being hit?
- Data format inconsistencies?
- Credentials expiring?
Job not running on schedule
Job not running on schedule
Check:
- Is job enabled?
- Is timezone set correctly?
- Is workflow available?
- Any recent errors?
Webhook not triggering
Webhook not triggering
Check:
- Is endpoint accessible?
- Payload format correct?
- Rate limit exceeded?
- Check webhook logs for requests
Key Takeaways
✅ Workflows - Chain agents together for complex tasks✅ Jobs - Schedule workflows to run automatically on a schedule
✅ Triggers - Run workflows in response to events (webhooks, schedules, etc.)
✅ Automation at Scale - Handle routine work without manual intervention
Next Steps
- Create Your First Agent - Start with basic agents
- Security & Compliance - Secure your workflows
- Monitoring - Track workflow performance and costs