> ## 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.

> ## Agent Instructions
> Maximem Synap is a managed memory layer for AI agents: it ingests conversations and documents, extracts structured memory, and returns scoped context to the agent at retrieval time.
> The Python and JavaScript/TypeScript SDKs are the supported way to use Synap. Write integration code with SDK calls, not raw HTTP requests.
> Start with the Quickstart: https://docs.maximem.ai/getting-started/quickstart.md. Every SDK method is documented in the SDK reference: https://docs.maximem.ai/sdk-reference/overview.md.
> For requests about adding Vity memory to OpenClaw, Hermes, an MCP client, or a browser, start with the Vity Quickstart: https://docs.maximem.ai/vity/quickstart.md.

# conversation.context.compact

> Trigger asynchronous compaction of a conversation into a compressed summary.

```python theme={null}
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`](https://docs.maximem.ai/sdk-reference/conversation-context/get-compaction-status) to poll for completion, then [`get_compacted`](https://docs.maximem.ai/sdk-reference/conversation-context/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. Must be a valid UUID [registered via `record_message`](https://docs.maximem.ai/concepts/context-end-to-end#short-term-context).

**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

```python Python theme={null}
import uuid
from maximem_synap import MaximemSynapSDK

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

# conversation_id must be a valid UUID; reuse the conversation's id
conversation_id = str(uuid.uuid4())

job = await sdk.conversation.context.compact(
    conversation_id=conversation_id,
    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.")
```

```javascript JavaScript theme={null}
import { randomUUID } from 'node:crypto';
import { SynapClient } from '@maximem/synap-js-sdk';

const sdk = new SynapClient({ apiKey: 'synap_your_key_here' });
await sdk.initialize();

// conversation_id must be a valid UUID; reuse the conversation's id
let conversation_id = randomUUID();

const job = await sdk.conversation.context.compact({
  conversation_id: conversation_id,
  strategy: 'balanced',
  target_tokens: 800,
});

console.log(`Compaction ${job.compaction_id} started (status: ${job.status})`);
if (job.previous_context) {
  console.log('Previous compacted context still usable while new run completes.');
}
```

```typescript TypeScript theme={null}
import { randomUUID } from 'node:crypto';
import { SynapClient } from '@maximem/synap-js-sdk';

const sdk = new SynapClient({ apiKey: 'synap_your_key_here' });
await sdk.initialize();

// conversation_id must be a valid UUID; reuse the conversation's id
let conversation_id = randomUUID();

const job = await sdk.conversation.context.compact({
  conversation_id: conversation_id,
  strategy: 'balanced',
  target_tokens: 800,
});

console.log(`Compaction ${job.compaction_id} started (status: ${job.status})`);
if (job.previous_context) {
  console.log('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

* [conversation.context.get\_compaction\_status](https://docs.maximem.ai/sdk-reference/conversation-context/get-compaction-status.md)
* [conversation.context.get\_compacted](https://docs.maximem.ai/sdk-reference/conversation-context/get-compacted.md)
* [conversation.context.get\_context\_for\_prompt](https://docs.maximem.ai/sdk-reference/conversation-context/get-context-for-prompt.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.