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.get_context_for_prompt(
    conversation_id: str,
    style: str = "structured",
) -> ContextForPromptResponse
Returns a single formatted_context string that stitches together the compacted history with any messages that arrived after the last compaction cutoff. Drop the result straight into your prompt — no further assembly required. If no compaction has run yet, every recorded message comes back as a recent message, so this method is useful from the very first turn.

Parameters

conversation_id
str
required
The conversation to assemble context for.
style
str
default:"structured"
Formatting style for the compacted portion:
  • "structured" — labelled sections (facts, decisions, preferences, current state)
  • "narrative" — prose summary
  • "bullet_points" — bulleted list

Returns

A ContextForPromptResponse ready for prompt injection.
formatted_context
str | None
The combined compacted + recent context, formatted per style. Inject directly into your LLM prompt.
available
bool
Whether usable context (compacted or recent) was found.
is_stale
bool
Whether the compacted portion is stale relative to newer messages.
compression_ratio
float | None
Compression ratio of the compacted portion.
validation_score
float | None
Quality validation score of the compacted portion.
compaction_age_seconds
int | None
How long ago the compaction completed.
quality_warning
bool
True when the compacted portion was flagged for quality concerns.
recent_messages
List[Dict[str, Any]]
Raw un-compacted messages since the last compaction. Use if you want to format them yourself.
recent_message_count
int
Number of un-compacted messages included.
compacted_message_count
int
Number of messages covered by the compacted portion.
total_message_count
int
Total messages in the conversation.

Example

from maximem_synap import MaximemSynapSDK

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

ctx = await sdk.conversation.context.get_context_for_prompt(
    conversation_id="conv_2026_05_16_alice",
    style="structured",
)

system_prompt = f"""You are a helpful assistant.

Conversation context so far:
{ctx.formatted_context or "(no prior context)"}
"""

print(system_prompt)
print(f"Covered {ctx.compacted_message_count} compacted + {ctx.recent_message_count} recent messages.")

Raises

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

See also