Multi-turn Conversation
Maintain context across conversations so AI agents generate more relevant and continuous responses.
Overview
Multi-turn conversations allow your agent to remember previous exchanges, enabling more natural, context-aware interactions. This is essential for building chatbots, assistants, and any application requiring back-and-forth dialogue.
Basic Example
Pass conversation history via the messages array:
Building Chat History
Here's a pattern for maintaining an ongoing conversation:
Message Roles
Mosaic supports three message roles:
system
Sets the behavior and personality of the assistant. Usually the first message in the conversation.
user
Represents messages from the user or the application requesting a response.
assistant
Represents previous responses from the AI. Include these to maintain context.
Managing Context Length
Warning