{
  "name": "Conditional Workflow Router",
  "version": "1.0.0",
  "description": "Demonstrates conditional branching, routing, and dynamic workflow paths based on input",
  "input_schema": {
    "type": "object",
    "properties": {
      "request_type": {
        "type": "string",
        "enum": ["order", "refund", "inquiry", "complaint"],
        "description": "Type of customer request"
      },
      "priority": {
        "type": "string",
        "enum": ["low", "medium", "high", "urgent"],
        "default": "medium"
      },
      "customer_data": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string" },
          "account_type": { "type": "string" },
          "lifetime_value": { "type": "number" }
        },
        "default": {
          "name": "John Doe",
          "email": "john@example.com",
          "account_type": "standard",
          "lifetime_value": 500
        }
      },
      "message": {
        "type": "string",
        "description": "Customer message",
        "default": "I need help with my recent order."
      }
    },
    "required": ["request_type"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "workflow_path": { "type": "string" },
      "assigned_team": { "type": "string" },
      "response": { "type": "object" },
      "escalated": { "type": "boolean" }
    }
  },
  "stages": [
    {
      "id": "log-request",
      "name": "Log Incoming Request",
      "component_type": "logger",
      "config": {
        "message": "New customer request received",
        "level": "info",
        "data": {
          "type": "{{input.request_type}}",
          "priority": "{{input.priority}}",
          "customer": "{{input.customer_data.name}}"
        },
        "tags": {
          "workflow": "conditional_demo"
        }
      },
      "depends_on": [],
      "position": { "x": 100, "y": 300 }
    },
    {
      "id": "check-vip",
      "name": "Check VIP Status",
      "component_type": "conditional",
      "config": {
        "condition": "{{input.customer_data.lifetime_value}}",
        "condition_expression": "value >= 1000",
        "true_branch_stages": ["vip-treatment"],
        "false_branch_stages": ["standard-treatment"],
        "pass_data": {
          "customer": "{{input.customer_data}}",
          "is_vip": true
        }
      },
      "depends_on": ["log-request"],
      "position": { "x": 300, "y": 300 }
    },
    {
      "id": "vip-treatment",
      "name": "VIP Customer Path",
      "component_type": "json_transform",
      "config": {
        "data": {
          "customer": "{{input.customer_data}}",
          "priority": "{{input.priority}}"
        },
        "jmespath_expression": "{ treatment: 'vip', priority_boost: 'high', dedicated_support: `true`, sla_hours: `4` }"
      },
      "depends_on": [],
      "position": { "x": 500, "y": 150 }
    },
    {
      "id": "standard-treatment",
      "name": "Standard Customer Path",
      "component_type": "json_transform",
      "config": {
        "data": {
          "customer": "{{input.customer_data}}",
          "priority": "{{input.priority}}"
        },
        "jmespath_expression": "{ treatment: 'standard', priority_boost: priority, dedicated_support: `false`, sla_hours: `24` }"
      },
      "depends_on": [],
      "position": { "x": 500, "y": 450 }
    },
    {
      "id": "route-by-type",
      "name": "Route by Request Type",
      "component_type": "router",
      "config": {
        "value": "{{input.request_type}}",
        "routes": {
          "order": ["process-order"],
          "refund": ["process-refund"],
          "inquiry": ["process-inquiry"],
          "complaint": ["process-complaint", "escalate-check"]
        },
        "default_route": ["process-inquiry"],
        "case_insensitive": true,
        "pass_data": {
          "message": "{{input.message}}"
        }
      },
      "depends_on": ["check-vip"],
      "position": { "x": 700, "y": 300 }
    },
    {
      "id": "process-order",
      "name": "Process Order Request",
      "component_type": "json_transform",
      "config": {
        "data": {
          "type": "order",
          "message": "{{input.message}}"
        },
        "jmespath_expression": "{ team: 'orders_team', action: 'process_order', template: 'order_response', queue: 'orders' }"
      },
      "depends_on": [],
      "position": { "x": 900, "y": 100 }
    },
    {
      "id": "process-refund",
      "name": "Process Refund Request",
      "component_type": "json_transform",
      "config": {
        "data": {
          "type": "refund",
          "message": "{{input.message}}"
        },
        "jmespath_expression": "{ team: 'finance_team', action: 'process_refund', template: 'refund_response', queue: 'refunds', requires_approval: `true` }"
      },
      "depends_on": [],
      "position": { "x": 900, "y": 225 }
    },
    {
      "id": "process-inquiry",
      "name": "Process General Inquiry",
      "component_type": "json_transform",
      "config": {
        "data": {
          "type": "inquiry",
          "message": "{{input.message}}"
        },
        "jmespath_expression": "{ team: 'support_team', action: 'answer_inquiry', template: 'inquiry_response', queue: 'general' }"
      },
      "depends_on": [],
      "position": { "x": 900, "y": 350 }
    },
    {
      "id": "process-complaint",
      "name": "Process Complaint",
      "component_type": "json_transform",
      "config": {
        "data": {
          "type": "complaint",
          "message": "{{input.message}}",
          "priority": "{{input.priority}}"
        },
        "jmespath_expression": "{ team: 'escalation_team', action: 'handle_complaint', template: 'complaint_response', queue: 'escalations', high_priority: `true` }"
      },
      "depends_on": [],
      "position": { "x": 900, "y": 475 }
    },
    {
      "id": "escalate-check",
      "name": "Check Escalation Need",
      "component_type": "conditional",
      "config": {
        "condition": "{{input.priority}}",
        "condition_expression": "value == 'urgent' or value == 'high'",
        "true_branch_stages": ["notify-manager"],
        "false_branch_stages": []
      },
      "depends_on": [],
      "position": { "x": 900, "y": 600 }
    },
    {
      "id": "notify-manager",
      "name": "Notify Manager",
      "component_type": "logger",
      "config": {
        "message": "ESCALATION: High priority complaint received",
        "level": "warning",
        "data": {
          "customer": "{{input.customer_data.name}}",
          "priority": "{{input.priority}}",
          "message": "{{input.message}}"
        },
        "tags": {
          "escalation": "true",
          "type": "complaint"
        }
      },
      "depends_on": [],
      "position": { "x": 1100, "y": 600 }
    },
    {
      "id": "merge-results",
      "name": "Merge All Results",
      "component_type": "json_transform",
      "config": {
        "data": {
          "request_type": "{{input.request_type}}",
          "priority": "{{input.priority}}",
          "customer": "{{input.customer_data}}",
          "vip_check": "{{upstream.check-vip}}",
          "routing": "{{upstream.route-by-type}}"
        },
        "jmespath_expression": "{ request_type: request_type, priority: priority, customer_name: customer.name, workflow_path: routing.route_taken, is_vip: customer.lifetime_value >= `1000`, stages_executed: routing.stages_to_execute }"
      },
      "depends_on": ["route-by-type"],
      "position": { "x": 1100, "y": 300 }
    },
    {
      "id": "generate-response",
      "name": "Generate Response",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a customer service AI. Generate brief, helpful responses. Be professional and empathetic.",
        "prompt": "Generate a brief acknowledgment for this customer request:\n\nCustomer: {{input.customer_data.name}}\nRequest Type: {{input.request_type}}\nMessage: {{input.message}}\n\nProvide a 2-3 sentence acknowledgment that their request has been received and will be handled.",
        "max_tokens": 150,
        "temperature": 0.7
      },
      "depends_on": ["merge-results"],
      "position": { "x": 1300, "y": 300 }
    },
    {
      "id": "format-output",
      "name": "Format Final Output",
      "component_type": "json_transform",
      "config": {
        "data": {
          "workflow": "{{upstream.merge-results.result}}",
          "response": "{{upstream.generate-response.content}}",
          "routing": "{{upstream.route-by-type}}"
        },
        "jmespath_expression": "{ workflow_path: workflow.workflow_path, assigned_team: routing.route_taken, customer: workflow.customer_name, is_vip: workflow.is_vip, priority: workflow.priority, auto_response: response, escalated: workflow.priority == 'urgent' || workflow.priority == 'high' }"
      },
      "depends_on": ["generate-response"],
      "position": { "x": 1500, "y": 300 }
    }
  ],
  "output_stage_id": "format-output"
}
