Module 10: Multi-Turn Conversations
Building conversational applications with context preservation.What You’ll Learn
- Maintaining context across multiple exchanges
- The query/response pattern for conversations
- How Claude remembers previous messages in a session
Single-Turn vs Multi-Turn
Both clients support multi-turn conversations with full context preservation. Choose based on your programming paradigm.
The Conversation Loop Pattern
- Blocking
- Reactive
connectText()/queryText(), reactive uses connect().text()/query().text() with flatMap chaining. Context is preserved across all turns in both.
How It Works
Full Message Access
When you need metadata, tool use details, or cost information:connectAndReceive() and queryAndReceive() when you need access to all message types.
Key Points
- Both
ClaudeSyncClientandClaudeAsyncClientsupport multi-turn conversations connectText(prompt)starts the session and returns the text responsequeryText(prompt)sends follow-ups and returns the text responseconnectAndReceive()/queryAndReceive()for full message access- Context persists until the client is closed
When to Use Multi-Turn
Tradeoffs
- Memory growth: Context accumulates with each turn. Long conversations consume more tokens and increase latency as Claude re-processes the full history.
- No partial context: You cannot selectively forget messages. The entire conversation history persists until the session closes.
- Session coupling: The client must remain open for the conversation to continue. Network interruptions or process crashes lose the session.
- Cost implications: Each turn includes all prior messages in the API call. A 20-turn conversation sends the full history 20 times.