> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlegion.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Run an agent inside your product

> Add the TypeScript kit to a Next.js app and see a signed tool call for a test customer.

You'll need Node.js 22 or later and access to a Platform developer organization. Use an existing Next.js 16 project with TypeScript and the App Router, or let the CLI create one. You can read the full developer reference before signing in. [Platform console](https://platform.openlegion.ai/sign-in?for=developers)

## 1. Add the kit in test mode

Run the initializer in the root of your application.

```sh theme={null}
npx openlegion init
```

For a new project, use `npx openlegion init my-app` and then `cd my-app`. When the browser opens, approve the code displayed in your terminal. The CLI installs `@openlegion/platform`, writes a test key to `.env.local` and adds these files to the application.

| File | What to look for |
| - | - |
| `openlegion/template.ts` | The agent's instructions and tools |
| `openlegion/tools.ts` | An example function named `get_account` in the agent's tool list |
| `openlegion/session.ts` and `openlegion/client.ts` | The development user and the code that finds or creates the customer's workspace |
| `app/api/openlegion/[...route]/route.ts` | The server handler for chat, signed tool calls and webhooks |
| `app/agent/page.tsx` | The page that renders the chat |

## 2. Start both development processes

Start the Next.js server with the command the initializer printed. For an npm project, use the development script.

```sh theme={null}
npm run dev
```

Open a second terminal in the project directory and start the Platform CLI.

```sh theme={null}
npx openlegion dev
```

Leave both running. The CLI pushes the template to test mode and forwards signed calls to your local app. The first run also writes the connector secret into `.env.local`. If the CLI asks you to restart your application, restart the app server, then run the CLI command again.

## 3. Verify the round trip

Open `http://localhost:3000/agent` on the default development port and ask **What's my account?** Look for `get_account` in the CLI output and the example customer information in the chat. That confirms the agent called code in your application.

If the page opens but calls redirect to your login page, check whether your app's sign-in middleware covers `/api/openlegion`. Let the kit handle that route's signed requests and keep the browser session check in your server-side resolver. Before putting real customer data behind the example tool, replace the development session with your own authentication. [Identity and tools](https://docs.openlegion.ai/platform/identity-and-tools.md)

[Maintained quickstart and scaffold examples](https://platform.openlegion.ai/docs/quickstart) · [Setup with a coding agent](https://platform.openlegion.ai/docs/add-to-your-app)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.