Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.maximem.ai/llms.txt

Use this file to discover all available pages before exploring further.

await sdk.conversation.context.compact(
    conversation_id: str,
    strategy: Optional[str] = None,
    compaction_level: Optional[str] = None,
    target_tokens: Optional[int] = None,
    force: bool = False,
) -> CompactionTriggerResponse
Kicks off compaction for a conversation. Compaction runs asynchronously — this call returns a handle with a compaction_id and an in_progress status. Use get_compaction_status to poll for completion, then get_compacted to retrieve the resulting summary. If a previous compacted summary already exists, it is returned on the trigger response as previous_context so you have something usable while the new compaction runs.

Parameters

conversation_id
str
required
The conversation to compact.
strategy
str
Override the compaction strategy. One of:
  • "aggressive" — maximum compression, shortest output
  • "balanced" — middle-ground compression
  • "conservative" — preserve more detail
  • "adaptive" — let Synap pick based on conversation shape
compaction_level
str
Backward-compatible alias for strategy. Prefer strategy in new code.
target_tokens
int
Override the target token budget for the compacted output.
force
bool
default:"False"
Compact even if the conversation has not crossed the automatic threshold.

Returns

A CompactionTriggerResponse describing the in-flight job.
compaction_id
str
Identifier for this compaction run.
conversation_id
str
Echo of the supplied conversation id.
status
str
Initial status, typically "in_progress".
trigger_type
str
How compaction was triggered (e.g., "manual_api").
initiated_at
datetime
When the run started.
estimated_completion_seconds
int
Rough ETA in seconds.
previous_context
Dict[str, Any] | None
Previously compacted context, if any. Usable while the new run finishes.
previous_context_age_seconds
int | None
Age of previous_context in seconds.
previous_compaction_id
str | None
Identifier of the previous compaction run.

Example

from maximem_synap import MaximemSynapSDK

sdk = MaximemSynapSDK(api_key="synap_your_key_here")
await sdk.initialize()

job = await sdk.conversation.context.compact(
    conversation_id="conv_2026_05_16_alice",
    strategy="balanced",
    target_tokens=800,
)

print(f"Compaction {job.compaction_id} started (status: {job.status})")
if job.previous_context:
    print("Previous compacted context still usable while new run completes.")

Raises

  • AuthenticationError — when the API key is missing or invalid.
  • NetworkError — when the SDK cannot reach Synap.

See also