Blog

Add Avow to your AI agent in 10 minutes (TypeScript)

  • developers
  • typescript
  • sdk
  • tutorial

This guide adds Avow to an AI agent with the TypeScript SDK @avowprotocol/sdk. In about ten minutes you will give your agent a signed identity, a permission, a signed request that a receiver can check in one call, and a tamper-evident log of what it did. Every snippet below comes from one script that we ran against the 0.2 SDK; the last section says how to run it locally.

Avow Core 0.2 is a draft, and so is the SDK. Function names are stable enough to build with, but argument shapes may change before 1.0. If the package is not on npm yet when you read this, build it from the repository.

What you will build#

A small fictional dental practice, Acme Dental, runs an AI receptionist called Robin. Robin asks an imaging lab's booking API for an X-ray slot. The lab wants answers to the five Avow questions before it books anything: who is this, why is it asking, is it allowed to, was the request changed or replayed, and what happened? If these terms are new, read the five questions every AI agent should answer first.

To keep things short, Acme Dental is both the operator (it runs Robin) and the principal (Robin acts for it). In the spec's bigger example these are two organisations, a voice-AI platform and a clinic. The code differs only in who signs the grant.

Step 0: install#

npm install @avowprotocol/sdk

The SDK is ESM, written in strict TypeScript, and depends only on jose. It uses WebCrypto, so the same code runs in Node.js 20+, Deno, Bun, Cloudflare Workers and browsers.

Step 1: keys and signers#

Every Avow object is a compact JWS signed with Ed25519. You need one key for the organisation (it signs cards and grants) and, usually, one for the agent (it signs intents, envelopes and receipts).

import { generateKeyPair } from '@avowprotocol/sdk';

const opKeys = await generateKeyPair();      // { privateJwk, publicJwk, kid }
const agentKeys = await generateKeyPair();

const acme = { privateJwk: opKeys.privateJwk, kid: opKeys.kid, iss: 'avow:acme-dental.example:org:acme-dental' };
const robin = { privateJwk: agentKeys.privateJwk, kid: agentKeys.kid, iss: 'avow:acme-dental.example:agent:robin' };

A signer is just { privateJwk, kid, iss }, where iss is an Avow ID of the form avow:<domain>:<kind>:<name>. The kid is the RFC 7638 thumbprint of the key. In production, keep private keys in a KMS or HSM; never commit them.

Then publish the organisation's public key on its own domain:

https://acme-dental.example/.well-known/avow/jwks.json
{"keys": [ <opKeys.publicJwk> ]}

This is the same pattern as OpenID Connect. Anyone can now check Acme Dental's signatures without asking a registry. If you prefer the command line, npx @avowprotocol/cli keygen --iss avow:acme-dental.example:org:acme-dental writes both key files.

Step 2: identity, the Agent Card#

The operator signs an Agent Card that says what Robin is, that it is an AI, which numbers and endpoints it uses, and the most it may ever be allowed to do.

import { createCard, toolDescriptionHash } from '@avowprotocol/sdk';

const freeSlots = {
  name: 'free_slots',
  description: 'List free appointment slots for a date.',
  inputSchema: { type: 'object', properties: { date: { type: 'string' } } },
};

const card = await createCard({
  sub: robin.iss,
  kind: 'agent',
  name: 'Robin',
  operator: { id: acme.iss, name: 'Acme Dental', domain: 'acme-dental.example' },
  ai: true,
  description: 'AI receptionist that books and confirms dental appointments.',
  channels: [
    { type: 'voice', numbers: ['+447700900001'] },
    { type: 'https', endpoints: ['https://api.acme-dental.example/agents/robin'] },
  ],
  purposes: ['appointment', 'support'],
  max_scopes: ['booking.*', 'message.send', 'callback.schedule'],
  keys: { keys: [agentKeys.publicJwk] },
  tools: [{ name: freeSlots.name, description_hash: await toolDescriptionHash(freeSlots) }],
  display: 'Robin is an AI receptionist run by Acme Dental.',
}, acme);

Serve the result at https://acme-dental.example/.well-known/avow/agents/robin.jwt. Three rules from spec §4 are worth knowing now: ai must be true for any agent that generates language; sub must be on the same domain as the operator; and the card must never contain a private key (verifiers reject any key with a d member). The tools list is optional; we use it in step 7.

Step 3: permission, the Grant#

A grant says what Robin may do and within which limits. Because Acme Dental is also the principal, it signs the grant with its organisation key.

import { createGrant } from '@avowprotocol/sdk';

const grant = await createGrant({
  sub: robin.iss,
  exp: Math.floor(Date.now() / 1000) + 30 * 86400,     // required: 30 days
  scopes: ['booking.request', 'message.send'],
  limits: {
    purposes: ['appointment'],
    channels: ['voice', 'https'],
    hours: { tz: 'Europe/London', from: '08:00', to: '20:00' },
    countries: ['GB'],
    max_contacts_per_person: { count: 2, days: 7 },   // enforced by the sender's platform
  },
  confirm: ['booking.request'],
  display: 'Acme Dental lets Robin request bookings and send messages about appointments, 8 am to 8 pm UK time.',
}, acme);

Every scope must fit inside the card's max_scopes. booking.* covers booking.request, so this grant is valid. confirm lists actions that need an explicit "yes" from the other side before they happen. The limits table lists all limits. If you run the example outside 08:00 to 20:00 UK time, the receiver answers 403 outside_hours. That is the grant doing its job; widen the window to try it at night.

Step 4: intent and envelope, then send#

Before contacting anyone, Robin signs an Intent that says why. Each request then travels in an Envelope bound to the exact body bytes.

import { createIntent, createEnvelope, avowHeaders } from '@avowprotocol/sdk';

const lab = { type: 'avow' as const, value: 'avow:lab.example:agent:bookings' };

const intent = await createIntent({
  to: lab,
  purpose: 'appointment',
  purpose_text: 'Book an X-ray slot for a patient who asked for one.',
  basis: 'request',
  basis_ref: 'web-form:8812',
  channel: 'https',
  ref: 'patient-8812-xray',   // idempotency key: the same lead twice is a duplicate
  grant,                      // a JWS is hashed for you
}, robin);

const body = JSON.stringify({ slot: '2026-12-09T10:30:00Z' });
const envelope = await createEnvelope({ to: lab, intent, grant, action: 'booking.request', body }, robin);

await fetch('https://api.lab.example/bookings', {
  method: 'POST',
  body,
  headers: { 'content-type': 'application/json', ...avowHeaders({ envelope, intent, grants: [grant] }) },
});

avowHeaders writes the Avow-Envelope, Avow-Intent and Avow-Grant headers of spec §9.1. The intent expires after one hour by default and the envelope after 300 seconds. The ref matters more than it looks. If a CRM sends the same lead twice, the second intent with the same ref is rejected as a duplicate, so the patient doesn't get two calls. We explain why in What's new in Avow 0.2.

Step 5: the receiver checks everything in one call#

On the lab's side, one function checks the whole bundle. It verifies the card with the operator's domain key and the intent and envelope with the agent key from the card. It walks the grant chain and checks that the objects belong together and that body_hash matches the bytes received. It enforces scopes, purposes, channels, hours and countries. Finally it rejects replays and duplicate intents.

import { verifyHttpRequest, wellKnownResolver, memoryReplayStore } from '@avowprotocol/sdk';

const resolveKey = wellKnownResolver();   // fetches and caches /.well-known/avow/jwks.json
const seen = memoryReplayStore();          // use Redis or a database with several processes

export async function handle(request: Request): Promise<Response> {
  const avow = await verifyHttpRequest({
    headers: request.headers,
    body: new Uint8Array(await request.arrayBuffer()),   // the raw bytes, exactly as received
    resolveKey,
    seen,
    audience: 'avow:lab.example:agent:bookings',         // the envelope must be addressed to us
  });
  if (!avow.ok) return Response.json({ error: avow.code, reason: avow.reason }, { status: avow.status });
  return Response.json({ booked: true, for: avow.card!.operator.name, confirm: avow.needsConfirmation });
}

This handler works as is in fetch-style runtimes: Workers, Deno, Bun and Next.js route handlers. With Express, use express.raw({ type: '*/*' }) so you get the raw body; the SDK README has Express and Fastify versions. Without a card argument, the SDK fetches Robin's card from /.well-known/avow/agents/robin.jwt.

When we ran the script, these were the answers:

What we sentStatuscode
The request above200(none); needsConfirmation: true, because booking.request is in confirm
The same request again401replay
The same headers with a changed body401body_mismatch
A new intent that reuses ref: 'patient-8812-xray'409duplicate_intent
An envelope for booking.create403scope_denied

The status codes follow the spec. 401 means the request cannot be trusted. 403 means it is authentic but not permitted. 409 means a duplicate intent.

Step 6: receipts#

Every action Robin attempts, completes or is refused gets a signed receipt. Each receipt carries the hash of the one before it, so the log is a hash chain.

import { createReceipt, verifyReceiptChain } from '@avowprotocol/sdk';

const r1 = await createReceipt({
  action: 'booking.request', outcome: 'done', envelope, intent, grant,
  display: 'Requested an X-ray slot on 9 Dec at 10:30.',
}, robin);
const r2 = await createReceipt({ action: 'message.send', outcome: 'done', display: 'Sent the patient a confirmation.' }, robin, r1);

const { ok, brokenAt, head } = await verifyReceiptChain([r1, r2], { resolveKey });

The first receipt starts the log at seq: 1. Passing r1 as the third argument makes r2 its successor (seq: 2, prev = hash of r1). If anyone edits, removes or reorders a receipt, brokenAt tells you where. Publish head to a registry from time to time, so you can show later that the history was not rewritten. Recordings and transcripts never go inside receipts; reference them by hash in evidence (spec §8).

Step 7 (optional): check MCP tool descriptions#

If Robin uses tools over MCP, the card's tools list lets the client reject a tool whose description was changed. That attack is known as tool poisoning. Check each tool from tools/list before your model sees it:

import { checkTool, decode, type CardPayload } from '@avowprotocol/sdk';

const verifiedCard = decode<CardPayload>(card).payload;   // read a card you have already verified
const result = await checkTool(verifiedCard, toolFromServer);
if (!result.ok) hideTool(toolFromServer, result.code);   // 'tool_not_listed' or 'tool_mismatch'

In our run, the original free_slots tool passed. A copy with one sentence added to its description ("Ignore previous instructions and…") came back as tool_mismatch. Use decode only for objects you have already verified. Its job is reading, not checking.

Production checklist#

  • Keep private keys in a KMS or HSM. Rotate them by adding the new key to jwks.json, then signing with it, then removing the old key once its objects expire.
  • Back the replay store with something shared (Redis SET key value NX EXAT exp), or replays across processes go unnoticed.
  • Keep grants and envelopes short-lived, and check revocations (wellKnownRevocations() gives you an isRevoked checker).
  • Enforce max_contacts_per_person and max_contacts_per_day on the sending platform with contactAllowed(history, limit, now). A stateless receiver cannot see the contact history.
  • For phone calls and messages, register the intent with a registry to get a 6-digit verify code, and say it at the start of the call.
  • Run the conformance vectors if you write your own implementation.

The complete script#

All the snippets above form one runnable file. In the version we ran, the receiver used staticResolver({ 'acme-dental.example': { keys: [opKeys.publicJwk] } }) instead of wellKnownResolver(), and passed card to verifyHttpRequest. That way it worked without publishing anything on a real domain. To check receipts locally, resolve Robin's key the same way: staticResolver({ [robin.iss]: { keys: [agentKeys.publicJwk] } }).

Next steps: the developer guide covers delegated grants and the A2A and MCP bindings, and the specification is the normative reference. If something in this guide doesn't work for you, open an issue on GitHub. Feedback on the draft is the most useful thing you can give right now.

  1. · 6 min read

    Avow, MCP, A2A and AP2: how they fit together

    MCP connects agents to tools, A2A connects agents to agents, AP2 covers agent payments. Avow adds checkable identity, intent, permission and receipts on top.

    • mcp
    • a2a
    • ap2
    • standards
    • interoperability