Compact Conversation
Compact (summarize) a conversation’s message history.
This endpoint summarizes the in-context messages for a specific conversation, reducing the message count while preserving important context.
Agent-direct mode: Pass conversation_id=“default” with agent_id in request body to compact the agent’s default conversation messages.
Deprecated: Passing an agent ID as conversation_id still works but will be removed.
ParametersExpand Collapse
conversation_id: str
The conversation identifier. Can be a conversation ID (‘conv-
agent_id: Optional[str]
Agent ID for agent-direct mode with ‘default’ conversation. Use with conversation_id=‘default’ in the URL path.
Configuration for conversation compaction / summarization.
Per-model settings (temperature, max tokens, etc.) are derived from the default configuration for that handle.
clip_chars: Optional[int]
The maximum length of the summary in characters. If none, no clipping is performed.
model: Optional[str]
Model handle to use for sliding_window/all summarization (format: provider/model-name). If None, uses lightweight provider-specific defaults.
model_settings: Optional[CompactionSettingsModelSettings]
Optional model settings used to override defaults for the summarizer model.
class OpenAIModelSettings: …
response_format: Optional[ResponseFormat]
class CompactionSettingsModelSettingsSgLangModelSettings: …
SGLang model configuration (OpenAI-compatible runtime with SGLang-specific parsing).
response_format: Optional[CompactionSettingsModelSettingsSgLangModelSettingsResponseFormat]
class AnthropicModelSettings: …
response_format: Optional[ResponseFormat]
strict: Optional[bool]
Enable strict mode for tool calling. When true, tool outputs are guaranteed to match JSON schemas.
class GoogleAIModelSettings: …
class GoogleVertexModelSettings: …
class AzureModelSettings: …
class XaiModelSettings: …
class CompactionSettingsModelSettingsMoonshotModelSettings: …
Moonshot/Kimi model configuration (OpenAI-compatible).
response_format: Optional[CompactionSettingsModelSettingsMoonshotModelSettingsResponseFormat]
class CompactionSettingsModelSettingsZaiModelSettings: …
Z.ai (ZhipuAI) model configuration (OpenAI-compatible).
class CompactionSettingsModelSettingsMoonshotCodingModelSettings: …
Kimi Code model configuration (Anthropic-compatible).
response_format: Optional[CompactionSettingsModelSettingsMoonshotCodingModelSettingsResponseFormat]
strict: Optional[bool]
Enable strict mode for tool calling. When true, tool outputs are guaranteed to match JSON schemas.
class GroqModelSettings: …
class DeepseekModelSettings: …
class TogetherModelSettings: …
class BedrockModelSettings: …
class CompactionSettingsModelSettingsBasetenModelSettings: …
Baseten model configuration (OpenAI-compatible).
class CompactionSettingsModelSettingsOpenRouterModelSettings: …
Compact Conversation
import os
from letta_client import Letta
client = Letta(
api_key=os.environ.get("LETTA_API_KEY"), # This is the default and can be omitted
)
compaction_response = client.conversations.messages.compact(
conversation_id="default",
)
print(compaction_response.num_messages_after){
"num_messages_after": 0,
"num_messages_before": 0,
"summary": "summary"
}Returns Examples
{
"num_messages_after": 0,
"num_messages_before": 0,
"summary": "summary"
}
Skip to content