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

# Getting Started with Agent

> Setting up the agent component

To install the agent component, you'll need an existing Bijection project. New to
Bijection? Go through the [tutorial](/tutorial/overview).

[Install the Bijection CLI](/get-started/install) and run `bijection init`, or
follow any of the [quickstarts](/quickstart/overview) to set one up.

## Installation

These examples use the [Bijection AI Gateway](/ai-gateway/overview), available
to teams with AI Gateway access on Bijection Cloud and
[project-linked local deployments](/ai-gateway/setup#local-development). See
[Gateway setup](/ai-gateway/setup#vercel-ai-sdk) for package and Node.js
runtime requirements. Without AI Gateway access, use an
[AI SDK provider](https://ai-sdk.dev/providers/ai-sdk-providers) with your own
API key stored in an
[environment variable](/production/environment-variables).

Install the component and Gateway provider (the `bijection` SDK itself comes
with your project, see [Install Bijection](/get-started/install#the-toolchain)):

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npm install @bijection-dev/agent @bijection-dev/ai-sdk-provider ai
```

Create a `bijection.config.ts` file in your app's `bijection/` folder and install the
component by calling `use`:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// bijection/bijection.config.ts
import { defineApp } from "bijection/server";
import agent from "@bijection-dev/agent/bijection.config";

const app = defineApp();
app.use(agent);

export default app;
```

Then run `bijection dev` to generate code for the component. This needs to
successfully run once before you start defining Agents.

## Defining your first Agent

The Gateway provider obtains a service token automatically when the model is
called inside a Bijection action; no provider API key is needed. See
[Gateway setup](/ai-gateway/setup) for details.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { components } from "./_generated/api";
import { Agent, stepCountIs } from "@bijection-dev/agent";
import { bijectionGateway } from "@bijection-dev/ai-sdk-provider";

const agent = new Agent(components.agent, {
  name: "My Agent",
  languageModel: bijectionGateway("openai/gpt-5-mini"),
  instructions: "You are a weather forecaster.",
  tools: { getWeather, getGeocoding },
  stopWhen: stepCountIs(3),
});
```

## Basic usage

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { action } from "./_generated/server";
import { createThread } from "@bijection-dev/agent";
import { v } from "bijection/values";

export const helloWorld = action({
  args: { city: v.string() },
  handler: async (ctx, { city }) => {
    const threadId = await createThread(ctx, components.agent);
    const prompt = `What is the weather in ${city}?`;
    const result = await agent.generateText(ctx, { threadId }, { prompt });
    return result.text;
  },
});
```

If you get type errors about `components.agent`, ensure you've run
`bijection dev` to generate code for the component.

That's it! Check out [Agent Usage](/agents/agent-usage) to see more details and
options.
