Documentation
¶
Index ¶
- Constants
- func CountMessages(messages []Message) int
- func EstimateTokens(text string) int
- func IsMaskedObservation(msg Message) bool
- type CompressionPolicy
- type InsertPosition
- type Manager
- type Message
- type NormalizeResult
- type Policy
- type Result
- type Role
- type RoleBudgets
- type Stats
- type Strategy
- type Summarizer
- type ToolOutputTransform
- type ToolResultClass
- type TransformMeta
Constants ¶
const ( TransformStrategyIntegrator = "integrator" TransformStrategyJSONAware = "json_aware" TransformStrategyByteCut = "byte_cut" TransformStrategyNone = "none" )
Variables ¶
This section is empty.
Functions ¶
func CountMessages ¶
func EstimateTokens ¶
func IsMaskedObservation ¶ added in v0.4.2
IsMaskedObservation reports whether a message content was replaced by MaskObservations.
Types ¶
type CompressionPolicy ¶
type InsertPosition ¶ added in v0.3.0
type InsertPosition string
InsertPosition controls where reinjected context sits after compaction.
const ( // InsertBeforeLastUserMessage places content above the last user message // (and below any trailing summary/system blocks that precede it). Matches // Codex InitialContextInjection::BeforeLastUserMessage so the model sees // reinjected world/plan context before the latest user turn. InsertBeforeLastUserMessage InsertPosition = "before_last_user_message" // InsertAppend appends at the end (legacy compact_reminder behavior). InsertAppend InsertPosition = "append" )
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewWithSummarizer ¶ added in v0.1.4
func NewWithSummarizer(policy Policy, summarizer Summarizer) *Manager
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content,omitempty"`
Name string `json:"name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
// ToolCallIDs lists tool_call ids issued by an assistant turn. Used for
// tool-pair-safe trimming (assistant + matching tool results stay atomic).
ToolCallIDs []string `json:"tool_call_ids,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
func CompactContext ¶ added in v0.4.2
CompactContext drops tool messages whose content was masked by MaskObservations, preserving all other messages in order.
func InsertMessage ¶ added in v0.3.0
func InsertMessage(messages []Message, msg Message, position InsertPosition) []Message
InsertMessage inserts msg into messages according to position. For BeforeLastUserMessage: finds the last RoleUser and inserts immediately before it; if none, appends.
func MaskObservations ¶ added in v0.4.2
MaskObservations replaces tool-role messages older than afterTurns assistant turns (counting from the latest message backward) with a short placeholder.
type NormalizeResult ¶ added in v0.3.0
type NormalizeResult struct {
Policy Policy
PolicySource string // profile | context_policy | default_8192
Fallback8192 bool
}
NormalizeResult carries a normalized policy plus how MaxInputTokens was derived.
type Policy ¶
type Policy struct {
Strategy Strategy `json:"strategy,omitempty" yaml:"strategy,omitempty"`
ContextWindowTokens int `json:"context_window_tokens,omitempty" yaml:"context_window_tokens,omitempty"`
MaxInputTokens int `json:"max_input_tokens,omitempty" yaml:"max_input_tokens,omitempty"`
ReservedOutputTokens int `json:"reserved_output_tokens,omitempty" yaml:"reserved_output_tokens,omitempty"`
SummaryTokens int `json:"summary_tokens,omitempty" yaml:"summary_tokens,omitempty"`
ToolResultMaxTokens int `json:"tool_result_max_tokens,omitempty" yaml:"tool_result_max_tokens,omitempty"`
// ToolOutputMaxBytes caps tool message bytes written to session memory.
// Zero disables the write-side byte cap (LLM-side ToolResultMaxTokens still applies).
ToolOutputMaxBytes int `json:"tool_output_max_bytes,omitempty" yaml:"tool_output_max_bytes,omitempty"`
MemoryRecallLimit int `json:"memory_recall_limit,omitempty" yaml:"memory_recall_limit,omitempty"`
SystemPromptProtection bool `json:"system_prompt_protection,omitempty" yaml:"system_prompt_protection,omitempty"`
Compression CompressionPolicy `json:"compression,omitempty" yaml:"compression,omitempty"`
RoleBudgets RoleBudgets `json:"role_budgets,omitempty" yaml:"role_budgets,omitempty"`
SummaryMode string `json:"summary_mode,omitempty" yaml:"summary_mode,omitempty"`
ToolSchemaPruning bool `json:"tool_schema_pruning,omitempty" yaml:"tool_schema_pruning,omitempty"`
StaleToolTurns int `json:"stale_tool_turns,omitempty" yaml:"stale_tool_turns,omitempty"`
// ExcludeFromStaleWindow lists tool result classes that do not consume a
// StaleToolTurns slot. When nil, denied and empty are excluded by default.
ExcludeFromStaleWindow []ToolResultClass `json:"exclude_from_stale_window,omitempty" yaml:"exclude_from_stale_window,omitempty"`
PinUserMessages *bool `json:"pin_user_messages,omitempty" yaml:"pin_user_messages,omitempty"`
// MemoryStoreLimit caps how many messages are retained in the persistent
// flat memory store. When exceeded, the oldest messages are dropped on
// write (keeping the most recent MemoryStoreLimit). Zero (the default)
// disables the write-side cap, preserving unbounded append behavior.
MemoryStoreLimit int `json:"memory_store_limit,omitempty" yaml:"memory_store_limit,omitempty"`
// StripAssistantPatterns is an optional list of substrings; when non-empty,
// matching assistant messages may be stripped on memory write by integrators
// that opt in. The framework does not strip by default.
StripAssistantPatterns []string `json:"strip_assistant_patterns,omitempty" yaml:"strip_assistant_patterns,omitempty"`
// InjectCompactReminder asks the runtime to reinject a system reminder with
// active plan/TODO state after compaction drops or summarizes history.
// Placement is before the last user message (see InsertBeforeLastUserMessage).
InjectCompactReminder bool `json:"inject_compact_reminder,omitempty" yaml:"inject_compact_reminder,omitempty"`
// ObservationMaskAfterTurns replaces tool-role messages older than this many
// assistant turns with a short placeholder before summarization/truncation.
ObservationMaskAfterTurns int `json:"observation_mask_after_turns,omitempty" yaml:"observation_mask_after_turns,omitempty"`
}
func (Policy) ExcludeFromStaleWindowOrDefault ¶ added in v0.3.0
func (p Policy) ExcludeFromStaleWindowOrDefault() []ToolResultClass
ExcludeFromStaleWindowOrDefault returns configured exclusions, or denied+empty.
func (Policy) NormalizeDetailed ¶ added in v0.3.0
func (p Policy) NormalizeDetailed() NormalizeResult
func (Policy) PinUserMessagesEnabled ¶ added in v0.3.0
PinUserMessagesEnabled reports whether user messages should be retained during context-window truncation. When nil, user pinning defaults to true.
type RoleBudgets ¶ added in v0.1.4
type Stats ¶
type Stats struct {
Strategy Strategy `json:"strategy"`
BeforeTokens int `json:"before_tokens"`
AfterTokens int `json:"after_tokens"`
MaxInputTokens int `json:"max_input_tokens"`
DroppedMessages int `json:"dropped_messages"`
DroppedUserMessages int `json:"dropped_user_messages,omitempty"`
DroppedAssistantMessages int `json:"dropped_assistant_messages,omitempty"`
DroppedToolMessages int `json:"dropped_tool_messages,omitempty"`
ContextIncomplete bool `json:"context_incomplete,omitempty"`
Summarized bool `json:"summarized"`
SummaryTokens int `json:"summary_tokens,omitempty"`
PolicySource string `json:"policy_source,omitempty"`
FallbackApplied bool `json:"fallback_applied,omitempty"`
StaleDroppedToolTurns int `json:"stale_dropped_tool_turns,omitempty"`
DenialOccupiedSlots int `json:"denial_occupied_slots,omitempty"`
StaleExcludedTurns int `json:"stale_excluded_turns,omitempty"`
CompactedToolDenials int `json:"compacted_tool_denials,omitempty"`
// NeedsReminder is true when compaction dropped or summarized history and
// hosts should re-inject active plan/TODO state.
NeedsReminder bool `json:"needs_reminder,omitempty"`
}
type Strategy ¶
type Strategy string
const ( StrategyNone Strategy = "none" StrategySlidingWindow Strategy = "sliding_window" StrategySlidingWindowWithSummary Strategy = "sliding_window_with_summary" // StrategyFullReplace summarizes everything outside a recent tail into one // system summary, then keeps the tool-pair-safe recent tail. StrategyFullReplace Strategy = "full_replace" )
type Summarizer ¶ added in v0.1.4
type ToolOutputTransform ¶ added in v0.3.0
type ToolOutputTransform func(tool string, raw []byte, limit int) (out []byte, meta TransformMeta)
ToolOutputTransform reshapes a tool's raw output to fit a byte/token budget. limit is a token budget (same units as ToolResultMaxTokens); implementations may convert via rune heuristics.
type ToolResultClass ¶ added in v0.3.0
type ToolResultClass string
ToolResultClass classifies tool messages for stale-window accounting.
const ( ToolResultClassSuccess ToolResultClass = "success" ToolResultClassDenied ToolResultClass = "denied" ToolResultClassEmpty ToolResultClass = "empty" )
type TransformMeta ¶ added in v0.3.0
type TransformMeta struct {
Truncated bool `json:"truncated"`
OriginalBytes int `json:"original_bytes"`
TruncatedBytes int `json:"truncated_bytes"`
Strategy string `json:"strategy"` // integrator | json_aware | byte_cut | none
}
TransformMeta describes how a tool output was reshaped before LLM/memory use.
func ApplyToolOutputTransform ¶ added in v0.3.0
func ApplyToolOutputTransform(tool string, raw []byte, limit int, transforms map[string]ToolOutputTransform) ([]byte, TransformMeta)
ApplyToolOutputTransform applies a per-tool integrator transform when present, otherwise JSON-aware truncation for JSON payloads, otherwise byte truncation. When limit <= 0 the input is returned unchanged.
func ByteTruncate ¶ added in v0.3.0
func ByteTruncate(raw []byte, limit int) ([]byte, TransformMeta)
ByteTruncate cuts raw bytes on a rune boundary and marks truncation. The cut point is chosen against EstimateTokens (not a fixed runes-per-token ratio) so CJK-heavy payloads honor the same budget as Latin text.
func JSONAwareTruncate ¶ added in v0.3.0
func JSONAwareTruncate(raw []byte, limit int) ([]byte, TransformMeta)
JSONAwareTruncate shortens JSON while keeping it parseable: top-level object keys are preserved; long strings and array elements are trimmed.