Skip to main content
The @corti/ai-sdk-adapter package provides utilities to connect Corti’s A2A (Agent-to-Agent) agents with the Vercel AI SDK. It converts between AI SDK’s UI message format and Corti’s A2A format, so you can use familiar patterns like useChat to build chat interfaces powered by Corti agents. The adapter provides three main functions:
  • convertToParams() — converts CortiUIMessage[] to A2A MessageSendParams
  • toUIMessageStream() — converts an A2A stream to a UI message stream
  • createA2AClientFactory() — creates an A2A client factory configured with Corti authentication

Installation

Quick start

Server: streaming API route (Next.js)

Create an API route that receives messages from the client, converts them to A2A format, streams the response from a Corti agent, and returns a UI message stream.
app/api/chat/route.ts

Client: React chat component

Use the Vercel AI SDK useChat hook with the CortiUIMessage type to render agent responses.
app/chat.tsx

How it works

Context and task continuity

The adapter automatically manages conversation context and task continuity:
  • contextId — maintains conversation context across multiple messages. Automatically inferred from the last assistant message.
  • taskId — continues an existing task when the agent requires more input. Only included when the last assistant message has state: 'input-required'.
  • Credentials — only sent on the first message (when no taskId is present).
The convertToParams() function handles all of this automatically — you just pass the messages array from useChat.

Stream callbacks

The toUIMessageStream() function accepts a StreamConversionOptions object with optional callbacks to monitor stream progress:

Runtime support

This package supports:
  • Node.js (18+)
  • Edge runtimes (Vercel Edge, Cloudflare Workers)

Resources