Module: LittleGhost::Agent::ContextManagement::ClassMethods
- Defined in:
- lib/little_ghost/agent/context_management.rb
Overview
Exposes context-management declarations on agent classes. These methods become inheritable DSL entries when the capability is included.
Instance Method Summary collapse
-
#context_management_configuration ⇒ Object
:nodoc:.
-
#manage_context(context_window_tokens: DEFAULT_CONTEXT_WINDOW_TOKENS, compression_threshold: DEFAULT_COMPRESSION_THRESHOLD, summary_ratio: DEFAULT_SUMMARY_RATIO, preserve_recent_messages: DEFAULT_PRESERVE_RECENT_MESSAGES) ⇒ Object
Enables automatic context compaction for the agent class.
Instance Method Details
#context_management_configuration ⇒ Object
:nodoc:
94 |
# File 'lib/little_ghost/agent/context_management.rb', line 94 def context_management_configuration = context_management_configuration_value # :nodoc: |
#manage_context(context_window_tokens: DEFAULT_CONTEXT_WINDOW_TOKENS, compression_threshold: DEFAULT_COMPRESSION_THRESHOLD, summary_ratio: DEFAULT_SUMMARY_RATIO, preserve_recent_messages: DEFAULT_PRESERVE_RECENT_MESSAGES) ⇒ Object
Enables automatic context compaction for the agent class.
The defaults assume a 200,000-token window, compact at 85% usage,
summarize about 30% of conversation messages, and preserve the 10 most
recent messages. The model's declared context window takes precedence
over context_window_tokens when available.
Invalid ranges raise ArgumentError when the agent class is defined.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/little_ghost/agent/context_management.rb', line 65 def manage_context( context_window_tokens: DEFAULT_CONTEXT_WINDOW_TOKENS, compression_threshold: DEFAULT_COMPRESSION_THRESHOLD, summary_ratio: DEFAULT_SUMMARY_RATIO, preserve_recent_messages: DEFAULT_PRESERVE_RECENT_MESSAGES ) context_window_tokens = Integer(context_window_tokens) compression_threshold = Float(compression_threshold) summary_ratio = Float(summary_ratio) = Integer() raise ArgumentError, "context_window_tokens must be positive" unless context_window_tokens.positive? unless compression_threshold.positive? && compression_threshold <= 1 raise ArgumentError, "compression_threshold must be between 0 and 1" end unless summary_ratio.between?(0.1, 0.8) raise ArgumentError, "summary_ratio must be between 0.1 and 0.8" end raise ArgumentError, "preserve_recent_messages must be at least 2" if < 2 self.context_management_configuration_value = { context_window_tokens:, compression_threshold:, summary_ratio:, preserve_recent_messages: } before_model :compact_model_context after_model_error :compact_context_after_overflow end |