TOOL WIKI · AGENT SDKS

Vercel AI SDK

Standardizes model access, tools, structured generation, and AI user-interface streams.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Bound a TypeScript support agent’s tool steps

A developer needs a small, observable agent or retrieval step before connecting real business services.

Input
A ToolLoopAgent, orderStatus tool and four-step ceiling.
Expected output
A grounded status plus the recorded number of steps.
  • Success check: The final answer uses packed and the number of steps stays within the configured budget.
  • Try a failure: A repeated tool request must not exceed the configured step ceiling.

Example scope: Actual AI SDK loop; the fixture is not a deployed order service.

Official reference · Vercel AI SDK

WHAT IT ISTypeScript toolkit
WHERE IT FITSAgent SDKs
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
taskinvokedecisiontool callresultstatemeasureApplicationTask + identityVercel AI SDKTypeScript toolkitModel providerConfigured API modelTool serviceAuthorization + executionState storageRun and thread progressEvaluationOutcome + evidence
  1. Authenticate the request and define the goal before calling the framework.

  2. Connecting an AI application backend to an interactive frontend. Separate browser UI state from server-side execution and credentials.

  3. The application supplies provider credentials, model selection, and budgets.

  4. Validate each operation and return authoritative observations.

  5. Choose the checkpoint or session store and its retention policy deliberately.

    Result or stopping point
  6. Check completion, cost, latency, and tool behavior against fixtures.

    Result or stopping point
Vercel AI SDK

Connecting an AI application backend to an interactive frontend. Separate browser UI state from server-side execution and credentials.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Connecting an AI application backend to an interactive frontend.

A design decision to make

  • Separate browser UI state from server-side execution and credentials.

Prerequisites and setup

  • Node.js 22+ and an OpenAI API key. Running the example can incur usage.
Shell
npm init -y
npm install ai @ai-sdk/openai zod
export OPENAI_API_KEY="YOUR_API_KEY"
export OPENAI_MODEL="YOUR_ENABLED_MODEL"

Try a small integration

agent.mjs

JavaScript · agent.mjs
import { ToolLoopAgent, tool, stepCountIs } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const agent=new ToolLoopAgent({model:openai(process.env.OPENAI_MODEL),
  instructions:'Use orderStatus; answer from the observed status.',stopWhen:stepCountIs(4),
  tools:{orderStatus:tool({description:'Read one demo order',
    inputSchema:z.object({orderId:z.string()}),
    execute:async({orderId})=>({status:orderId==='A104'?'packed':'not_found'})})}});
const result=await agent.generate({prompt:'What is the status of A104?'});
console.log(result.text);
console.log('Steps:',result.steps.length);

Run and check the result

Shell
node agent.mjs
  • The final answer uses packed and the number of steps stays within the configured budget.
  • Keep the provider import server-side; a browser UI can consume a separately authenticated stream.

Common failures

  • A missing @ai-sdk/openai provider package fails before the model call.
  • Tool inputSchema validates arguments, while execute must still enforce user permissions.

Production decisions

  • Bind tool execution to the authenticated user and resource permissions. Keep keys in server environment variables.
  • Add deadlines, a turn budget, redacted traces, regression fixtures and explicit handling for refused or incomplete runs.

Keep exploring

Workflow, single agent, or multiple agents?Build an explicit agent loop with LangGraph

Explore the same layer

OpenAI Agents SDKClaude Agent SDKGoogle ADKLangGraph

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.