Skip to main content
Chat sessions in AI agents can be modeled at different layers of your architecture. The choice affects state ownership and how you handle interruptions and reconnections. While there are many ways to model chat sessions, the two most common categories are single-turn and multi-turn.

Single-Turn Workflows

Each user message triggers a new workflow run. The client or API route owns the conversation history and sends the full message array with each request.
workflows/chat/index.ts
In this pattern, the client owns conversation state, with the latest turn managed by the AI SDK’s useChat, and past turns persisted to a user-managed database. Persisting turns is usually done through either:
  • A step on the workflow that runs after agent.stream() and takes the message history from the agent return value
  • A hook on useChat in the client that calls an API to persist state
  • The resumable stream attached to the workflow (see Resumable Streams)

Multi-Turn Workflows

A single workflow handles the entire conversation session across multiple turns, and owns the current conversation state. The clients/API routes inject new messages via hooks. The workflow run ID serves as the session identifier.
workflows/chat/index.ts
The writeUserMessageMarker helper writes a data-workflow chunk to mark user turns:
workflows/chat/steps/writer.ts
In this pattern, the workflow owns the entire conversation session. All messages are persisted in the workflow, and follow-up messages are injected via hooks. The workflow writes user message markers to the stream using data-workflow chunks, which allows the client to reconstruct the full conversation in the correct order when replaying the stream.

Choosing a Pattern

Multi-turn is recommended for most production use-cases. If you’re starting fresh, go with multi-turn. It’s more flexible and grows with your requirements. You don’t need to maintain the chat history yourself and can offload all that to the workflow’s built-in persistence. Single-turn works well when adapting existing architectures. If you already have a system for managing message state, and want to adopt durable agents incrementally, single-turn workflows slot in with minimal changes.