SessionSummarizer (sync) and AsyncSessionSummarizer (async) solve the context-window problem for long user sessions.
Instead of accumulating hundreds of raw actions that grow unboundedly, the summarizer condenses them into a compact prose paragraph every N actions β keeping your RAG context small and retrieval meaningful.
How it works
on_summary callback fires after each summarisation β wire it to your vector store, database, or RagPipeline.
Sync usage
Async usage
Custom prompt
By default the summarizer uses a built-in prompt optimised for RAG pipelines. You can override it with your own β just include{actions} as the placeholder:
Get partial context
Read whatβs been accumulated for a session before the threshold is reached:Composing with RagPipeline
The most common pattern β attach the summarizer to aRagPipeline so summaries are automatically embedded and upserted:
Constructor
SessionSummarizer(llm, threshold=10, prompt=None, on_summary=None)
Any synchronous LLM callable. Receives the formatted prompt and must return the summary as a plain string.
Number of individual actions (not batches) to accumulate before triggering summarisation.
A batch of 3 actions counts as 3 toward the threshold.
Custom prompt template. Must contain
{actions} as a placeholder. Uses the built-in default if not provided.Called after each summarisation with
(session_id, summary_text). Can also be set after construction by assigning to summarizer.on_summary.AsyncSessionSummarizer(llm, threshold=10, prompt=None, on_summary=None)
Same parameters but llm is async (prompt: str) -> str and on_summary can be sync or async.
API reference
| Method / Property | Description |
|---|---|
.add(payload) | Receive an actions batch β wire to on_actions |
.get_context(session_id) | Return accumulated (not-yet-summarised) actions as text |
.reset(session_id) | Clear a sessionβs history without summarising |
.active_sessions | List of session IDs with pending actions |
.on_summary | Assignable callback (session_id, summary) -> None |