Module: LittleGhost::Agent::ContextManagement
- Included in:
- LittleGhost::Agent
- Defined in:
- lib/little_ghost/agent/context_management.rb
Overview
Keep long conversations within the model's available context window. The capability summarizes older turns while preserving trusted instructions and recent messages.
class CustomerSupportAgent < LittleGhost::Agent
manage_context compression_threshold: 0.75,
preserve_recent_messages: 12
end
As a support thread reaches the threshold, the next model request contains a generated summary and targets retaining its 12 most recent conversation messages. System and developer messages remain intact, and tool-use/result pairs are never split merely to hit the requested count.
Context management is inactive until manage_context is declared. The
configured window is a fallback: provider metadata takes precedence when
it advertises a positive context-window size. Compaction uses the current
model with the request's settings, cancellation token, and deadline.
Proactive compaction failures leave the original request unchanged and emit diagnostic instrumentation. A provider context-overflow error triggers one compaction replacement through the model-error callback; cancellation, deadlines, and cleanup failures still escape as control flow.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_CONTEXT_WINDOW_TOKENS =
:nodoc:
200_000- DEFAULT_COMPRESSION_THRESHOLD =
:nodoc:
0.85- DEFAULT_SUMMARY_RATIO =
:nodoc:
0.3- DEFAULT_PRESERVE_RECENT_MESSAGES =
:nodoc:
10- ESTIMATED_CHARS_PER_TOKEN =
:nodoc:
4- OUTPUT_LIMIT_STOP_REASONS =
:nodoc:
%i[max_tokens limit_output_tokens limit_total_tokens limit_turns].freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
38 39 40 41 |
# File 'lib/little_ghost/agent/context_management.rb', line 38 def self.included(base) # :nodoc: base.extend(ClassMethods) base.class_attribute :context_management_configuration_value end |