refactor: default-enable session planning and scheduling without config flags

This commit is contained in:
lpf
2026-03-04 12:49:43 +08:00
parent 154ab3f7f9
commit a7dcafae60
7 changed files with 27 additions and 79 deletions

View File

@@ -69,10 +69,6 @@
"run_state_max": 500,
"tool_parallel_safe_names": ["read_file", "list_files", "find_files", "grep_files", "memory_search", "web_search", "repo_map", "system_info"],
"tool_max_parallel_calls": 2,
"session_resource_scheduling_enabled": true,
"session_max_parallel_runs": 4,
"session_auto_plan_enabled": true,
"session_auto_plan_max_tasks": 4,
"system_summary": {
"marker": "## System Task Summary",
"completed_prefix": "- Completed:",

View File

@@ -54,8 +54,6 @@ type AgentLoop struct {
runtimeCompactionNote string
startupCompactionNote string
systemRewriteTemplate string
sessionAutoPlan bool
sessionAutoPlanMax int
audit *triggerAudit
running bool
intentMu sync.RWMutex
@@ -242,25 +240,16 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
runtimeCompactionNote: cfg.Agents.Defaults.Texts.RuntimeCompactionNote,
startupCompactionNote: cfg.Agents.Defaults.Texts.StartupCompactionNote,
systemRewriteTemplate: cfg.Agents.Defaults.Texts.SystemRewriteTemplate,
sessionAutoPlan: cfg.Agents.Defaults.RuntimeControl.SessionAutoPlanEnabled,
sessionAutoPlanMax: cfg.Agents.Defaults.RuntimeControl.SessionAutoPlanMaxTasks,
audit: newTriggerAudit(workspace),
running: false,
intentHints: map[string]string{},
sessionScheduler: NewSessionScheduler(cfg.Agents.Defaults.RuntimeControl.SessionMaxParallelRuns),
sessionScheduler: NewSessionScheduler(0),
ekg: ekg.New(workspace),
sessionProvider: map[string]string{},
sessionStreamed: map[string]bool{},
providerResponses: map[string]config.ProviderResponsesConfig{},
telegramStreaming: cfg.Channels.Telegram.Streaming,
}
if !cfg.Agents.Defaults.RuntimeControl.SessionResourceSchedulingEnabled {
loop.sessionScheduler = nil
}
if loop.sessionAutoPlanMax <= 0 {
loop.sessionAutoPlanMax = 4
}
// Initialize provider fallback chain (primary + proxy_fallbacks).
loop.providerPool = map[string]providers.LLMProvider{}
loop.providerNames = []string{}

View File

@@ -12,8 +12,6 @@ import (
"clawgo/pkg/scheduling"
)
const defaultSessionAutoPlanMaxTasks = 4
type plannedTask struct {
Index int
Content string
@@ -42,9 +40,6 @@ func (al *AgentLoop) planSessionTasks(msg bus.InboundMessage) []plannedTask {
if base == "" {
return nil
}
if !al.sessionAutoPlan {
return []plannedTask{{Index: 1, Content: base, ResourceKeys: scheduling.DeriveResourceKeys(base)}}
}
if msg.Channel == "system" || msg.Channel == "internal" {
return []plannedTask{{Index: 1, Content: base, ResourceKeys: scheduling.DeriveResourceKeys(base)}}
}
@@ -62,14 +57,6 @@ func (al *AgentLoop) planSessionTasks(msg bus.InboundMessage) []plannedTask {
return []plannedTask{{Index: 1, Content: base, ResourceKeys: scheduling.DeriveResourceKeys(base)}}
}
maxTasks := al.sessionAutoPlanMax
if maxTasks <= 0 {
maxTasks = defaultSessionAutoPlanMaxTasks
}
if len(segments) > maxTasks {
segments = segments[:maxTasks]
}
out := make([]plannedTask, 0, len(segments))
for i, seg := range segments {
content := strings.TrimSpace(seg)

View File

@@ -16,7 +16,7 @@ func TestSplitPlannedSegments_Bullets(t *testing.T) {
}
func TestPlanSessionTasks_Semicolon(t *testing.T) {
loop := &AgentLoop{sessionAutoPlan: true, sessionAutoPlanMax: 4}
loop := &AgentLoop{}
tasks := loop.planSessionTasks(bus.InboundMessage{Channel: "cli", Content: "修复 pkg/a.go修复 pkg/b.go"})
if len(tasks) != 2 {
t.Fatalf("expected 2 tasks, got %#v", tasks)
@@ -32,8 +32,6 @@ func TestProcessPlannedMessage_AggregatesResults(t *testing.T) {
{Content: "done-b", FinishReason: "stop"},
}}
loop := setupLoop(t, rp)
loop.sessionAutoPlan = true
loop.sessionAutoPlanMax = 4
resp, err := loop.processPlannedMessage(context.Background(), bus.InboundMessage{
Channel: "cli",

View File

@@ -93,23 +93,19 @@ type HeartbeatConfig struct {
}
type RuntimeControlConfig struct {
IntentMaxInputChars int `json:"intent_max_input_chars" env:"CLAWGO_INTENT_MAX_INPUT_CHARS"`
AutonomyTickIntervalSec int `json:"autonomy_tick_interval_sec" env:"CLAWGO_AUTONOMY_TICK_INTERVAL_SEC"`
AutonomyMinRunIntervalSec int `json:"autonomy_min_run_interval_sec" env:"CLAWGO_AUTONOMY_MIN_RUN_INTERVAL_SEC"`
AutonomyIdleThresholdSec int `json:"autonomy_idle_threshold_sec" env:"CLAWGO_AUTONOMY_IDLE_THRESHOLD_SEC"`
AutonomyMaxRoundsWithoutUser int `json:"autonomy_max_rounds_without_user" env:"CLAWGO_AUTONOMY_MAX_ROUNDS_WITHOUT_USER"`
AutonomyMaxPendingDurationSec int `json:"autonomy_max_pending_duration_sec" env:"CLAWGO_AUTONOMY_MAX_PENDING_DURATION_SEC"`
AutonomyMaxConsecutiveStalls int `json:"autonomy_max_consecutive_stalls" env:"CLAWGO_AUTONOMY_MAX_STALLS"`
AutoLearnMaxRoundsWithoutUser int `json:"autolearn_max_rounds_without_user" env:"CLAWGO_AUTOLEARN_MAX_ROUNDS_WITHOUT_USER"`
RunStateTTLSeconds int `json:"run_state_ttl_seconds" env:"CLAWGO_RUN_STATE_TTL_SECONDS"`
RunStateMax int `json:"run_state_max" env:"CLAWGO_RUN_STATE_MAX"`
ToolParallelSafeNames []string `json:"tool_parallel_safe_names"`
ToolMaxParallelCalls int `json:"tool_max_parallel_calls"`
SessionResourceSchedulingEnabled bool `json:"session_resource_scheduling_enabled" env:"CLAWGO_SESSION_RESOURCE_SCHEDULING_ENABLED"`
SessionMaxParallelRuns int `json:"session_max_parallel_runs" env:"CLAWGO_SESSION_MAX_PARALLEL_RUNS"`
SessionAutoPlanEnabled bool `json:"session_auto_plan_enabled" env:"CLAWGO_SESSION_AUTO_PLAN_ENABLED"`
SessionAutoPlanMaxTasks int `json:"session_auto_plan_max_tasks" env:"CLAWGO_SESSION_AUTO_PLAN_MAX_TASKS"`
SystemSummary SystemSummaryPolicyConfig `json:"system_summary"`
IntentMaxInputChars int `json:"intent_max_input_chars" env:"CLAWGO_INTENT_MAX_INPUT_CHARS"`
AutonomyTickIntervalSec int `json:"autonomy_tick_interval_sec" env:"CLAWGO_AUTONOMY_TICK_INTERVAL_SEC"`
AutonomyMinRunIntervalSec int `json:"autonomy_min_run_interval_sec" env:"CLAWGO_AUTONOMY_MIN_RUN_INTERVAL_SEC"`
AutonomyIdleThresholdSec int `json:"autonomy_idle_threshold_sec" env:"CLAWGO_AUTONOMY_IDLE_THRESHOLD_SEC"`
AutonomyMaxRoundsWithoutUser int `json:"autonomy_max_rounds_without_user" env:"CLAWGO_AUTONOMY_MAX_ROUNDS_WITHOUT_USER"`
AutonomyMaxPendingDurationSec int `json:"autonomy_max_pending_duration_sec" env:"CLAWGO_AUTONOMY_MAX_PENDING_DURATION_SEC"`
AutonomyMaxConsecutiveStalls int `json:"autonomy_max_consecutive_stalls" env:"CLAWGO_AUTONOMY_MAX_STALLS"`
AutoLearnMaxRoundsWithoutUser int `json:"autolearn_max_rounds_without_user" env:"CLAWGO_AUTOLEARN_MAX_ROUNDS_WITHOUT_USER"`
RunStateTTLSeconds int `json:"run_state_ttl_seconds" env:"CLAWGO_RUN_STATE_TTL_SECONDS"`
RunStateMax int `json:"run_state_max" env:"CLAWGO_RUN_STATE_MAX"`
ToolParallelSafeNames []string `json:"tool_parallel_safe_names"`
ToolMaxParallelCalls int `json:"tool_max_parallel_calls"`
SystemSummary SystemSummaryPolicyConfig `json:"system_summary"`
}
type SystemSummaryPolicyConfig struct {
@@ -423,22 +419,18 @@ func DefaultConfig() *Config {
MaxTranscriptChars: 20000,
},
RuntimeControl: RuntimeControlConfig{
IntentMaxInputChars: 1200,
AutonomyTickIntervalSec: 20,
AutonomyMinRunIntervalSec: 20,
AutonomyIdleThresholdSec: 20,
AutonomyMaxRoundsWithoutUser: 120,
AutonomyMaxPendingDurationSec: 180,
AutonomyMaxConsecutiveStalls: 3,
AutoLearnMaxRoundsWithoutUser: 200,
RunStateTTLSeconds: 1800,
RunStateMax: 500,
ToolParallelSafeNames: []string{"read_file", "list_files", "find_files", "grep_files", "memory_search", "web_search", "repo_map", "system_info"},
ToolMaxParallelCalls: 2,
SessionResourceSchedulingEnabled: true,
SessionMaxParallelRuns: 4,
SessionAutoPlanEnabled: true,
SessionAutoPlanMaxTasks: 4,
IntentMaxInputChars: 1200,
AutonomyTickIntervalSec: 20,
AutonomyMinRunIntervalSec: 20,
AutonomyIdleThresholdSec: 20,
AutonomyMaxRoundsWithoutUser: 120,
AutonomyMaxPendingDurationSec: 180,
AutonomyMaxConsecutiveStalls: 3,
AutoLearnMaxRoundsWithoutUser: 200,
RunStateTTLSeconds: 1800,
RunStateMax: 500,
ToolParallelSafeNames: []string{"read_file", "list_files", "find_files", "grep_files", "memory_search", "web_search", "repo_map", "system_info"},
ToolMaxParallelCalls: 2,
SystemSummary: SystemSummaryPolicyConfig{
Marker: "## System Task Summary",
CompletedPrefix: "- Completed:",

View File

@@ -52,12 +52,6 @@ func Validate(cfg *Config) []error {
if rc.ToolMaxParallelCalls <= 0 {
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.tool_max_parallel_calls must be > 0"))
}
if rc.SessionMaxParallelRuns <= 0 {
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.session_max_parallel_runs must be > 0"))
}
if rc.SessionAutoPlanMaxTasks <= 0 {
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.session_auto_plan_max_tasks must be > 0"))
}
if strings.TrimSpace(rc.SystemSummary.Marker) == "" {
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.system_summary.marker must be non-empty"))
}

View File

@@ -374,10 +374,6 @@ const resources = {
run_state_max: 'Run State Max',
tool_parallel_safe_names: 'Tool Parallel Safe Names',
tool_max_parallel_calls: 'Tool Max Parallel Calls',
session_resource_scheduling_enabled: 'Session Resource Scheduling Enabled',
session_max_parallel_runs: 'Session Max Parallel Runs',
session_auto_plan_enabled: 'Session Auto Plan Enabled',
session_auto_plan_max_tasks: 'Session Auto Plan Max Tasks',
system_summary: 'System Summary',
marker: 'Summary Marker',
completed_prefix: 'Completed Prefix',
@@ -800,10 +796,6 @@ const resources = {
run_state_max: '运行状态上限',
tool_parallel_safe_names: '工具并行安全名单',
tool_max_parallel_calls: '工具最大并行调用数',
session_resource_scheduling_enabled: '会话资源调度开关',
session_max_parallel_runs: '会话最大并行数',
session_auto_plan_enabled: '会话自动拆解开关',
session_auto_plan_max_tasks: '会话自动拆解最大任务数',
system_summary: '系统摘要',
marker: '摘要标记',
completed_prefix: '完成前缀',