---
title: Quickstart
description: Create your first agent in under 5 minutes.
type: guide
summary: Install the SDK, create an agent, and wire up send/reconnect chat helpers.
---

# Quickstart



This guide walks through setting up an agent with Next.js.

## Prerequisites

* Node.js 18+
* A Next.js app (or `npx create-next-app@latest`)
* An API key for your model provider (e.g. `ANTHROPIC_API_KEY`)

## 1. Install

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npm i experimental-agent ai
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm add experimental-agent ai
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn add experimental-agent ai
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun add experimental-agent ai
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## 2. Create your agent

```ts title="src/agent.ts"
import { agent } from "experimental-agent";

export const myAgent = agent("my-agent", {
  model: "anthropic/claude-opus-4.6",
  system: "You are a helpful assistant. Be concise.",
});
```

This agent includes built-in tools (Read, Write, Edit, Grep, List, Bash, Skill, JavaScript) and uses local filesystem storage in development.

## 3. Create chat helpers

```ts title="src/chat.ts"
import { createUIMessageStreamResponse } from "ai";
import { myAgent } from "@/agent";

export async function sendMessage({
  chatId,
  message,
}: {
  chatId: string;
  message: string;
}) {
  const session = myAgent.session(chatId);
  await session.send(message);
  const stream = await session.stream();
  return createUIMessageStreamResponse({ stream });
}

export async function reconnectStream({ chatId }: { chatId: string }) {
  const session = myAgent.session(chatId);
  const stream = await session.stream();
  return createUIMessageStreamResponse({ stream });
}
```

## 4. Wire into your app

```ts
await sendMessage({
  chatId: "my-first-session",
  message: "What files are in the current directory?",
});
```

Call `sendMessage` from your request layer and use `reconnectStream` when the client resumes an in-progress response. For concrete Next.js route handlers, see [Using with Next.js](/docs/guides/nextjs).

## What you just built

* An agent with a model, system prompt, and built-in tools
* Chat helpers for sending and reconnecting streams
* Persistent sessions — send another message to `my-first-session` and the agent remembers the conversation
* Local storage that persists across restarts (stored in `.agent/` in your project root)

## Adding Workflow (Optional)

To make the agent durable — surviving crashes, timeouts, and deploys — add a workflow:

```ts title="src/workflow.ts"
import { myAgent } from "@/agent";
import type { SessionSendArgs } from "experimental-agent";

export async function agentWorkflow(
  sessionId: string,
  ...args: SessionSendArgs<typeof myAgent>
) {
  "use workflow";
  return await myAgent.session(sessionId).send(...args);
}
```

Then use `start()` in your route instead of calling `send()` directly:

```ts
import { start } from "workflow/api";
import { agentWorkflow } from "./workflow";

const result = await start(agentWorkflow, [chatId, message]);
const stream = await session.stream(result);
```

## Next steps

* **[Build Your First Agent](/docs/guides/build-your-first-agent)**: Extend this quickstart with sandbox, custom tools, approvals, and deployment.
* **[Build Your First Tool](/docs/guides/build-your-first-tool)**: Create a custom tool with typed input and output.
* **[Concepts](/docs/concepts)**: Understand sessions, tools, sandbox, and storage.
* **[API Reference](/docs/reference/agent)**: Full `agent()` API documentation.
