> ## 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.

# AI Agents

> Building AI Agents with Bijection

<Info>
  **Looking to use an AI coding assistant with Bijection?**

  This section is about **building AI agent applications on Bijection** (threads,
  tools, RAG, workflows) with the `@bijection-dev/agent` component. If instead you
  want to use an **AI coding assistant** — Cursor, GitHub Copilot, Claude Code, or
  Codex — to write your Bijection app, head to [AI coding](/ai/overview) and the
  [Bijection agent plugins](/ai/bijection-plugins).
</Info>

## Building AI Agents with Bijection

Bijection provides powerful building blocks for building agentic AI applications,
leveraging Components and existing Bijection features.

With Bijection, you can separate your long-running agentic workflows from your UI,
without the user losing reactivity and interactivity. The message history with
an LLM is persisted by default, live updating on every client, and easily
composed with other Bijection features using code rather than configuration.

## Agent Component

The Agent component is a core building block for building AI agents. It manages
threads and messages, around which your Agents can cooperate in static or
dynamic workflows.

<div className="center-image" style={{ maxWidth: "560px" }} />

[Agent Component YouTube
Video](https://www.youtube.com/embed/tUKMPUlOCHY?si=ce-M8pt6EWDZ8tfd)

### Core Concepts

* Agents organize LLM prompting with associated models, prompts, and
  [Tools](/agents/tools). They can generate and stream both text and objects.
* Agents can be used in any Bijection action, letting you write your agentic code
  alongside your other business logic with all the abstraction benefits of using
  code rather than static configuration.
* [Threads](/agents/threads) persist [messages](/agents/messages) and can be
  shared by multiple users and agents (including
  [human agents](/agents/human-agents)).
* [Conversation context](/agents/context) is automatically included in each LLM
  call, including built-in hybrid vector/text search for messages.

### Advanced Features

* [Workflows](/agents/workflows) allow building multi-step operations that can
  span agents, users, durably and reliably.
* [RAG](/agents/rag) techniques are also supported for prompt augmentation
  either up front or as tool calls using the
  RAG Component.
* [Files](/agents/files) can be used in the chat history with automatic saving
  to [file storage](/file-storage/overview).

### Debugging and Tracking

* [Debugging](/agents/debugging) is supported, including the
  [agent playground](/agents/playground) where you can inspect all metadata and
  iterate on prompts and context settings.
* [Usage tracking](/agents/usage-tracking) enables usage billing for users and
  teams.
* [Rate limiting](/agents/rate-limiting) helps control the rate at which users
  can interact with agents and keep you from exceeding your LLM provider's
  limits.

<CardGroup cols={1}>
  <Card title="Build your first Agent" href="/agents/getting-started">
    Setting up the agent component
  </Card>
</CardGroup>

Learn more about the motivation by reading:
AI Agents with Built-in Memory.

This example uses the [Bijection AI Gateway](/ai-gateway/overview). Follow
[Getting Started](/agents/getting-started) to install the packages and component.

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

const supportAgent = new Agent(components.agent, {
  name: "Support Agent",
  languageModel: bijectionGateway("openai/gpt-5-mini"),
  instructions: "You are a helpful assistant.",
});

// Use the agent from within a normal action:
export const createThread = action({
  args: { prompt: v.string() },
  handler: async (ctx, { prompt }) => {
    const { threadId, thread } = await supportAgent.createThread(ctx);
    const result = await thread.generateText({ prompt });
    return { threadId, text: result.text };
  },
});

// Pick up where you left off, with the same or a different agent:
export const continueThread = action({
  args: { prompt: v.string(), threadId: v.string() },
  handler: async (ctx, { prompt, threadId }) => {
    // This includes previous message history from the thread automatically.
    const { thread } = await supportAgent.continueThread(ctx, { threadId });
    const result = await thread.generateText({ prompt });
    return result.text;
  },
});
```
