Skip to main content
Bot platform adapters now ship in the praisonai-bot package. praisonai bot serve still works exactly as documented here; for a standalone install see praisonai-bot Migration.
Long-lived bot conversations get a compact summary of older turns instead of having them silently dropped.
This is the bot-side runtime context compactor. For the store-side, on-disk retention model (session-persistence retention policies), see Session Persistence — Retention Policies.
The user continues a long-lived bot thread; older turns are summarised instead of being dropped silently.

Quick Start

1

Enable with one line

2

Tune the budget


Agent-Centric Example


How It Works

Compaction runs at save time. When history exceeds the budget, the manager summarises older turns into a single system message, appends the most-recent verbatim tail, and persists the compacted form. Bot restarts preserve the same memory.
The manager builds a fresh ContextCompactor per save call rather than sharing one instance. This prevents per-conversation summary state from leaking between users under concurrent saves.

Choosing a Strategy


Configuration Options

Configure under session.compaction inside any channel block in gateway.yaml or bot.yaml.

User Interaction Flow

A 3-week-old Telegram support bot conversation. Messages 1–400 covered the customer’s account setup, billing decisions, and ongoing tickets. Message #500 arrives. Without compaction: the bot loads the most recent 100 messages and has no memory of the original setup — the customer has to re-explain everything. With compaction: the bot loads a one-line summary of decisions/facts from messages 1–490 followed by the last 10 verbatim turns. The agent answers the new question with full historical context. The compacted form is also persisted, so a bot restart preserves the memory.

Best Practices

Reset clears context on idle or daily schedule. Compaction keeps context across long sessions. max_history × 4 is the hard cap in compaction mode — history cannot grow past that ceiling even if the token threshold has not tripped yet. Use all three together for production bots.
enabled: true alone is enough for most bots. The defaults (strategy: summarize, max_messages: 100, keep_recent: 10) work well out of the box.
When the most recent turns carry the context that matters — a multi-step purchase flow or live escalation — increase keep_recent so more verbatim turns survive the compaction cycle.
The manager builds a fresh compactor per save call, so per-conversation summary state never leaks between users sharing the same bot instance. This is safe for concurrent, high-traffic bots.

Bot Session Reset

Clear history on idle or daily schedule

Session Persistence

How bot sessions are stored and restored

Messaging Bots

Multi-platform bot setup and YAML config

Context Compaction

Agent-level context compaction (core ContextCompactor API)