-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs(ai-chat): custom agents page, backend decision table, and a building-agents anatomy entry #3921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
docs(ai-chat): custom agents page, backend decision table, and a building-agents anatomy entry #3921
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3726bc0
docs(ai-chat): document custom agents and complete the createSession …
ericallam eb908b9
docs(ai-chat): add an anatomy entry page and reorder building agents
ericallam 965b814
docs(ai-chat): keep anchor stubs for moved backend sections
ericallam 3415122
docs(ai-chat): repoint the tools page customAgent link to custom-agents
ericallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| title: "Anatomy of an agent" | ||
| sidebarTitle: "Anatomy" | ||
| description: "The moving parts of a chat agent — the agent task, the session, the frontend transport — and which page covers each." | ||
| --- | ||
|
|
||
| import RcBanner from "/snippets/ai-chat-rc-banner.mdx"; | ||
|
|
||
| <RcBanner /> | ||
|
|
||
| **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). | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| FE["Frontend<br/>useChat + transport"] -- "user messages" --> IN([Session .in]) | ||
| IN --> AGENT["Agent task<br/>turn loop + hooks"] | ||
| AGENT --> OUT([Session .out]) | ||
| OUT -- "streamed response" --> FE | ||
| ``` | ||
|
|
||
| Everything below maps onto one annotated agent: | ||
|
|
||
| ```ts trigger/my-agent.ts | ||
| import { chat } from "@trigger.dev/sdk/ai"; | ||
| import { streamText, stepCountIs } from "ai"; | ||
| import { anthropic } from "@ai-sdk/anthropic"; | ||
|
|
||
| export const myAgent = chat.agent({ | ||
| id: "my-agent", | ||
|
|
||
| // Tools declared on the config survive history re-conversion | ||
| // across turns — see Tools. | ||
| tools: { searchDocs }, | ||
|
|
||
| // Hooks fire around each turn: validation, persistence, | ||
| // post-turn work — see Lifecycle hooks. | ||
| onTurnComplete: async ({ responseMessage }) => { | ||
| await db.messages.save(responseMessage); | ||
| }, | ||
|
|
||
| // The turn loop. Messages arrive accumulated; you stream back. | ||
| // Options, levels, and alternatives — see Backend. | ||
| run: async ({ messages, tools, signal }) => | ||
| streamText({ | ||
| ...chat.toStreamTextOptions({ tools }), | ||
| model: anthropic("claude-sonnet-4-5"), | ||
| messages, | ||
| abortSignal: signal, | ||
| stopWhen: stepCountIs(15), | ||
| }), | ||
| }); | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ## Where each part is covered | ||
|
|
||
| | Part | Page | | ||
| | ----------------------------------------------------- | ---------------------------------------------- | | ||
| | `chat.agent()` options, the turn loop, piping | [Backend](/ai-chat/backend) | | ||
| | Hooks around each turn (`onTurnComplete`, hydration) | [Lifecycle hooks](/ai-chat/lifecycle-hooks) | | ||
| | Declaring tools, typed payloads, `toModelOutput` | [Tools](/ai-chat/tools) | | ||
| | `useChat` wiring, tokens, starting sessions | [Frontend](/ai-chat/frontend) | | ||
| | Driving a chat from your server instead of a browser | [Server-side chat](/ai-chat/server-chat) | | ||
| | The durable substrate under every agent | [Sessions](/ai-chat/sessions) | | ||
| | Per-run typed state inside the loop | [chat.local](/ai-chat/chat-local) | | ||
| | Type-safe payloads, client data, and messages | [Types](/ai-chat/types) | | ||
| | Building without the managed lifecycle | [Custom agents](/ai-chat/custom-agents) | | ||
| | End-to-end mechanics: what survives a refresh and why | [How it works](/ai-chat/how-it-works) | | ||
|
|
||
| Beyond this section: [Features](/ai-chat/fast-starts) covers opt-in capabilities (Head Start, compaction, steering, actions), and [Patterns](/ai-chat/patterns/sub-agents) covers production recipes (sub-agents, HITL approvals, persistence, recovery). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.