Use chat-style prompts with generateText to build conversational AI with
system instructions and message history.
Overview
While simple prompts work for basic tasks, chat prompts unlock powerful features: system instructions to define AI behavior, conversation history for context-aware responses, and multi-turn interactions where the AI remembers previous exchanges.
Demo
Try a multi-turn conversation. Say your name, then ask "What's my name?" - the AI remembers!
Server Endpoint
The server accepts a messages array containing the full conversation
history. Using ModelMessage[] type ensures proper structure.
Client Component
The client maintains local message state and sends the complete history with each request. This lets the AI maintain context across turns.
Key Concepts
ModelMessage Type
Each message has a role (user/assistant/system) and content. This structure enables multi-turn conversations.
System Message
Use the system parameter to set persistent instructions. This
shapes the AI's personality and response style.
Conversation History
Send all previous messages with each request. The AI uses this context to give relevant, coherent responses.