Workflow definition

Trigger · mail

trigger: { type: "mail" }

A message arriving at one of the account's own mailboxes starts a run, with the message as the input.

an arriving messagethe body is untrustedneeds a mailbox
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

trigger: { type: "mail" }

{ id: "triage", type: "model.generate", config: {
    model: "gemini-3.5-flash",
    prompt: "Classify this message. Subject: {{input.subject}}\n\n{{input.text}}" } }
trigger = {"type": "mail"}

{"id": "triage", "type": "model.generate", "config": {
    "model": "gemini-3.5-flash",
    "prompt": "Classify this message. Subject: {{input.subject}}\n\n{{input.text}}"}}

It needs a mailbox

The account must own one — see api.mail. Without it there is nothing for a message to arrive at.

A message is the most untrusted input there is

Anyone can send one

Its content reaches a model's prompt. Say what the step should do with it, and never let the body decide the task — a message asking to be forwarded somewhere is a message, not an instruction.

The agent's own mail tool carries the same rule in its description, for the same reason.

Answering needs an approval

A chain that replies ends in mail.send, which requires a human step upstream. An automatic answer to an arriving message is exactly the thing that must not happen unsupervised.

The usual shape

  • Classify the message with a model.
  • Branch on the classification with a condition or a switch.
  • File it with storage.write — no approval needed, it stays inside the account.
  • For anything that answers: a human step, then mail.send.