Skip to content

Filter 11: compact #30

Description

@leseb

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

No fields configured for Task.

Projects

Status
In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions