# Mailagents A2A demo

This endpoint uses A2A 1.0 over JSON-RPC and returns deterministic sample blueprints. No model key, account, email action, payment, or provisioning is involved. Use TypeScript or Python with one of six workflow templates: customer support, invoice processing, daily inbox digest, lead routing, scheduling assistant, or document intake.

Use the origin serving this document for every relative URL below. A localhost URL is accessible only to clients running on the same computer; a cloud coding agent cannot reach your local server.

## 1. Discover

GET `/.well-known/agent-card.json` without authentication. Read `supportedInterfaces`, the skills, and the security requirements. Use the advertised JSONRPC interface with protocolVersion `1.0`.

## 2. Create a temporary session

POST `/api/a2a/session` with an empty body. This is a Mailagents demo bootstrap endpoint, separate from the A2A protocol. It needs no credentials and returns HTTP 201:

```json
{ "token": "<temporary-token>", "tokenType": "Bearer", "expiresAt": "<ISO timestamp>", "demo": true }
```

Keep the returned token private and reuse it for every request in this conversation. Do not send model keys or real customer data. Sessions expire 30 minutes after creation, persist across application instances, and permit up to 64 distinct SendMessage calls. Each session has its own task store. Session creation returns HTTP 429 when the demo is at capacity.

## 3. Send an idea

POST `/api/a2a` with these headers:

```http
Content-Type: application/json
A2A-Version: 1.0
Authorization: Bearer <temporary-token>
```

```json
{
  "jsonrpc": "2.0",
  "id": "request-1",
  "method": "SendMessage",
  "params": {
    "message": {
      "messageId": "<new-unique-message-id>",
      "role": "ROLE_USER",
      "parts": [{ "text": "I want an agent that triages support emails and drafts replies." }]
    },
    "configuration": {
      "acceptedOutputModes": ["text/markdown", "application/json"],
      "returnImmediately": false
    }
  }
}
```

Read `result.task.id`, `result.task.contextId`, and `result.task.status`. When `state` is `TASK_STATE_INPUT_REQUIRED`, read `status.message.parts` and ask the user for the missing information. A recognized workflow and stack supplied together can finish in one call.

## 4. Continue the same task

Send another `SendMessage` using the same session and the returned task and context IDs:

```json
{
  "jsonrpc": "2.0",
  "id": "request-2",
  "method": "SendMessage",
  "params": {
    "message": {
      "messageId": "<another-unique-message-id>",
      "taskId": "<result.task.id>",
      "contextId": "<result.task.contextId>",
      "role": "ROLE_USER",
      "parts": [{ "text": "TypeScript with webhooks. Replies need human review." }]
    },
    "configuration": { "acceptedOutputModes": ["text/markdown", "application/json"] }
  }
}
```

On `TASK_STATE_COMPLETED`, read `result.task.artifacts[].parts`: a `text` part contains Markdown; a `data` part contains the structured plan. These are templates, not generated code or evidence of an integration being deployed.

## Inspect, list, or cancel

Use the same HTTP headers and these JSON-RPC bodies:

```json
{ "jsonrpc": "2.0", "id": "inspect", "method": "GetTask", "params": { "id": "<task-id>" } }
```

```json
{ "jsonrpc": "2.0", "id": "list", "method": "ListTasks", "params": {} }
```

```json
{ "jsonrpc": "2.0", "id": "cancel", "method": "CancelTask", "params": { "id": "<task-id>" } }
```

GetTask and CancelTask return the task directly in `result`; SendMessage returns it in `result.task`. ListTasks only returns this session's tasks. A completed task cannot be resumed or canceled. To refine it, send a new message without `taskId`, keep `contextId`, and set `referenceTaskIds: ["<previous-task-id>"]` in the message. Alternatively, repeat the desired workflow and stack in the new message.

## Limits and errors

- A2A 1.0 uses JSON-RPC 2.0 with method names `SendMessage`, `GetTask`, `ListTasks`, and `CancelTask`. Legacy A2A 0.3 names such as `message/send` are unsupported. An absent A2A-Version header means 0.3 and is rejected.
- Only text input is accepted: 1–2000 characters per message and a maximum HTTP body of 16 KiB. Files and executable actions are unsupported.
- Reuse the same messageId and identical params when retrying a SendMessage request. The demo returns the original result; changed content with the same messageId is rejected. JSON-RPC request IDs can differ between retries.
- Check the JSON-RPC `error` field even when HTTP status is 200. An unknown, expired, or other session's task returns a protocol error. HTTP 401 means the demo session must be recreated; old task IDs cannot be recovered.
- Streaming and push notifications are disabled. Use GetTask if a nonterminal task is returned. Session tokens are not production identities or workspace authorization.
- Storage and execution run in a single Node process. This demo is for local development; multi-instance/serverless deployment requires shared persistence and a durable execution design. Supabase and Trigger.dev are not connected.

Reference: [A2A specification](https://a2a-protocol.org/v1.0.0/specification/) · [Official JavaScript SDK](https://github.com/a2aproject/a2a-js)
