Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit d789cdd

Browse files
committed
fix: llm auto continue judge for new loop
1 parent 08d8ffe commit d789cdd

8 files changed

Lines changed: 983 additions & 8 deletions

File tree

internal/config/config.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ type SandboxOutputCompactionConfig struct {
102102

103103
// LoopConfig holds configuration for the orchestrator loop abstraction
104104
type LoopConfig struct {
105-
Strategy string `json:"strategy"` // Loop strategy: "default", "conservative", "aggressive"
106-
MaxIterations int `json:"max_iterations"` // Maximum number of iterations (0 = use default)
107-
MaxAutoContinueAttempts int `json:"max_auto_continue_attempts"` // Maximum auto-continue attempts (0 = use default)
108-
EnableLoopDetection bool `json:"enable_loop_detection"` // Enable repetitive pattern detection
109-
EnableAutoContinue bool `json:"enable_auto_continue"` // Enable automatic continuation on incomplete responses
105+
Strategy string `json:"strategy"` // Loop strategy: "default", "conservative", "aggressive", "llm-judge"
106+
MaxIterations int `json:"max_iterations"` // Maximum number of iterations (0 = use default)
107+
MaxAutoContinueAttempts int `json:"max_auto_continue_attempts"` // Maximum auto-continue attempts (0 = use default)
108+
EnableLoopDetection bool `json:"enable_loop_detection"` // Enable repetitive pattern detection
109+
EnableAutoContinue bool `json:"enable_auto_continue"` // Enable automatic continuation on incomplete responses
110+
EnableLLMAutoContinueJudge bool `json:"enable_llm_auto_continue_judge"` // Enable LLM-based auto-continue decisions
111+
LLMAutoContinueJudgeTimeout int `json:"llm_auto_continue_judge_timeout_seconds"` // LLM judge timeout in seconds (0 = use default 15s)
112+
LLMAutoContinueJudgeTokenLimit int `json:"llm_auto_continue_judge_token_limit"` // LLM judge token limit (0 = use default 1000)
110113
}
111114

112115
// SandboxConfig holds configuration for shell command sandboxing

internal/orchestrator/loop/doc.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,41 @@
118118
// - DefaultStrategy: Balanced approach with standard limits
119119
// - ConservativeStrategy: Stops earlier to prevent excessive token usage
120120
// - AggressiveStrategy: Continues more aggressively for batch operations
121+
// - LLMJudgeStrategy: Uses an LLM to make intelligent auto-continue decisions
121122
//
122123
// Custom strategies can be implemented by implementing the Strategy interface.
123124
//
125+
// # LLM Judge Strategy
126+
//
127+
// The LLMJudgeStrategy provides intelligent auto-continue decisions by:
128+
//
129+
// 1. Checking for repetitive patterns (loops) in recent messages
130+
// 2. Using an LLM to evaluate whether continuation is needed
131+
// 3. Applying model-specific decision logic (Qwen 3, Mistral, etc.)
132+
// 4. Falling back to pattern matching on any LLM failure
133+
//
134+
// Configuration options:
135+
//
136+
// - EnableLLMAutoContinueJudge: Enable/disable the LLM judge
137+
// - LLMAutoContinueJudgeTimeout: Maximum time to wait for LLM response (default: 15s)
138+
// - LLMAutoContinueJudgeTokenLimit: Context limit sent to LLM judge (default: 1000 tokens)
139+
//
140+
// Example usage:
141+
//
142+
// config := loop.DefaultConfig()
143+
// config.EnableLLMAutoContinueJudge = true
144+
// config.LLMAutoContinueJudgeTimeout = 15 * time.Second
145+
// config.LLMAutoContinueJudgeTokenLimit = 1000
146+
// factory := loop.NewStrategyFactory(config)
147+
// strategy := factory.CreateWithLLMJudge("llm-judge", config, llmClient, modelID, session)
148+
//
149+
// The LLM judge automatically falls back to pattern matching if:
150+
// - The LLM client is not available
151+
// - The model ID is empty
152+
// - The LLM call times out
153+
// - The LLM returns an invalid response
154+
// - Auto-continue is disabled in the config
155+
//
124156
// # Testing
125157
//
126158
// The package includes mock implementations for testing:

0 commit comments

Comments
 (0)