# Agent-to-Agent Payments

TherosAI natively supports the pattern of agents commissioning other agents. An orchestrating agent can pay a specialist agent for completing a task — with on-chain escrow ensuring payment releases only on verified completion.

This is the primitive that makes agent economies real: autonomous workflows where agents commission work, pay for results, and settle atomically on-chain, without human intervention at any step.

***

## How A2A payments work

The A2A payment flow has four stages:

### 1. Initiate

The requesting agent calls `POST /v1/payments/a2a`, specifying the payee vault address, task description, agreed amount, and a timeout:

```typescript
const escrow = await client.payments.a2a.create({
  fromWallet: "wal_requester",
  toWallet: "7xKp...nR4Q",          // Payee's TherosAI Solana address
  amount: "10.00",
  currency: "USDC",
  taskDescription: "Summarise Q1 2026 earnings calls for the S&P 500 healthcare sector",
  timeoutSeconds: 3600,              // 1 hour — funds return if not completed
});

console.log(escrow.id);             // escrow_...
console.log(escrow.status);         // "locked"
console.log(escrow.solanaAddress);  // The escrow PDA address
```

### 2. Lock

TherosAI creates an **on-chain escrow vault** — a PDA separate from both agent vaults. The USDC is transferred from the requesting agent's vault to the escrow PDA. The funds are locked: neither party can access them until the escrow resolves.

The requesting agent's vault balance decreases immediately. The payment is subject to the requesting agent's spending policy — `maxPerTx`, `allowedRecipients`, and all other rules apply.

### 3. Complete

The receiving agent performs the task and submits a **completion proof**. Accepted proof formats:

* **Output hash** — a SHA-256 hash of the task output, submitted via `POST /v1/payments/a2a/{escrow_id}/complete`
* **Signed attestation** — a payload signed by the receiving agent's session authority
* **Webhook callback** — a webhook from a trusted third-party verifier (e.g. an evaluation agent)

```typescript
await client.payments.a2a.complete("escrow_xyz", {
  proofType: "output_hash",
  proof: "sha256:a3f2b1...",
  outputUrl: "https://your-storage.com/result_8821.json", // Optional
});
```

### 4. Release

Upon verification of the completion proof, the TherosAI on-chain program releases the escrowed USDC to the receiving agent's vault. The release is written on-chain and emits an `escrow.released` event.

```json
{
  "event": "escrow.released",
  "escrow_id": "escrow_xyz",
  "from_wallet": "wal_requester",
  "to_wallet": "wal_specialist",
  "amount": "10.00",
  "tx_signature": "5KtP...",
  "timestamp": "2026-04-29T13:00:00Z"
}
```

***

## Timeouts and disputes

### Timeout

If the receiving agent does not submit a completion proof within the `timeoutSeconds` window, the escrow automatically releases back to the requesting agent's vault. An `escrow.refunded` event is emitted.

### Dispute

Either party can raise a dispute before the timeout expires:

```typescript
await client.payments.a2a.dispute("escrow_xyz", {
  reason: "Output does not match task specification",
  evidence: "sha256:evidence_hash...",
});
```

During beta, TherosAI acts as the arbiter for disputes. The outcome is one of:

* **Full release** — funds released to the receiving agent
* **Full refund** — funds returned to the requesting agent
* **Partial settlement** — a split determined by TherosAI's review of the evidence

The dispute resolution process targets a 24-hour resolution window. All dispute decisions are written on-chain.

***

## x402 compatibility

TherosAI A2A payments are compatible with the **x402 micropayment protocol** — an emerging standard for machine-readable per-request payments.

When a TherosAI agent encounters an x402-enabled API endpoint (one that returns HTTP 402 with a machine-readable payment requirement), it can resolve the payment automatically using its TherosAI vault, provided the recipient is permitted by the vault's spending policy.

x402 payments do not use the escrow mechanism — they are direct transfers, settled in a single transaction.

***

## Querying escrows

```typescript
// All open escrows for a vault
const escrows = await client.payments.a2a.list({
  walletId: "wal_requester",
  status: "locked",
});

// Single escrow detail
const escrow = await client.payments.a2a.get("escrow_xyz");
```

***

## Escrow events

| Event              | Trigger                                                    |
| ------------------ | ---------------------------------------------------------- |
| `escrow.created`   | Escrow PDA created, funds locked                           |
| `escrow.completed` | Completion proof submitted, pending release                |
| `escrow.released`  | Funds released to receiving agent                          |
| `escrow.refunded`  | Timeout reached or dispute resolved in favour of requester |
| `escrow.disputed`  | Dispute raised — awaiting arbiter review                   |

***

## Current limitations (beta)

* **TherosAI is the arbiter.** Dispute resolution is not fully trustless in beta — the TherosAI program is the final authority. A decentralised arbitration layer is on the roadmap for post-beta.
* **Single-asset only.** Escrow supports USDC only.
* **Solana-only.** Cross-chain A2A is not supported in v1.
* **No partial release.** Escrow either releases in full or refunds in full. Milestone-based partial releases are on the roadmap.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.therosai.com/core-concepts/a2a-payments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
