---
title: "Multi-turn conversations"
description: "Pass conversation history to the Query Agent for context-aware follow-up questions."
url: https://docs.weaviate.io/query-agent/reference/multi_turn_conversations
---

# Multi-turn conversations

The Query Agent transforms a natural language query into actionable searches. You can either pass a single string for the query, or provide more context by including a full conversation with previous message turns.

**Python (Agents)**

```py
from weaviate.agents.classes import ChatMessage

conversation = [
    ChatMessage(
        role="user",
        content=(
            "I have some questions about the weather data. "
            "You can assume the temperature is in Fahrenheit "
            "and the wind speed is in mph."
        )
    ),
    ChatMessage(
        role="assistant",
        content=(
            "I can help with that. "
            "What specific information are you looking for?"
        )
    ),
    ChatMessage(
        role="user",
        content=(
            "What's the average wind speed, the max wind speed, "
            "and the min wind speed?"
        )
    )
]

response = qa.ask(conversation)
```

**JavaScript/TypeScript (Agents)**

```ts
import { ChatMessage } from '@weaviate/agents';

const conversation: ChatMessage[] = [
    {
        role: "user",
        content: "Hi!"
    },
    {
        role: "assistant",
        content: "Hello! How can I assist you today?"
    },
    {
        role: "user",
        content: "I have some questions about the weather data. You can assume the temperature is in Fahrenheit and the wind speed is in mph.",
    },
    {
        role: "assistant",
        content: "I can help with that. What specific information are you looking for?",
    },
    {
        role: "user",
        content: "What's the average wind speed, the max wind speed, and the min wind speed",
    }
]

const response = await qa.ask(conversation)
```

Each message in the conversation must have a `role`, being either `"user"` or `"assistant"`, and `content`, being the text of the message.

The final message should be a user message, and it will be treated as the current user query to define the task.

### Example: Iterative message history

In a chat-style application, you typically want each new user message to build on top of everything said so far, rather than asking the agent in isolation. To do this, keep a running list of `ChatMessage` objects and append both the user's query and the agent's reply to it after every turn. Pass the full list back into `qa.ask()` on the next call so the agent has the complete context.

The example below wraps this pattern in a simple way.

**Python (Agents)**

```py
message_history: list[ChatMessage] = []

def use_qa(query: str) -> str:
    message_history.append(
        ChatMessage(role="user", content=query)
    )
    response = qa.ask(message_history)
    message_history.append(
        ChatMessage(role="assistant", content=response.final_answer)
    )
    return response.final_answer

use_qa(
    "I have some questions about the weather data. "
    "You can assume the temperature is in Fahrenheit "
    "and the wind speed is in mph."
)

use_qa(
    "What's the average wind speed, the max wind speed, "
    "and the min wind speed?"
)
```

**JavaScript/TypeScript (Agents)**

```ts
const messageHistory: ChatMessage[] = []

async function useQA(query: string): Promise<string> {
    messageHistory.push({ role: "user", content: query })
    const response = await qa.ask(messageHistory)
    messageHistory.push({ role: "assistant", content: response.finalAnswer })
    return response.finalAnswer
}

await useQA(
    "I have some questions about the weather data. " +
    "You can assume the temperature is in Fahrenheit " +
    "and the wind speed is in mph."
)

await useQA(
    "What's the average wind speed, the max wind speed, " +
    "and the min wind speed?"
)
```
