mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-17 23:57:30 +08:00
refactor: default-enable session planning and scheduling without config flags
This commit is contained in:
@@ -69,10 +69,6 @@
|
|||||||
"run_state_max": 500,
|
"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_parallel_safe_names": ["read_file", "list_files", "find_files", "grep_files", "memory_search", "web_search", "repo_map", "system_info"],
|
||||||
"tool_max_parallel_calls": 2,
|
"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": {
|
"system_summary": {
|
||||||
"marker": "## System Task Summary",
|
"marker": "## System Task Summary",
|
||||||
"completed_prefix": "- Completed:",
|
"completed_prefix": "- Completed:",
|
||||||
|
|||||||
@@ -54,8 +54,6 @@ type AgentLoop struct {
|
|||||||
runtimeCompactionNote string
|
runtimeCompactionNote string
|
||||||
startupCompactionNote string
|
startupCompactionNote string
|
||||||
systemRewriteTemplate string
|
systemRewriteTemplate string
|
||||||
sessionAutoPlan bool
|
|
||||||
sessionAutoPlanMax int
|
|
||||||
audit *triggerAudit
|
audit *triggerAudit
|
||||||
running bool
|
running bool
|
||||||
intentMu sync.RWMutex
|
intentMu sync.RWMutex
|
||||||
@@ -242,25 +240,16 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
|
|||||||
runtimeCompactionNote: cfg.Agents.Defaults.Texts.RuntimeCompactionNote,
|
runtimeCompactionNote: cfg.Agents.Defaults.Texts.RuntimeCompactionNote,
|
||||||
startupCompactionNote: cfg.Agents.Defaults.Texts.StartupCompactionNote,
|
startupCompactionNote: cfg.Agents.Defaults.Texts.StartupCompactionNote,
|
||||||
systemRewriteTemplate: cfg.Agents.Defaults.Texts.SystemRewriteTemplate,
|
systemRewriteTemplate: cfg.Agents.Defaults.Texts.SystemRewriteTemplate,
|
||||||
sessionAutoPlan: cfg.Agents.Defaults.RuntimeControl.SessionAutoPlanEnabled,
|
|
||||||
sessionAutoPlanMax: cfg.Agents.Defaults.RuntimeControl.SessionAutoPlanMaxTasks,
|
|
||||||
audit: newTriggerAudit(workspace),
|
audit: newTriggerAudit(workspace),
|
||||||
running: false,
|
running: false,
|
||||||
intentHints: map[string]string{},
|
intentHints: map[string]string{},
|
||||||
sessionScheduler: NewSessionScheduler(cfg.Agents.Defaults.RuntimeControl.SessionMaxParallelRuns),
|
sessionScheduler: NewSessionScheduler(0),
|
||||||
ekg: ekg.New(workspace),
|
ekg: ekg.New(workspace),
|
||||||
sessionProvider: map[string]string{},
|
sessionProvider: map[string]string{},
|
||||||
sessionStreamed: map[string]bool{},
|
sessionStreamed: map[string]bool{},
|
||||||
providerResponses: map[string]config.ProviderResponsesConfig{},
|
providerResponses: map[string]config.ProviderResponsesConfig{},
|
||||||
telegramStreaming: cfg.Channels.Telegram.Streaming,
|
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).
|
// Initialize provider fallback chain (primary + proxy_fallbacks).
|
||||||
loop.providerPool = map[string]providers.LLMProvider{}
|
loop.providerPool = map[string]providers.LLMProvider{}
|
||||||
loop.providerNames = []string{}
|
loop.providerNames = []string{}
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import (
|
|||||||
"clawgo/pkg/scheduling"
|
"clawgo/pkg/scheduling"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultSessionAutoPlanMaxTasks = 4
|
|
||||||
|
|
||||||
type plannedTask struct {
|
type plannedTask struct {
|
||||||
Index int
|
Index int
|
||||||
Content string
|
Content string
|
||||||
@@ -42,9 +40,6 @@ func (al *AgentLoop) planSessionTasks(msg bus.InboundMessage) []plannedTask {
|
|||||||
if base == "" {
|
if base == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !al.sessionAutoPlan {
|
|
||||||
return []plannedTask{{Index: 1, Content: base, ResourceKeys: scheduling.DeriveResourceKeys(base)}}
|
|
||||||
}
|
|
||||||
if msg.Channel == "system" || msg.Channel == "internal" {
|
if msg.Channel == "system" || msg.Channel == "internal" {
|
||||||
return []plannedTask{{Index: 1, Content: base, ResourceKeys: scheduling.DeriveResourceKeys(base)}}
|
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)}}
|
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))
|
out := make([]plannedTask, 0, len(segments))
|
||||||
for i, seg := range segments {
|
for i, seg := range segments {
|
||||||
content := strings.TrimSpace(seg)
|
content := strings.TrimSpace(seg)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestSplitPlannedSegments_Bullets(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPlanSessionTasks_Semicolon(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"})
|
tasks := loop.planSessionTasks(bus.InboundMessage{Channel: "cli", Content: "修复 pkg/a.go;修复 pkg/b.go"})
|
||||||
if len(tasks) != 2 {
|
if len(tasks) != 2 {
|
||||||
t.Fatalf("expected 2 tasks, got %#v", tasks)
|
t.Fatalf("expected 2 tasks, got %#v", tasks)
|
||||||
@@ -32,8 +32,6 @@ func TestProcessPlannedMessage_AggregatesResults(t *testing.T) {
|
|||||||
{Content: "done-b", FinishReason: "stop"},
|
{Content: "done-b", FinishReason: "stop"},
|
||||||
}}
|
}}
|
||||||
loop := setupLoop(t, rp)
|
loop := setupLoop(t, rp)
|
||||||
loop.sessionAutoPlan = true
|
|
||||||
loop.sessionAutoPlanMax = 4
|
|
||||||
|
|
||||||
resp, err := loop.processPlannedMessage(context.Background(), bus.InboundMessage{
|
resp, err := loop.processPlannedMessage(context.Background(), bus.InboundMessage{
|
||||||
Channel: "cli",
|
Channel: "cli",
|
||||||
|
|||||||
@@ -93,23 +93,19 @@ type HeartbeatConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RuntimeControlConfig struct {
|
type RuntimeControlConfig struct {
|
||||||
IntentMaxInputChars int `json:"intent_max_input_chars" env:"CLAWGO_INTENT_MAX_INPUT_CHARS"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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"`
|
RunStateTTLSeconds int `json:"run_state_ttl_seconds" env:"CLAWGO_RUN_STATE_TTL_SECONDS"`
|
||||||
RunStateMax int `json:"run_state_max" env:"CLAWGO_RUN_STATE_MAX"`
|
RunStateMax int `json:"run_state_max" env:"CLAWGO_RUN_STATE_MAX"`
|
||||||
ToolParallelSafeNames []string `json:"tool_parallel_safe_names"`
|
ToolParallelSafeNames []string `json:"tool_parallel_safe_names"`
|
||||||
ToolMaxParallelCalls int `json:"tool_max_parallel_calls"`
|
ToolMaxParallelCalls int `json:"tool_max_parallel_calls"`
|
||||||
SessionResourceSchedulingEnabled bool `json:"session_resource_scheduling_enabled" env:"CLAWGO_SESSION_RESOURCE_SCHEDULING_ENABLED"`
|
SystemSummary SystemSummaryPolicyConfig `json:"system_summary"`
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemSummaryPolicyConfig struct {
|
type SystemSummaryPolicyConfig struct {
|
||||||
@@ -423,22 +419,18 @@ func DefaultConfig() *Config {
|
|||||||
MaxTranscriptChars: 20000,
|
MaxTranscriptChars: 20000,
|
||||||
},
|
},
|
||||||
RuntimeControl: RuntimeControlConfig{
|
RuntimeControl: RuntimeControlConfig{
|
||||||
IntentMaxInputChars: 1200,
|
IntentMaxInputChars: 1200,
|
||||||
AutonomyTickIntervalSec: 20,
|
AutonomyTickIntervalSec: 20,
|
||||||
AutonomyMinRunIntervalSec: 20,
|
AutonomyMinRunIntervalSec: 20,
|
||||||
AutonomyIdleThresholdSec: 20,
|
AutonomyIdleThresholdSec: 20,
|
||||||
AutonomyMaxRoundsWithoutUser: 120,
|
AutonomyMaxRoundsWithoutUser: 120,
|
||||||
AutonomyMaxPendingDurationSec: 180,
|
AutonomyMaxPendingDurationSec: 180,
|
||||||
AutonomyMaxConsecutiveStalls: 3,
|
AutonomyMaxConsecutiveStalls: 3,
|
||||||
AutoLearnMaxRoundsWithoutUser: 200,
|
AutoLearnMaxRoundsWithoutUser: 200,
|
||||||
RunStateTTLSeconds: 1800,
|
RunStateTTLSeconds: 1800,
|
||||||
RunStateMax: 500,
|
RunStateMax: 500,
|
||||||
ToolParallelSafeNames: []string{"read_file", "list_files", "find_files", "grep_files", "memory_search", "web_search", "repo_map", "system_info"},
|
ToolParallelSafeNames: []string{"read_file", "list_files", "find_files", "grep_files", "memory_search", "web_search", "repo_map", "system_info"},
|
||||||
ToolMaxParallelCalls: 2,
|
ToolMaxParallelCalls: 2,
|
||||||
SessionResourceSchedulingEnabled: true,
|
|
||||||
SessionMaxParallelRuns: 4,
|
|
||||||
SessionAutoPlanEnabled: true,
|
|
||||||
SessionAutoPlanMaxTasks: 4,
|
|
||||||
SystemSummary: SystemSummaryPolicyConfig{
|
SystemSummary: SystemSummaryPolicyConfig{
|
||||||
Marker: "## System Task Summary",
|
Marker: "## System Task Summary",
|
||||||
CompletedPrefix: "- Completed:",
|
CompletedPrefix: "- Completed:",
|
||||||
|
|||||||
@@ -52,12 +52,6 @@ func Validate(cfg *Config) []error {
|
|||||||
if rc.ToolMaxParallelCalls <= 0 {
|
if rc.ToolMaxParallelCalls <= 0 {
|
||||||
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.tool_max_parallel_calls must be > 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) == "" {
|
if strings.TrimSpace(rc.SystemSummary.Marker) == "" {
|
||||||
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.system_summary.marker must be non-empty"))
|
errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.system_summary.marker must be non-empty"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,10 +374,6 @@ const resources = {
|
|||||||
run_state_max: 'Run State Max',
|
run_state_max: 'Run State Max',
|
||||||
tool_parallel_safe_names: 'Tool Parallel Safe Names',
|
tool_parallel_safe_names: 'Tool Parallel Safe Names',
|
||||||
tool_max_parallel_calls: 'Tool Max Parallel Calls',
|
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',
|
system_summary: 'System Summary',
|
||||||
marker: 'Summary Marker',
|
marker: 'Summary Marker',
|
||||||
completed_prefix: 'Completed Prefix',
|
completed_prefix: 'Completed Prefix',
|
||||||
@@ -800,10 +796,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_max_parallel_runs: '会话最大并行数',
|
|
||||||
session_auto_plan_enabled: '会话自动拆解开关',
|
|
||||||
session_auto_plan_max_tasks: '会话自动拆解最大任务数',
|
|
||||||
system_summary: '系统摘要',
|
system_summary: '系统摘要',
|
||||||
marker: '摘要标记',
|
marker: '摘要标记',
|
||||||
completed_prefix: '完成前缀',
|
completed_prefix: '完成前缀',
|
||||||
|
|||||||
Reference in New Issue
Block a user