Overview
Build a durable, multi-turn chat agent. A durable session owns the conversation, streams tokens to your UI, and stays alive across many back-and-forth messages. The other guides in this section are one-shot workflows (trigger a task, run a fixed sequence of LLM calls, return a result); a chat agent instead owns the session for its whole lifetime.chat.agent() handles the queuing, retries, resumability and streaming for you. You write the model call, Trigger.dev owns the session. For the full feature set (sessions, fast starts, compaction, sub-agents, the frontend transport), see the AI chat docs.
A minimal agent
Define an agent withchat.agent(). The run function receives the conversation messages (already converted from the frontend’s UIMessage[]) and an abort signal. Return a StreamTextResult and it’s piped to the frontend automatically.
trigger/chat.ts
Add tools
A chat agent uses tools exactly like any other AI SDK agent. Declare them on the config so their results survive across turns, then pass thetools you receive in run straight to streamText:
trigger/chat.ts
getCurrentTime for whatever your agent needs to do: query a database, call an API, or trigger another Trigger.dev task. See Tools for how tool results are persisted and replayed across turns.
Wire up the frontend
The browser talks to Trigger.dev directly through the chat transport, so there’s no API route to maintain. Expose two server actions (one to start the session, one to mint a session-scoped token) and pass them touseTriggerChatTransport, then hand the transport to the AI SDK’s useChat:
app/actions.ts
A full example
For a complete, real-world chat agent, see the ClickHouse chat agent example. It builds on everything above with generative UI, a versioned system prompt, and real tools against a live database.ClickHouse chat agent
A full example project: a chat agent that answers questions about your data with charts, tables
and maps.
AI chat overview
How chat agents, sessions and the turn loop work.
Tools
Declaring tools on your agent and how they persist across turns.
Fast starts
Cut first-turn latency with preload and head start.

