Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions internal/config/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

const (
DefaultCompactManualKeepRecentMessages = 10
DefaultCompactMaxSummaryChars = 1200
DefaultAutoCompactInputTokenThreshold = 100000
DefaultCompactManualKeepRecentMessages = 10
DefaultCompactMaxSummaryChars = 1200
DefaultAutoCompactInputTokenThreshold = 100000
DefaultMicroCompactRetainedToolSpans = 2

CompactManualStrategyKeepRecent = "keep_recent"
CompactManualStrategyFullReplace = "full_replace"
Expand All @@ -21,10 +22,12 @@ type ContextConfig struct {
}

type CompactConfig struct {
ManualStrategy string `yaml:"manual_strategy,omitempty"`
ManualKeepRecentMessages int `yaml:"manual_keep_recent_messages,omitempty"`
MaxSummaryChars int `yaml:"max_summary_chars,omitempty"`
MicroCompactDisabled bool `yaml:"micro_compact_disabled,omitempty"`
ManualStrategy string `yaml:"manual_strategy,omitempty"`
ManualKeepRecentMessages int `yaml:"manual_keep_recent_messages,omitempty"`
MaxSummaryChars int `yaml:"max_summary_chars,omitempty"`
MicroCompactDisabled bool `yaml:"micro_compact_disabled,omitempty"`
MicroCompactRetainedToolSpans int `yaml:"micro_compact_retained_tool_spans,omitempty"`
MaxArchivedPromptChars int `yaml:"max_archived_prompt_chars,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompactConfig adds micro_compact_retained_tool_spans / max_archived_prompt_chars, but the YAML persistence mapping is not updated (persistedCompactConfig, newPersistedContextConfig, fromPersistedContextConfig in internal/config/loader.go). With KnownFields(true), users configuring these keys will hit unknown-field parse failures, and values also cannot round-trip through save/load.

Please wire both fields through loader read/write structs and add config load/save tests for these keys.

}

// AutoCompactConfig controls automatic context compression triggered by token thresholds.
Expand All @@ -50,9 +53,10 @@ func defaultAutoCompactConfig() AutoCompactConfig {
// defaultCompactConfig 返回手动 compact 策略的默认配置。
func defaultCompactConfig() CompactConfig {
return CompactConfig{
ManualStrategy: CompactManualStrategyKeepRecent,
ManualKeepRecentMessages: DefaultCompactManualKeepRecentMessages,
MaxSummaryChars: DefaultCompactMaxSummaryChars,
ManualStrategy: CompactManualStrategyKeepRecent,
ManualKeepRecentMessages: DefaultCompactManualKeepRecentMessages,
MaxSummaryChars: DefaultCompactMaxSummaryChars,
MicroCompactRetainedToolSpans: DefaultMicroCompactRetainedToolSpans,
}
}

Expand Down Expand Up @@ -99,6 +103,9 @@ func (c *CompactConfig) ApplyDefaults(defaults CompactConfig) {
if c.MaxSummaryChars <= 0 {
c.MaxSummaryChars = defaults.MaxSummaryChars
}
if c.MicroCompactRetainedToolSpans <= 0 {
c.MicroCompactRetainedToolSpans = defaults.MicroCompactRetainedToolSpans
}
}

// ApplyDefaults 为 auto_compact 配置填充缺省阈值。
Expand Down
62 changes: 35 additions & 27 deletions internal/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ type persistedContextConfig struct {
}

type persistedCompactConfig struct {
ManualStrategy string `yaml:"manual_strategy,omitempty"`
ManualKeepRecentMessages int `yaml:"manual_keep_recent_messages,omitempty"`
MaxSummaryChars int `yaml:"max_summary_chars,omitempty"`
MicroCompactDisabled bool `yaml:"micro_compact_disabled,omitempty"`
ManualStrategy string `yaml:"manual_strategy,omitempty"`
ManualKeepRecentMessages int `yaml:"manual_keep_recent_messages,omitempty"`
MaxSummaryChars int `yaml:"max_summary_chars,omitempty"`
MicroCompactDisabled bool `yaml:"micro_compact_disabled,omitempty"`
MicroCompactRetainedToolSpans int `yaml:"micro_compact_retained_tool_spans,omitempty"`
MaxArchivedPromptChars int `yaml:"max_archived_prompt_chars,omitempty"`
}

type persistedAutoCompactConfig struct {
Expand Down Expand Up @@ -237,10 +239,12 @@ func marshalPersistedConfig(snapshot Config) ([]byte, error) {
func newPersistedContextConfig(cfg ContextConfig) persistedContextConfig {
return persistedContextConfig{
Compact: persistedCompactConfig{
ManualStrategy: cfg.Compact.ManualStrategy,
ManualKeepRecentMessages: cfg.Compact.ManualKeepRecentMessages,
MaxSummaryChars: cfg.Compact.MaxSummaryChars,
MicroCompactDisabled: cfg.Compact.MicroCompactDisabled,
ManualStrategy: cfg.Compact.ManualStrategy,
ManualKeepRecentMessages: cfg.Compact.ManualKeepRecentMessages,
MaxSummaryChars: cfg.Compact.MaxSummaryChars,
MicroCompactDisabled: cfg.Compact.MicroCompactDisabled,
MicroCompactRetainedToolSpans: cfg.Compact.MicroCompactRetainedToolSpans,
MaxArchivedPromptChars: cfg.Compact.MaxArchivedPromptChars,
},
AutoCompact: persistedAutoCompactConfig{
Enabled: cfg.AutoCompact.Enabled,
Expand All @@ -253,10 +257,12 @@ func newPersistedContextConfig(cfg ContextConfig) persistedContextConfig {
func fromPersistedContextConfig(file persistedContextConfig, defaults ContextConfig) ContextConfig {
out := ContextConfig{
Compact: CompactConfig{
ManualStrategy: strings.TrimSpace(file.Compact.ManualStrategy),
ManualKeepRecentMessages: file.Compact.ManualKeepRecentMessages,
MaxSummaryChars: file.Compact.MaxSummaryChars,
MicroCompactDisabled: file.Compact.MicroCompactDisabled,
ManualStrategy: strings.TrimSpace(file.Compact.ManualStrategy),
ManualKeepRecentMessages: file.Compact.ManualKeepRecentMessages,
MaxSummaryChars: file.Compact.MaxSummaryChars,
MicroCompactDisabled: file.Compact.MicroCompactDisabled,
MicroCompactRetainedToolSpans: file.Compact.MicroCompactRetainedToolSpans,
MaxArchivedPromptChars: file.Compact.MaxArchivedPromptChars,
},
AutoCompact: AutoCompactConfig{
Enabled: file.AutoCompact.Enabled,
Expand Down Expand Up @@ -288,24 +294,26 @@ func assembleProviders(builtin []ProviderConfig, custom []ProviderConfig) ([]Pro
return nil
}

for _, provider := range builtin {
candidate := cloneProviderConfig(provider)
if candidate.Source == "" {
candidate.Source = ProviderSourceBuiltin
}
if err := appendProvider(candidate); err != nil {
return nil, err
}
sections := []struct {
providers []ProviderConfig
source ProviderSource
}{
{providers: builtin, source: ProviderSourceBuiltin},
{providers: custom, source: ProviderSourceCustom},
}
for _, provider := range custom {
candidate := cloneProviderConfig(provider)
if candidate.Source == "" {
candidate.Source = ProviderSourceCustom
}
if err := appendProvider(candidate); err != nil {
return nil, err

for _, section := range sections {
for _, provider := range section.providers {
candidate := cloneProviderConfig(provider)
if candidate.Source == "" {
candidate.Source = section.source
}
if err := appendProvider(candidate); err != nil {
return nil, err
}
}
}

return assembled, nil
}

Expand Down
Loading
Loading