Public
Likevercel-ai-agent-demo
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
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.
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...
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")
- Fork this val
- Set the
OPENAI_API_KEYenvironment 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.
- Or use a different provider — set
- Customize your agent: Edit
main.ts— change the model, add custom tools, or modify the prompt. - Run it: Click
Runonmain.ts
- Vercel AI SDK Docs
- Building Agents with AI SDK
- Web Search Agent Cookbook
- OpenAI Agents Template — the OpenAI-specific version of this template
- Val Town Documentation