|
|
Claude Multi-Turn Conversations - Managing Chat History
Author: Venkata Sudhakar
Multi-turn conversations require maintaining a messages array that grows with each exchange between the user and Claude. For ShopMax India, a customer support chatbot must remember context across turns - if a customer mentions they are in Bangalore and then asks about delivery times, Claude should recall the city without the customer repeating it. The messages array is stateless from Claude's perspective, so the application is responsible for storing and replaying the full conversation history on every API call.
Each call to the Messages API requires sending the complete conversation history in the messages array, alternating between user and assistant roles. The application appends the user message, sends the full history, receives Claude's response, then appends the assistant message before the next turn. History management strategies include keeping the full history (simple but costly), sliding window (drop oldest turns), and summarization compression (replace old turns with a summary to stay within token limits).
The following example shows ShopMax India running a multi-turn support session with history trimming when the conversation grows beyond a token threshold:
It gives the following output,
Customer: Hi, I am Priya from Chennai. I want to buy a washing machine.
Support: Hello Priya! Welcome to ShopMax India. We have a great range of washing
machines. Are you looking for a front load or top load model?
History turns: 1
Customer: What is the price range for front load machines?
Support: Our front load washing machines range from Rs 23,490 to Rs 45,000.
The IFB 6.5kg starts at Rs 23,490 and the LG 8kg ThinQ is at Rs 31,990.
History turns: 2
Customer: Is the IFB 6.5kg model good for Chennai water quality?
Support: Yes, the IFB 6.5kg is an excellent choice for Chennai. Its Aqua Energie
feature treats hard water, which is common in Chennai, making it very suitable.
History turns: 3
Customer: Can I get 0% EMI on my HDFC card?
Support: Absolutely, Priya! We offer 0% EMI on HDFC, ICICI, and Axis cards
for up to 12 months on the IFB 6.5kg at Rs 23,490.
History turns: 4
Customer: What is the delivery time to my city?
Support: For Chennai, standard delivery takes 2-3 business days.
Installation is included and will be scheduled within 24 hours of delivery.
History turns: 5
For ShopMax India production chatbots, store conversation history in Redis with a TTL of 30 minutes to match typical session lengths - this avoids re-sending history on page refreshes while keeping memory usage bounded. When using summarization compression, send the last 4 turns verbatim plus a summary of earlier context so Claude has both recent detail and long-term context. Monitor average history length per session in your analytics; if users regularly hit 20+ turns, your bot may not be resolving issues efficiently and needs better tool coverage or escalation logic.
|
|