Purpose
Token counting and context window management. Summarize conversation history when threshold is exceeded.
Behavior
- Check
context_management parameter for compaction config
- Count tokens via provider usage (from
previous_usage) or tiktoken estimate
- If token count > threshold:
- Build summarization prompt from conversation messages
- Prepend
instructions to summarization prompt
- Call inference API with configured
compaction_model
- Extract summary text
- Apply
summary_prefix if configured
- Create
OpenAIResponseCompaction item with summary as encrypted_content
- Replace conversation history with compaction item + preserved user messages
- Store compaction response in response store (hidden, usable as
previous_response_id)
- Hide compaction items from
input_items API response
- Update
responses.messages with compacted messages
- Also handles explicit
POST /v1/responses/compact requests
Config
filter: compact
default_model: gpt-4o-mini # model for summarization
tiktoken_encoding: cl100k_base
Praxis trait methods
on_request — check token count, compact if needed
Dependencies
- Inference backend (for summarization)
- Response store
Reference
Purpose
Token counting and context window management. Summarize conversation history when threshold is exceeded.
Behavior
context_managementparameter for compaction configprevious_usage) or tiktoken estimateinstructionsto summarization promptcompaction_modelsummary_prefixif configuredOpenAIResponseCompactionitem with summary asencrypted_contentprevious_response_id)input_itemsAPI responseresponses.messageswith compacted messagesPOST /v1/responses/compactrequestsConfig
Praxis trait methods
on_request— check token count, compact if neededDependencies
Reference