Skip to main content

Agent (app/agent.ts)

Your agent is defined using Vercel AI SDK (ai@^6). The file exports a default ToolLoopAgent and an optional accepts for payment pricing.
app/agent.ts

ToolLoopAgent

The ToolLoopAgent from Vercel AI SDK handles multi-step tool execution loops automatically. It:
  • Takes a model, instructions, and a set of tools
  • Executes tool calls in a loop until the stop condition is met
  • Returns the final response

accepts Export

The optional accepts named export controls x402 payment gating on the A2A /agent endpoint:
  • Agents with accepts are registered on payment-gated A2A endpoints
  • Agents without accepts are not registered
You can also pass an array to accept payment on multiple networks:

capabilities Export

The optional capabilities named export configures the A2A agent card’s capabilities and controls how the executor runs your agent:
app/agent.ts
  • streaming (default: true) — When false, the executor uses generate() instead of stream(), returning the full response as a single artifact
  • pushNotifications (default: false) — Advertises push notification support in the agent card
  • stateTransitionHistory — Advertises state transition history support in the agent card
If omitted, the agent defaults to { streaming: true, pushNotifications: false }. See the agent.ts reference for details.

Sub-Agents (app/agents/*.ts)

Place additional agent files in app/agents/ to expose multiple A2A endpoints from a single deployment. Each file follows the same format as app/agent.ts and is automatically registered on its own path.
app/agents/research.ts
With the layout below, the build auto-generates three independent A2A endpoints:
Files starting with _ (e.g., _helpers.ts) are ignored by the build pipeline. Use this convention for shared utilities.

Tools (app/tools/*.ts)

Each .ts file in app/tools/ exports a Vercel AI SDK tool and an optional accepts for MCP payment gating. Tools are automatically discovered and registered on both A2A and MCP endpoints.
app/tools/weather.ts

Tool Discovery

The build pipeline automatically discovers all .ts files in app/tools/:
  • Each file is registered as an MCP tool
  • Tools with accepts are payment-gated on the /mcp endpoint
  • Tools without accepts are not registered on MCP
Files starting with _ (e.g., _helpers.ts) are ignored by the build pipeline. Use this convention for shared utilities.

Per-Tool Pricing

Each tool can declare its own price, enabling granular pricing across your agent:
Tools also support multiple payment options via an array of accepts entries.

Custom Server

For full control over endpoint registration and middleware, create app/server.ts. This overrides auto-generation entirely:
app/server.ts
See the Custom Server template for a working example.