You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: rework the intro, agent anatomy page, and AI agent examples
## Docs: intro rework, agent anatomy rewrite, and more AI agent examples
- **Introduction.** Reworked the docs landing page to lead with AI
agents and workflows: a cleaner hero, a core concepts section, and short
sections for building agents, scaling and scheduling, and self hosting.
Corrected the licensing wording and refreshed the card styling.
- **Anatomy of an agent.** Rewrote the page so it teaches the three
parts of a chat agent (the agent task, the durable session, and the
frontend transport) and traces a single message through them, instead of
only linking out to other pages.
- **AI agent examples.** Added more example projects to the AI agents
overview: an ElevenLabs voice agent, the ask Trigger chat agent, a batch
LLM evaluator, and a Claude thinking chatbot.
Mono-RevId: fb6db42f103bdc6d35af62163ee33427fb67211d
description: "The moving parts of a chat agent — the agent task, the session, the frontend transport — and which page covers each."
4
+
description: "The three parts of a chat agent — the agent task that runs the turn loop, the durable session that carries messages, and the frontend transport — what each does and where it's documented."
5
5
---
6
6
7
-
**A chat agent is three parts: a long-lived agent task that runs the turn loop, a durable Session carrying messages in and the response stream out, and a frontend transport that plugs the session into`useChat`.**The pages in this section each own one part of that picture. This page is the map — if you'd rather read mechanics end to end, skip to [How it works](/ai-chat/how-it-works).
7
+
**A chat agent is three parts: an agent task that runs the turn loop, a durable session that carries messages in and streams the response out, and a frontend transport that connects the session to`useChat`.**This page is your map of the Building agents section — what each part does, how a single message flows through them, and which page to open next.
8
8
9
9
```mermaid
10
10
flowchart LR
@@ -14,7 +14,33 @@ flowchart LR
14
14
OUT -- "streamed response" --> FE
15
15
```
16
16
17
-
Everything below maps onto one annotated agent:
17
+
## Follow one message
18
+
19
+
A single turn moves through all three parts in order:
20
+
21
+
1. The **frontend transport** sends the user's message to the session's inbound stream (`.in`).
22
+
2. The **agent task** wakes on the new message, runs your turn loop, and streams the model's response into the session's outbound stream (`.out`).
23
+
3. The **frontend transport** reads `.out` and renders tokens into `useChat` as they arrive.
24
+
25
+
The session sits in the middle so both sides never have to be online at the same moment — the task keeps writing to `.out` even if the browser reloads mid-stream.
26
+
27
+
## The three parts
28
+
29
+
### The agent task
30
+
31
+
`chat.agent()` is the code you write: a long-lived agent whose `run` function is the turn loop. Messages arrive accumulated, you call `streamText`, and the returned stream is piped back to the frontend for you. [Tools](/ai-chat/tools) the model can call and [lifecycle hooks](/ai-chat/lifecycle-hooks) that fire around each turn both hang off the same config. See [Backend](/ai-chat/backend) for the full `chat.agent()` surface.
32
+
33
+
### The session
34
+
35
+
The conversation lives in a [session](/ai-chat/sessions), not in the task's memory: a pair of durable streams — `.in` and `.out` — keyed on your `chatId`. Because the session is durable, a conversation survives page refreshes, deploys, and the run boundaries between turns. The task can restart and pick up the same session. [How it works](/ai-chat/how-it-works) covers the mechanics of what survives and why.
36
+
37
+
### The frontend transport
38
+
39
+
One hook — `useTriggerChatTransport` — connects the Vercel AI SDK's `useChat` to the agent's session. There are no API routes to write: the transport talks to the session directly using a scoped token. See [Frontend](/ai-chat/frontend) for wiring, tokens, and starting sessions.
40
+
41
+
## An annotated agent
42
+
43
+
Everything above maps onto one task:
18
44
19
45
```ts trigger/my-agent.ts
20
46
import { chat } from"@trigger.dev/sdk/ai";
@@ -24,18 +50,18 @@ import { anthropic } from "@ai-sdk/anthropic";
24
50
exportconst myAgent =chat.agent({
25
51
id: "my-agent",
26
52
27
-
// Tools declared on the config survive history re-conversion
28
-
// across turns — see Tools.
53
+
// Tools the model can call, declared on the config so they
54
+
//survive history re-conversion across turns — see Tools.
29
55
tools: { searchDocs },
30
56
31
-
//Hooks fire around each turn: validation, persistence,
32
-
//post-turn work — see Lifecycle hooks.
57
+
//A lifecycle hook: fires after each turn, here to persist
58
+
//the response — see Lifecycle hooks.
33
59
onTurnComplete: async ({ responseMessage }) => {
34
60
awaitdb.messages.save(responseMessage);
35
61
},
36
62
37
-
// The turn loop. Messages arrive accumulated; you stream back.
38
-
//Options, levels, and alternatives — see Backend.
63
+
// The turn loop. Messages arrive accumulated; the returned
64
+
//stream is piped back to the frontend — see Backend.
The frontend side is one hook — `useTriggerChatTransport` connects `useChat` to the agent's session, no API routes ([Frontend](/ai-chat/frontend)). Underneath, the conversation lives on a [Session](/ai-chat/sessions): a pair of durable streams keyed on your `chatId` that survives refreshes, deploys, and run boundaries.
0 commit comments