Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Groq Groq python Message Construction

From Leeroopedia
Knowledge Sources
Domains NLP, API_Design
Last Updated 2026-02-15 16:00 GMT

Overview

A structured message format for encoding multi-turn conversations between system instructions, users, and AI assistants in chat-based language model APIs.

Description

Message Construction is the process of building a structured list of messages that represents a conversation history. Each message in the list has a role (system, user, assistant, tool, or function) and content (text or multipart data). This format enables:

  • Multi-turn context: The model sees the full conversation history to generate contextually appropriate responses
  • System instructions: A system message sets the behavior and personality of the assistant
  • Tool integration: Tool and function messages allow the model to interact with external tools in agentic workflows
  • Multimodal content: Messages can contain text, images, or structured content parts

The message list is the primary input to all chat completion APIs and follows the OpenAI-compatible message format adopted by most LLM providers.

Usage

Use this principle whenever preparing input for a chat completion request. The message list must contain at least one user message. System messages are optional but recommended for controlling assistant behavior. Assistant and tool messages are used for multi-turn conversations and tool-use workflows.

Theoretical Basis

The chat message format follows a role-based dialogue protocol:

# Abstract message construction pattern
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris."},
    {"role": "user", "content": "What about Germany?"},
]
# Messages are processed sequentially; the model attends to the full context

Role hierarchy:

  • system — Sets global behavior constraints (processed first)
  • user — Human input (the query)
  • assistant — Model's previous responses (for multi-turn)
  • tool — Results from tool execution
  • function — Legacy function calling results (deprecated)

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment