Module: Anthropic::Helpers::Tools::CompactionControl
- Defined in:
- lib/anthropic/helpers/tools/compaction_control.rb
Overview
Configuration for automatic conversation history compaction in tool runners.
When the cumulative token count (input + output) across all messages exceeds the threshold, the message history will be automatically summarized and compressed.
By default, a warning is printed to STDERR the first time compaction occurs for each runner instance. To silence the warning, provide an ‘on_compact` callback - when present, the warning is suppressed and you handle compaction events your way.
Instance Attribute Summary collapse
-
#context_token_threshold ⇒ Integer?
The cumulative token count threshold at which to trigger compaction.
-
#enabled ⇒ Boolean
Whether to enable automatic compaction.
-
#model ⇒ String, ...
The model to use for generating the compaction summary.
-
#on_compact ⇒ Proc?
Optional callback invoked when compaction occurs.
-
#summary_prompt ⇒ String?
The prompt used to instruct the model on how to generate the summary.
Instance Attribute Details
#context_token_threshold ⇒ Integer?
Returns The cumulative token count threshold at which to trigger compaction. When the total of input tokens (including cache tokens) and output tokens exceeds this value, compaction will occur. Defaults to 100,000 tokens.
102 |
# File 'lib/anthropic/helpers/tools/compaction_control.rb', line 102 module CompactionControl; end |
#enabled ⇒ Boolean
Returns Whether to enable automatic compaction. Required.
102 |
# File 'lib/anthropic/helpers/tools/compaction_control.rb', line 102 module CompactionControl; end |
#model ⇒ String, ...
Returns The model to use for generating the compaction summary. If not specified, defaults to the same model used for the tool runner.
102 |
# File 'lib/anthropic/helpers/tools/compaction_control.rb', line 102 module CompactionControl; end |
#on_compact ⇒ Proc?
Returns Optional callback invoked when compaction occurs. Receives two arguments: tokens_before (Integer) and tokens_after (Integer). Use this to log, monitor, or track compaction events. When provided, the default warning to STDERR is suppressed (you’re handling it yourself).
102 |
# File 'lib/anthropic/helpers/tools/compaction_control.rb', line 102 module CompactionControl; end |
#summary_prompt ⇒ String?
Returns The prompt used to instruct the model on how to generate the summary. If not specified, uses DEFAULT_SUMMARY_PROMPT.
102 |
# File 'lib/anthropic/helpers/tools/compaction_control.rb', line 102 module CompactionControl; end |