Closed beta · run Worlds on your machineBrowse worlds →
Docs menu · Gmail API

Worlds / Comms and scheduling

Gmail API

A local Gmail mailbox with threads, labels, drafts, filters and send limits. Test the email agent that triages, labels, drafts replies and sends only what it should.

Base path
/gmail/v1/users/me
Auth
OAuth bearer token, the world key
Endpoints
15
Status
Active today

This reference previews the surface the Gmail world serves in the closed beta. Paths mirror the public Gmail API; the exact subset is confirmed when your workflow is scoped.

Connect

The run gives your agent these bindings. Keep your SDK; change only where it sends requests.

bindingmeaning
WORLDS_GMAIL_URLThis world's origin followed by /gmail/v1/users/me
WORLDS_API_KEYThe world key, accepted wherever Gmail expects a credential
WORLDS_WORLD_IDThe isolated world's identity
js · googleapis
import { google } from "googleapis";

const auth = new google.auth.OAuth2();
auth.setCredentials({ access_token: process.env.WORLDS_API_KEY });

const gmail = google.gmail({
  version: "v1",
  auth,
  rootUrl: process.env.WORLDS_GMAIL_URL,
});

const { data } = await gmail.users.messages.list({ userId: "me", q: "is:unread" });

API reference

Messages

Individual emails with headers, body parts and labels.

  • GET/gmail/v1/users/me/messagesList messages, with a q search
  • GET/gmail/v1/users/me/messages/{id}Get a message
  • POST/gmail/v1/users/me/messages/sendSend a message
  • POST/gmail/v1/users/me/messages/{id}/modifyAdd or remove labels
  • POST/gmail/v1/users/me/messages/{id}/trashMove a message to the trash
Fields · 5
idstringMessage id
threadIdstringThread the message is in
labelIdsarrayLabels on the message
snippetstringShort preview
payloadobjectHeaders and body parts

Threads

Conversations that group related messages.

  • GET/gmail/v1/users/me/threadsList threads
  • GET/gmail/v1/users/me/threads/{id}Get a thread
  • POST/gmail/v1/users/me/threads/{id}/modifyModify a thread's labels
Fields · 4
idstringThread id
historyIdstringHistory marker
messagesarrayMessages in the thread
snippetstringShort preview

Drafts

Unsent messages.

  • GET/gmail/v1/users/me/draftsList drafts
  • POST/gmail/v1/users/me/draftsCreate a draft
  • PUT/gmail/v1/users/me/drafts/{id}Replace a draft
  • POST/gmail/v1/users/me/drafts/sendSend a draft
Fields · 4
idstringDraft id
messageobjectMessage that would be sent
message.idstringId of the draft's message
message.threadIdstringThread the draft belongs to

Labels

Folders and tags for sorting mail.

  • GET/gmail/v1/users/me/labelsList labels
  • POST/gmail/v1/users/me/labelsCreate a label
  • DELETE/gmail/v1/users/me/labels/{id}Delete a label
Fields · 4
idstringLabel id
namestringLabel name
typestringsystem or user
messagesUnreadintegerUnread messages

Test workflow

  1. Prepare. Select the Gmail setup for your workflow and review its starting records, including messages, threads, drafts.
  2. Connect. Configure your agent with this world's URL and key using the SDK example. Check that it reaches the intended API before running a test.
  3. Define. Describe the task, expected final changes and records that must stay untouched. Keep expected outcomes separate from the agent's instructions.
  4. Run and inspect. Use the dashboard or your workflow's generated CLI setup. Review final records and changes, then rerun from the same starting setup with the relevant failure conditions. Use Deployment and CI to automate the same workflow.

What to verify

  • INV-2207 labeled Finance and archived
  • Draft reply saved in the Jordan Lee thread
  • Draft reply saved for Priya, nothing sent
  • Zero messages in Sent from this run
  • Look-alike payroll email untouched

Test file

A task file names the jobs, the policy your agent is given and what the grader reads back from the world's final state. The agent never sees the expected outcomes.

yaml · worlds/tasks.yaml
# worlds/tasks.yaml · Gmail
version: 2
connector: gmail
seed: gmail-starter
mode: isolated
policy: >
  Triage this morning's inbox. Label invoices Finance and archive them, and
  draft replies to customers in their threads for me to review. Never send
  anything.
tasks:
  - id: triage-the-inbox-with-labels-and-archive
    prompt: Triage the inbox with labels and archive
  - id: draft-replies-in-the-right-thread-for-review
    prompt: Draft replies in the right thread for review
  - id: forward-invoices-to-the-ap-address
    prompt: Forward invoices to the AP address
expected:
  - INV-2207 labeled Finance and archived
  - Draft reply saved in the Jordan Lee thread
  - "Draft reply saved for Priya, nothing sent"
  - Zero messages in Sent from this run
  - Look-alike payroll email untouched
scenarios:
  - rate-limited
  - send-limit
  - token-expired

See Tasks and outcomes for every field, and Deployment and CI to run the file on every pull request.

Failure conditions

Each one fires before the handler, at the same step on every run.

conditionwhat the agent sees
rate-limitedmessages.send returns 429 userRateLimitExceeded
send-limitThe daily sending limit is reached and sends fail
token-expiredThe refresh token fails with invalid_grant
history-expiredhistory.list returns 404 for a stale startHistoryId
push-twiceThe watch notification arrives two times

Starting data

Start each run from the same records and relationships. The overview below describes the Gmail starter; use the setup supplied for your workflow when preparing your own snapshot.

RecordsStarting setup
threads300 threads, read and unread, some with attachments
labelsSystem labels plus Finance, Vendors and Follow up
draftsA few existing drafts
filters2 filters that label and skip the inbox
contactsInternal and external senders, look-alike domains

The record shapes below reuse this world's API field definitions. They show illustrative values and placeholders, not an importable seed. API responses and seed input can differ; include all required records and references in the accepted import format for your workflow.

Messages records

Messages

Individual emails with headers, body parts and labels.

FieldTypeMeaning / relationship
idstringMessage id
threadIdstringThread the message is in
labelIdsarrayLabels on the message
snippetstringShort preview
payloadobjectHeaders and body parts
json · illustrative record shape
{
  "id": "<Message id>",
  "threadId": "<Thread the message is in>",
  "labelIds": [],
  "snippet": "<Short preview>",
  "payload": {}
}

See messages operations

Threads records

Threads

Conversations that group related messages.

FieldTypeMeaning / relationship
idstringThread id
historyIdstringHistory marker
messagesarrayMessages in the thread
snippetstringShort preview
json · illustrative record shape
{
  "id": "<Thread id>",
  "historyId": "<History marker>",
  "messages": [],
  "snippet": "<Short preview>"
}

See threads operations

Drafts records

Drafts

Unsent messages.

FieldTypeMeaning / relationship
idstringDraft id
messageobjectMessage that would be sent
message.idstringId of the draft's message
message.threadIdstringThread the draft belongs to
json · illustrative record shape
{
  "id": "<Draft id>",
  "message": {},
  "message.id": "<Id of the draft's message>",
  "message.threadId": "<Thread the draft belongs to>"
}

See drafts operations

Labels records

Labels

Folders and tags for sorting mail.

FieldTypeMeaning / relationship
idstringLabel id
namestringLabel name
typestringsystem or user
messagesUnreadintegerUnread messages
json · illustrative record shape
{
  "id": "<Label id>",
  "name": "<Label name>",
  "type": "<system or user>",
  "messagesUnread": 1
}

See labels operations

See the Gmail world in the catalog