Documentation
¶
Index ¶
- func AutoCompactThresholdRatio() float64
- func AutoCompactThresholdTokens(maxTokens int) int
- func EstimateTokens(text string) int
- type ContextManager
- type Manager
- func (m *Manager) Add(msg provider.Message)
- func (m *Manager) AutoCompactThreshold() int
- func (m *Manager) CheckAndSummarize(ctx context.Context, prov provider.Provider) (bool, error)
- func (m *Manager) Clear()
- func (m *Manager) MaxTokens() int
- func (m *Manager) Messages() []provider.Message
- func (m *Manager) Microcompact() bool
- func (m *Manager) RecordUsage(usage provider.TokenUsage)
- func (m *Manager) SetMaxTokens(n int)
- func (m *Manager) SetOutputReserve(n int)
- func (m *Manager) SetProvider(p provider.Provider)
- func (m *Manager) SetTodoFilePath(path string)
- func (m *Manager) Summarize(ctx context.Context, prov provider.Provider) error
- func (m *Manager) TokenCount() int
- func (m *Manager) TruncateOldestGroupForRetry() bool
- func (m *Manager) UsageRatio() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoCompactThresholdRatio ¶
func AutoCompactThresholdRatio() float64
func EstimateTokens ¶
EstimateTokens provides a more accurate token estimation than simple len/4. It distinguishes ASCII characters (~0.25 token/char) from CJK characters (~0.5 token/char).
Types ¶
type ContextManager ¶
type ContextManager interface {
Add(msg provider.Message)
Messages() []provider.Message
TokenCount() int
MaxTokens() int
SetMaxTokens(n int)
SetOutputReserve(n int)
RecordUsage(usage provider.TokenUsage)
Summarize(ctx context.Context, prov provider.Provider) error
CheckAndSummarize(ctx context.Context, prov provider.Provider) (bool, error)
TruncateOldestGroupForRetry() bool
Clear()
UsageRatio() float64
AutoCompactThreshold() int
}
ContextManager manages conversation history, tracking tokens and auto-summarizing.
⚠️ Consuming packages must import this as "ctxpkg" to avoid collision with the standard library "context" package.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager implements ContextManager.
func NewManager ¶
NewManager creates a ContextManager with the given context window limit.
func (*Manager) AutoCompactThreshold ¶ added in v1.1.17
func (*Manager) CheckAndSummarize ¶
CheckAndSummarize triggers summarization if usage ratio >= threshold.
func (*Manager) Microcompact ¶
Microcompact reduces old bulky tool results in-place before falling back to full summarization.
func (*Manager) RecordUsage ¶ added in v1.1.17
func (m *Manager) RecordUsage(usage provider.TokenUsage)
func (*Manager) SetMaxTokens ¶
func (*Manager) SetOutputReserve ¶ added in v1.1.17
func (*Manager) SetProvider ¶
SetProvider sets the provider for provider-aware token counting.
func (*Manager) SetTodoFilePath ¶ added in v1.1.7
func (*Manager) Summarize ¶
Summarize compresses old messages into a summary while retaining an adaptive recent suffix sized to fit within the target token budget.