Give Your Agent a Computer — Nico Albanese, Vercel
By AI Engineer
Key Concepts
- AI SDK (v6/v7): A lightweight JavaScript/TypeScript framework for building AI agents, featuring structured outputs, global providers, and end-to-end type safety.
- Tool Loop Agent: A pattern for building agents that iteratively use tools to solve tasks.
- Vercel Sandbox: A persistent, file-system-backed environment that allows agents to execute code (Bash/Python) and maintain state across sessions.
- AI Gateway: A service used for model inference, providing access to various LLMs via a unified interface.
- Context Engineering: Managing the agent's "memory" and input history to optimize token usage and performance.
- Durable Workflows: A mechanism to ensure agent tasks are resilient, allowing for retries and long-running processes.
1. Building the Agent Runtime
The speaker emphasizes that modern agents (2026) are built on three pillars: an agent runtime (managing the loop and context), tools (the agent's capabilities), and a computer/sandbox (for state persistence).
- Agent Definition: Using
toolLoopAgentfrom the AI SDK, developers define an agent by specifying a model (e.g., GPT-4o mini) and instructions. - Global Provider: AI SDK 6+ allows setting a global provider, enabling the use of any model via the AI Gateway without re-configuring providers for every function.
- Route Handlers: The agent is exposed via a Next.js
POSTroute, usingcreateAgentUIStreamResponseto abstract the complexity of streaming agent responses to the client.
2. Tooling and Context Management
The speaker categorizes tools into three types:
- Custom Tools: Defined by the developer with a description, input schema, and
executefunction. - Provider-Defined Tools: Pre-trained tools (e.g., Anthropic’s bash or computer-use tools) where the provider handles the execution logic.
- Provider-Executed Tools: Tools like "Web Search" that run on the provider's infrastructure, returning results directly to the agent.
Context Optimization:
- To prevent context bloat, the speaker suggests using
prepareStepcallbacks to filter or prune message history before each step. - Sub-agents: For complex tasks, offload work to sub-agents that process data independently and return only a concise summary (e.g., 500 tokens) to the main thread, keeping the primary context window lean.
3. Persistent Sandboxes
A major focus is the use of Named Persistent Sandboxes. Unlike ephemeral environments, these allow the agent to maintain a consistent file system state.
- Mechanism: When a sandbox is referenced by name, Vercel checks for an active session or spins up a new one, snapshotting the file system state upon inactivity.
- Memory Implementation: The speaker demonstrates using a
memories.mmdfile within the sandbox. The agent is instructed to read/write to this file, effectively creating a "long-term memory" that persists across different user interactions.
4. Step-by-Step Implementation Framework
- Setup: Install dependencies (
ai,@ai-sdk/react,zod,vercel-sandbox). - Agent Definition: Create
lib/agent.tsusingtoolLoopAgent. - Route Handler: Define the API endpoint to handle incoming messages and pass them to the agent.
- UI Integration: Use the
useChathook inpage.tsxto manage message state and render tool-specific components (e.g., a terminal UI for Bash tool outputs). - Sandbox Injection: Use
callOptionsto pass a sandbox instance into the agent runtime, allowing tools to access the persistent file system via thecontextobject.
5. Notable Quotes
- "The beauty of the AI SDK is it is lightweight JavaScript... you can define this once in code in a monorepo and then use it anywhere."
- "Memory is a file that you store in your sandbox and you have some kind of actual deterministic code for pulling that in."
- "I don't think having used this my coding agent for 14 hours a day... compaction has not been an issue to me. I have a 95% cache token read ratio... that to me is more valuable."
6. Synthesis and Conclusion
The presentation highlights a shift toward durable, file-system-backed agents. By treating the agent's environment as a persistent computer rather than just a stateless chat interface, developers can build agents that learn, store memories, and execute complex, multi-step tasks. The combination of the AI SDK’s type-safe primitives and Vercel’s persistent sandboxes provides a robust framework for building production-grade agents capable of handling thousands of PRs or complex data-driven workflows.
Chat with this Video
AI-PoweredLoad the transcript when you're ready to chat so the initial page stays lighter.