feat(vercel): add AI SDK adapter#290
Draft
robelest wants to merge 3 commits into
Draft
Conversation
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Vercel AI SDK 7 adapter on top of Agent V2.
This PR is stacked on #289. Agent V2 remains the durable Convex primitive: it owns threads, messages, runs, tools, approvals, usage, structured output, cancellation, and run event streams. The Vercel adapter lets apps use AI SDK model providers and AI SDK React without moving
UIMessage,ModelMessage, or provider-specific APIs into Agent core.Stack
Base PR: #289,
refactor(agent): introduce durable run coreThis PR adds the Vercel layer and updates the example to prove the happy path.
Public API
Server-side model adapter:
React chat transport over Convex realtime:
The app passes normal Convex function references. The adapter handles
UIMessageconversion, run-event streaming, reconnection, and cancel propagation.Tool Composition
Agent tools stay Agent-native. The Vercel adapter maps their input schemas into AI SDK
streamText, but Agent still owns approval, execution, output validation, persistence, and replay.The execution path is still Convex-native:
tool.calland projects tool state into bounded rows.needsApproval.tool.result, usage, output, and final messages.This keeps the core tool shape adapter-neutral. A TanStack adapter can map the same
defineToolresult to TanStack'stoolDefinition({ inputSchema, outputSchema, needsApproval }); LangChain, Mastra, or custom provider adapters can do their own translation without changing Agent core.AI SDK Helpers Stay Composable
This adapter does not wrap every AI SDK helper. That is intentional. Agent should do one thing: durable agent execution. Apps can still use the AI SDK directly for provider-specific work around Agent.
Image generation inside an Agent tool
Agent stores the result as Agent tool output or an Agent file part. The app still owns storage, authorization, and file lifecycle.
Embeddings and RAG as app-owned context
Agent receives
AgentContextBlock[]. It does not own embeddings, vector tables, RAG indexing, or retrieval policy.Structured generation outside a run
AI SDK 7 routes structured output through
generateText/streamTextwithoutput. Apps can use that for side tasks and then save the result into app tables, Agent messages, or run-owned output events.Agent core also supports run-owned structured output through
new Agent(..., { output: v.object(...) })and Agentoutputevents. Apps can choose the shape that fits the workflow.Provider-specific helpers remain available
Because
defineModelaccepts AI SDKstreamTextoptions, apps keep provider settings where they belong:Agent does not hide provider configuration behind a new wrapper language.
Convex Realtime Transport
The React adapter uses Convex subscriptions, not the Vercel HTTP transport path.
A server module provides conventional Convex functions:
useChatTransportcallssend, then watchesreadover the normal Convex connection. Stream remains internal to Agent users, but the adapter reuses Agent's Stream-backed run events to emit live AI SDKUIMessageChunkupdates.Public vs Internal
Public exports:
Internal translation code maps between:
UIMessage;UIMessageChunk;streamTexttool schemas.The public happy path is intentionally small: define an Agent model with AI SDK provider settings, define Agent tools once, and use AI SDK React with a Convex realtime transport.