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.- Tab Title
- Tab Title
- Tab Title
workflows/chat/index.ts
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
useChatin 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.- Tab Title
- Tab Title
- Tab Title
- Tab Title
workflows/chat/index.ts
writeUserMessageMarker helper writes a data-workflow chunk to mark user turns:workflows/chat/steps/writer.ts
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.
Related Documentation
- Building Durable AI Agents - Foundation guide for durable agents
- Message Queueing - Queueing messages during tool execution
defineHook()API Reference - Hook configuration optionsDurableAgentAPI Reference - Full API documentation