Vercel AI SDK Agent Template

A Val Town template for building AI agents using the Vercel AI SDK. This is a model-agnostic alternative to the OpenAI Agents template — same agent pattern, but you can swap in any model provider (Anthropic, Google, etc.) by changing a single line.

What is an Agent?

An agent is inference in a loop with tools: an LLM receives a system prompt, reads from and writes to an environment through tools, and loops until it decides it's done.

Rendering mermaid diagram...

Why Vercel AI SDK?

The OpenAI Agents SDK is great if you're all-in on OpenAI. The Vercel AI SDK gives you the same agent capabilities — tool loops, multi-step reasoning, structured output — but with a unified interface across providers. Switch from OpenAI to Anthropic to Google by changing one line:

// OpenAI model: openai("gpt-4o-mini") // Anthropic (just change this line + import) model: anthropic("claude-sonnet-4-20250514") // Google model: google("gemini-2.0-flash")

Get Started

  1. Fork this val
  2. Set the OPENAI_API_KEY environment variable. Get your API key here: https://platform.openai.com/api-keys
    • Or use a different provider — set ANTHROPIC_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, etc.
  3. Customize your agent: Edit main.ts — change the model, add custom tools, or modify the prompt.
  4. Run it: Click Run on main.ts

Learn More