Principle:Googleapis Python genai Message Exchange
| Knowledge Sources | |
|---|---|
| Domains | NLP, Conversational_AI |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
The core conversational operation of sending a user message within a chat session and receiving a model response with automatic history accumulation.
Description
Message Exchange is the turn-by-turn interaction within a chat session. Each exchange sends a user message (text, parts, or multimodal content), the SDK appends it to the session history, calls the underlying generation API with the full history, receives the model's response, appends it to history, and returns the response. Both unary (complete response) and streaming (incremental chunks) modes are supported. Per-message configuration overrides allow varying parameters (temperature, tools) between turns.
Usage
Use send_message for standard request-response turns within a chat session. Use send_message_stream for real-time response delivery. Pass config to override session-level settings for specific turns (e.g., higher temperature for creative responses, additional tools for specific queries).
Theoretical Basis
Message exchange within a session follows the Context Window model:
# Each message exchange includes growing history
# Turn N: history = [user_1, model_1, ..., user_N]
# The model sees all prior context to generate model_N
response_N = model.generate(
contents=[user_1, model_1, ..., user_N],
config=session_config
)
The key constraint is the model's context window size — the maximum number of tokens that can be included in a single generation call. As conversation grows, older turns may need to be truncated or summarized.