{
  "name": "Email Polling + Dedup",
  "goal": "Poll Gmail for new emails, process each, and mark them with a label so they're never reprocessed.",
  "description": "Pattern 02 (dedup-gates). Default intake pattern — prefer this over event triggers unless you need sub-minute latency.",
  "status": "draft",
  "steps": [
    {
      "id": "schedule",
      "type": "trigger",
      "name": "Daily poll",
      "pipelineStepStartConditions": {
        "trigger": {
          "type": "schedule",
          "config": { "frequency": "daily", "time": "07:00" }
        }
      },
      "next": { "stepId": "ensure-label" }
    },
    {
      "id": "ensure-label",
      "type": "appAction",
      "name": "Ensure Processed Label",
      "app": { "id": "gmail", "actionId": "GMAIL_CREATE_LABEL", "source": "composio" },
      "stepInputData": { "name": "processed" },
      "next": { "stepId": "fetch-emails" }
    },
    {
      "id": "fetch-emails",
      "type": "appAction",
      "name": "Fetch New Emails",
      "app": { "id": "gmail", "actionId": "GMAIL_FETCH_EMAILS", "source": "composio" },
      "stepInputData": {
        "query": "-label:processed newer_than:1d",
        "max_results": "50"
      },
      "next": { "stepId": "process" }
    },
    {
      "id": "process",
      "type": "aiAction",
      "name": "Process Email",
      "loopConfig": {
        "source": "executionContent",
        "config": { "stepId": "fetch-emails", "field": "messages" },
        "ItemAlias": "emailItem"
      },
      "pipelineStepPrompt": {
        "template": "Process this email:\n\nFrom: {{emailItem.from}}\nSubject: {{emailItem.subject}}\n\n{{emailItem.body}}",
        "responseStructure": { "summary": "string", "action": "string" }
      },
      "creditCost": 8,
      "next": { "stepId": "mark-processed" }
    },
    {
      "id": "mark-processed",
      "type": "appAction",
      "name": "Mark as Processed",
      "app": { "id": "gmail", "actionId": "GMAIL_ADD_LABEL", "source": "composio" },
      "stepInputData": {
        "message_id": "{{emailItem.id}}",
        "label_id": "{{steps.ensure-label.id}}"
      },
      "next": { "stepId": "done" }
    },
    {
      "id": "done",
      "type": "milestone",
      "name": "Done"
    }
  ]
}
