# §41 — The agent service

A model on one side, your data on the other, and a protocol in between so the model can ask for things instead of hallucinating them.

`@atlas/ai` is provider-agnostic — OpenAI, Anthropic, or a local Ollama behind the same calls, with streaming, embeddings, RAG, and conversations. `@atlas/mcp` exposes your own application over the Model Context Protocol: tools register from whatever you put in the context, so handing an agent your database is a line, not a project.

Two documentation tools are always on, with or without a context: `docs.list` and `docs.read`. An agent working in your repository can read Atlas's canonical documentation without a network round trip.

## What you are carrying

- `@atlas/ai` — Providers, chat, streaming, embeddings, RAG, agents.
- `@atlas/mcp` — Your app as MCP tools, plus the docs tools.
- `@atlas/server` — The HTTP surface in front of it.
- `@atlas/cache` — Embeddings are not free twice.

## Start it

```bash
atlas init -n mybot --template ai
```

## What it looks like

`src/agent.ts`

```ts
import { createProvider } from "@atlas/ai"
import { collectTools, createContext, createMcpServer } from "@atlas/mcp"

const model = createProvider({ provider: "anthropic", key: process.env.ANTHROPIC_API_KEY! })

for await (const chunk of model.chatStream({
  messages: [{ role: "user", content: "Summarise the last release" }],
})) {
  if (chunk.type === "text") process.stdout.write(chunk.content ?? "")
}

// The same app, exposed to an agent. Tools register from what the context has.
const ctx = createContext({ db, routes, config })
createMcpServer(collectTools(ctx), ctx).start()
```

## Where now

- Put it online — turn to §100 (Appendix A)
- Hand it to an agent — turn to §102 (Appendix C)
- Walk it again from the start — turn to §1
