Examples
These examples illustrate common workflow patterns. Each one describes the states, transitions, guards, and tools involved.
Sales Agent
A three-state workflow that qualifies a lead, searches for matching products, and handles checkout.
States:
- Gather Preferences (Conversation) – Ask the customer about their needs, budget, and timeline. Required fields:
product_type,budget,timeline. - Search Options (Action) – Use
search_productsto find matching items based on gathered data. Present results to the user. - Checkout (Conversation) – Walk the user through purchase confirmation. Use
create_orderwhen they are ready.
Transitions:
- Gather Preferences -> Search Options: Guard
all_required_answered(all three fields recorded) - Search Options -> Checkout: Guard
tool_called(thesearch_productstool has been called) - Checkout is a terminal state
Tools: record_data (global), search_products (Search Options), create_order (Checkout)
Document Processing
A three-state workflow for extracting data from uploaded documents, sending it to an external system, and confirming delivery.
States:
- Extract Data (Conversation) – Ask the user to upload a document. Use
extract_documentto parse it andrecord_datato store the extracted fields. - Send to System (Action) – Use an HTTP tool to POST the extracted data to an external API. Record the response status.
- Confirm Delivery (Conversation) – Report the result to the user and ask if they want to process another document.
Transitions:
- Extract Data -> Send to System: Guard
data_contains(keyextracted_datais present) - Send to System -> Confirm Delivery: Guard
always(advance immediately after the action completes) - Confirm Delivery is a terminal state
Tools: record_data (global), extract_document (Extract Data), a custom HTTP tool (Send to System)
Approval Flow
A four-state workflow for submitting a request, checking entitlement, routing to an approver, and updating a calendar.
States:
- Gather Request (Conversation) – Collect the request details from the user: type, dates, and reason. Required fields:
request_type,start_date,end_date,reason. - Check Entitlement (Action) – Query an external system to verify the user has sufficient entitlement. Record the result as
entitled: true/false. - Request Approval (Conversation) – If entitled, notify the user’s manager and wait for an external approval event via webhook. If not entitled, inform the user and end.
- Update Calendar (Action) – On approval, use a calendar tool to block the requested dates and notify the user.
Transitions:
- Gather Request -> Check Entitlement: Guard
all_required_answered - Check Entitlement -> Request Approval: Guard
data_contains(keyentitledequalstrue) - Check Entitlement -> terminal “Not Entitled” state: Guard
data_contains(keyentitledequalsfalse) - Request Approval -> Update Calendar: Guard
external_event(event typeapproval_granted) - Request Approval -> terminal “Denied” state: Guard
external_event(event typeapproval_denied) - Update Calendar is a terminal state
Tools: record_data (global), a custom HTTP tool for entitlement checks (Check Entitlement), send_email (Request Approval), a calendar HTTP tool (Update Calendar)
Report Collection
A workflow that uses the Task state to fan out report requests to multiple team members, then compiles and distributes the results.
States:
- Collect Reports (Task) – Fan out a “Submit your weekly status report” task to each member of the team. Participants are resolved from a dataset query against the
team_membersdataset. Each participant receives the request via their preferred channel and responds independently. - Compile Report (Action) – Once all participant tasks are complete, combine the individual reports into a single summary using
save_content. - Send to Management (Action) – Use
send_emailto deliver the compiled report to the management distribution list.
Transitions:
- Collect Reports -> Compile Report: Guard
all_tasks_complete - Compile Report -> Send to Management: Guard
always - Send to Management is a terminal state
Tools: record_data (global), save_content (Compile Report), send_email (Send to Management)
Task template configuration: The Task state in “Collect Reports” uses a task template with participant resolution set to dataset_query against the team_members dataset. Each participant receives the task instructions and can respond via any enabled channel. See Task Templates for details on configuring participant resolution.
Expense Reimbursement (Logic States + Approval Gate)
A workflow that collects an expense claim, validates it with deterministic logic, routes for approval, and processes the reimbursement. Demonstrates Logic states, conditional branching, and the approval gate feature.
States:
- Collect Details (Conversation) – Ask the user for the expense type, amount, receipt, and description. Required fields:
expense_type,amount,receipt_url,description. - Validate & Route (Logic) – A deterministic state that checks the amount and routes accordingly:
- Operation 1:
transform– convertamountto a number usingto_number - Operation 2:
conditional_branch– ifamount> 500, route to “Manager Approval”; otherwise route to “Process Reimbursement”
- Operation 1:
- Manager Approval (Conversation) – Present the expense summary to the user and wait for manager approval. This state has
require_human_approval: truewithapproval_contactsset to{gathered_data.manager_email}. - Process Reimbursement (Logic) – A deterministic state that calls the finance API:
- Operation 1:
http_request– POST to the finance system with the expense details - Operation 2:
set_data– store the transaction ID from the response - Operation 3:
send_notification– email the user a confirmation with the transaction ID
- Operation 1:
- Done (Conversation) – Confirm the reimbursement to the user.
Transitions:
- Collect Details -> Validate & Route: Guard
all_required_answered - Validate & Route -> Manager Approval: Via
conditional_branch(amount > 500) - Validate & Route -> Process Reimbursement: Via
conditional_branch(amount <= 500) - Manager Approval -> Process Reimbursement: Guard
always(fires after approval is granted) - Process Reimbursement -> Done: Guard
always - Done is a terminal state
Retry policy: The “Process Reimbursement” state has a retry policy of max_attempts: 3, backoff_seconds: 10 in case the finance API is temporarily unavailable.
Employee Onboarding (Subworkflow)
A workflow that orchestrates new employee onboarding by nesting reusable sub-processes as child workflows.
States:
- Collect Employee Info (Conversation) – Gather the new hire’s name, role, department, start date, and equipment preferences. Required fields:
employee_name,role,department,start_date. - IT Setup (Subworkflow) – Runs the “IT Provisioning” workflow as a child process. Input mapping sends
employee_name,role, anddepartmentto the child. Output mapping receiveslaptop_id,email_address, andvpn_credentialsback. - HR Paperwork (Subworkflow) – Runs the “HR Document Collection” workflow. Input mapping sends
employee_nameandstart_date. Output mapping receivesdocuments_complete: true/false. - Welcome Email (Logic) – Sends a welcome email with all provisioned details:
- Operation:
send_notification– email to{gathered_data.email_address}with a template referencing laptop ID, VPN credentials, and start date
- Operation:
- Complete (Conversation) – Notify the requesting manager that onboarding is finished and provide a summary.
Transitions:
- Collect Employee Info -> IT Setup: Guard
all_required_answered - IT Setup -> HR Paperwork: Guard
always - HR Paperwork -> Welcome Email: Guard
data_equals(keydocuments_completeequalstrue) - Welcome Email -> Complete: Guard
always - Complete is a terminal state
This pattern keeps each sub-process (IT provisioning, HR paperwork) as its own independently testable workflow that can be reused across different parent workflows.
Lead Scoring Pipeline (Logic + Reducers)
A workflow that uses Logic states and reducers to build up a composite lead score from multiple data sources before routing to the right sales team.
States:
- Qualify Lead (Conversation) – Gather company name, size, industry, budget range, and use case. Required fields:
company_name,company_size,industry,budget. - Score Lead (Logic) – Compute a lead score using deterministic operations:
- Operation 1:
set_data– initializelead_scoreto 0 - Operation 2:
conditional_branch– ifcompany_size> 500, setlead_scoreto 30 viaset_datawith reducerincrement; if > 100, increment by 20; otherwise increment by 10
- Operation 1:
- Enrich Data (Logic) – Look up the company in an external CRM:
- Operation 1:
http_request– GET company details from CRM API using{gathered_data.company_name} - Operation 2:
set_data– store the CRM response data
- Operation 1:
- Route to Team (Logic) – Route based on final score:
- Operation:
conditional_branch– iflead_score>= 50, route to “Enterprise Team”; otherwise route to “SMB Team”
- Operation:
- Enterprise Team (Conversation) – High-touch follow-up with enterprise sales playbook.
- SMB Team (Conversation) – Automated follow-up with SMB sales playbook.
State schema (reducers):
{
"lead_score": {
"type": "number",
"reducer": "increment"
},
"crm_data": {
"type": "dict",
"reducer": "merge_dict"
}
}Transitions:
- Qualify Lead -> Score Lead: Guard
all_required_answered - Score Lead -> Enrich Data: Guard
always - Enrich Data -> Route to Team: Guard
always - Route to Team -> Enterprise Team / SMB Team: Via
conditional_branch - Enterprise Team and SMB Team are terminal states
Vacation Request
A workflow that handles vacation requests end-to-end using the new state primitives: Parse, Approval, Output, and named output ports. An employee emails their vacation request in natural language. The workflow extracts the dates, checks a calendar, gets manager approval (with back-and-forth), records the vacation, and notifies the requestor.
States:
- Parse Request (Parse) – Extract
requestor_name,vacation_start(date),vacation_end(date), andreason(string, optional) from the user’s message. - Ask for Details (Conversation) – If the parse was incomplete, ask the user for missing information: “I need your name and the dates you’d like off.”
- Check Calendar (Logic) – Call a calendar API via
http_requestto check availability. Useconditional_branchto route based oncalendar_available. - Notify Conflict (Output) – Email the requestor about scheduling conflicts. Target:
conversation. Template: “Unfortunately your requested dates conflict with: {gathered_data.conflicting_events}.” - Request Approval (Approval) – Email the manager for approval. Approvers:
{gathered_data.manager_email}. Body: “{gathered_data.requestor_name} requests vacation from {gathered_data.vacation_start} to {gathered_data.vacation_end}.” Escalation: 48 hours to department head. - Negotiate (Conversation) – The manager had questions or suggested alternatives. Facilitate discussion, then loop back to Request Approval.
- Record Vacation (Logic) – Call the HR system via
http_requestto record the approved vacation. Error handling: retry 3x, then route to error port. - Confirm to Requestor (Output) – Send confirmation email. Target:
conversation. Template: “Your vacation from {gathered_data.vacation_start} to {gathered_data.vacation_end} has been approved and recorded.” - Notify Denied (Output) – Send denial notification. Target:
conversation. Template: “Your vacation request was denied. Reason: {gathered_data.rejection_reason}.”
Transitions:
- Parse Request
complete→ Check Calendar - Parse Request
incomplete→ Ask for Details - Ask for Details → Parse Request: Guard
all_required_answered(keys: requestor_name, vacation_start, vacation_end) - Check Calendar → Request Approval: Via
conditional_branch(calendar_available = true) - Check Calendar → Notify Conflict: Via
conditional_branch(calendar_available = false) - Notify Conflict
done→ terminal - Request Approval
approved→ Record Vacation - Request Approval
rejected→ Notify Denied - Request Approval
discussion→ Negotiate - Request Approval
timeout→ terminal (auto-escalation handles reminders) - Negotiate → Request Approval: Guard
user_confirmed - Record Vacation → Confirm to Requestor: Guard
always - Record Vacation
error→ terminal (admin notified via error data) - Confirm to Requestor
done→ terminal - Notify Denied
done→ terminal
Flow diagram:
[Parse Request] --complete--> [Check Calendar] --available--> [Request Approval]
^ | | | | |
| conflict appr rej disc timeout
| | | | |
| [Notify Conflict] [Record] [Denied] [Negotiate]
| | | |
+------(new dates)------------+ [Confirm] (resubmit)
^
|
[Ask for Details] <--incomplete--Key patterns demonstrated:
- Parse + Conversation loop – Parse extracts fields, incomplete loops back through Conversation to gather missing info.
- Email-native Approval with discussion – The manager replies to an email naturally. LLM classifies the reply and routes accordingly.
- Output for notifications – Template-based emails without LLM cost.
- Error boundaries – Record Vacation retries 3x on API failure, then routes to an error handler.
- Named output ports – No guard configuration needed for standard branching.