Multi-turn conversations

Real applications do not use single prompts but handle ongoing conversations. A hotel concierge bot needs to route billing questions to the accounting expert, tech issues to IT, and restaurant requests to the concierge. Multi-turn conversations combine routing, state management, and specialized expert personas.

A router is a preliminary prompt that examines the user's intent and directs the conversation to the right expert system. Think of it like a receptionist who listens to your request and sends you to the right department.

You could, but quality drops as the system prompt grows. A single mega-prompt forces the model to juggle every domain at once. Routing lets each expert focus on one thing so the billing expert only worries about charges and the tech expert only handles device issues. Specialization means better answers and easier maintenance.

The routing pattern uses a classifier prompt to categorize the user intent, then routes to a specialized expert: Router: "Classify this query as BILLING, TECH, or CONCIERGE. Reply with only the category." Then based on the category, select the appropriate system prompt: - BILLING -> "You are a hotel accountant. Be precise about charges." - TECH -> "You are an IT specialist. Ask about device and OS." - CONCIERGE -> "You are a luxury hotel concierge. Be warm and enthusiastic." Each expert handles the query with domain-specific knowledge and tone.

For multi-turn conversations, you maintain a messages list that grows with each exchange: messages = [ {role: "system", content: expert_prompt}, {role: "user", content: "My room TV is not working"}, {role: "assistant", content: "I will help. What model is the TV?"}, {role: "user", content: "Samsung, room 405"}, ] Each new user message gets appended, giving the model full conversation context. The system prompt stays constant, keeping the expert persona consistent.

Three common strategies: (1) Sliding window, where you keep only the last N messages. (2) Summarization, where you periodically summarize older messages into a compact context. (3) Retrieval, where you store messages in a database and retrieve relevant ones. Most production systems combine these: recent messages in full, older ones summarized, and a retrieval system for specific facts mentioned earlier.

Routing and orchestration

Matching exercise: Conversation patterns

Loading practice…

Ordering exercise: Multi-turn orchestration

Loading practice…

Validation checklist: Multi-turn conversations checklist

Loading practice…