feat: harden jsonl runtime reliability

This commit is contained in:
lpf
2026-04-13 13:41:01 +08:00
parent 36890c7ce0
commit fac235db80
34 changed files with 4370 additions and 757 deletions

View File

@@ -106,15 +106,16 @@ type SubagentToolsConfig struct {
}
type SubagentRuntimeConfig struct {
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TimeoutSec int `json:"timeout_sec,omitempty"`
MaxRetries int `json:"max_retries,omitempty"`
RetryBackoffMs int `json:"retry_backoff_ms,omitempty"`
MaxTaskChars int `json:"max_task_chars,omitempty"`
MaxResultChars int `json:"max_result_chars,omitempty"`
MaxParallelRuns int `json:"max_parallel_runs,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TimeoutSec int `json:"timeout_sec,omitempty"`
MaxRetries int `json:"max_retries,omitempty"`
RetryBackoffMs int `json:"retry_backoff_ms,omitempty"`
MaxTaskChars int `json:"max_task_chars,omitempty"`
MaxResultChars int `json:"max_result_chars,omitempty"`
MaxParallelRuns int `json:"max_parallel_runs,omitempty"`
MaxToolIterations int `json:"max_tool_iterations,omitempty"`
}
type AgentDefaults struct {
@@ -158,12 +159,15 @@ type SystemSummaryPolicyConfig struct {
}
type ContextCompactionConfig struct {
Enabled bool `json:"enabled" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_ENABLED"`
Mode string `json:"mode" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_MODE"`
TriggerMessages int `json:"trigger_messages" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_TRIGGER_MESSAGES"`
KeepRecentMessages int `json:"keep_recent_messages" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_KEEP_RECENT_MESSAGES"`
MaxSummaryChars int `json:"max_summary_chars" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_MAX_SUMMARY_CHARS"`
MaxTranscriptChars int `json:"max_transcript_chars" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_MAX_TRANSCRIPT_CHARS"`
Enabled bool `json:"enabled" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_ENABLED"`
Mode string `json:"mode" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_MODE"`
TriggerMessages int `json:"trigger_messages" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_TRIGGER_MESSAGES"`
KeepRecentMessages int `json:"keep_recent_messages" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_KEEP_RECENT_MESSAGES"`
TargetRatio float64 `json:"target_ratio" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_TARGET_RATIO"`
ProtectLastN int `json:"protect_last_n" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_PROTECT_LAST_N"`
PressureThreshold float64 `json:"pressure_threshold" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_PRESSURE_THRESHOLD"`
MaxSummaryChars int `json:"max_summary_chars" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_MAX_SUMMARY_CHARS"`
MaxTranscriptChars int `json:"max_transcript_chars" env:"CLAWGO_AGENTS_DEFAULTS_CONTEXT_COMPACTION_MAX_TRANSCRIPT_CHARS"`
}
type ChannelsConfig struct {
@@ -402,6 +406,9 @@ func DefaultConfig() *Config {
Mode: "summary",
TriggerMessages: 60,
KeepRecentMessages: 20,
TargetRatio: 0.35,
ProtectLastN: 12,
PressureThreshold: 0.8,
MaxSummaryChars: 6000,
MaxTranscriptChars: 20000,
},

View File

@@ -76,6 +76,15 @@ func Validate(cfg *Config) []error {
if cc.KeepRecentMessages <= 0 {
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.keep_recent_messages must be > 0 when enabled=true"))
}
if cc.TargetRatio <= 0 || cc.TargetRatio >= 1 {
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.target_ratio must be > 0 and < 1 when enabled=true"))
}
if cc.ProtectLastN <= 0 {
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.protect_last_n must be > 0 when enabled=true"))
}
if cc.PressureThreshold <= 0 || cc.PressureThreshold > 1 {
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.pressure_threshold must be > 0 and <= 1 when enabled=true"))
}
if cc.TriggerMessages > 0 && cc.KeepRecentMessages >= cc.TriggerMessages {
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.keep_recent_messages must be < trigger_messages"))
}
@@ -395,6 +404,9 @@ func validateSubagents(cfg *Config) []error {
if raw.Runtime.MaxParallelRuns < 0 {
errs = append(errs, fmt.Errorf("agents.subagents.%s.runtime.max_parallel_runs must be >= 0", id))
}
if raw.Runtime.MaxToolIterations < 0 {
errs = append(errs, fmt.Errorf("agents.subagents.%s.runtime.max_tool_iterations must be >= 0", id))
}
if raw.Tools.MaxParallelCalls < 0 {
errs = append(errs, fmt.Errorf("agents.subagents.%s.tools.max_parallel_calls must be >= 0", id))
}