feat: add loop detection

Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
mudler
2025-04-09 19:13:41 +02:00
parent 1c4ab09335
commit 0eb68b6c20
6 changed files with 59 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ type AgentConfig struct {
EnableKnowledgeBase bool `json:"enable_kb" form:"enable_kb"`
EnableReasoning bool `json:"enable_reasoning" form:"enable_reasoning"`
KnowledgeBaseResults int `json:"kb_results" form:"kb_results"`
LoopDetectionSteps int `json:"loop_detection_steps" form:"loop_detection_steps"`
CanStopItself bool `json:"can_stop_itself" form:"can_stop_itself"`
SystemPrompt string `json:"system_prompt" form:"system_prompt"`
LongTermMemory bool `json:"long_term_memory" form:"long_term_memory"`
@@ -250,6 +251,15 @@ func NewAgentConfigMeta(
HelpText: "Enable agent to explain its reasoning process",
Tags: config.Tags{Section: "AdvancedSettings"},
},
{
Name: "loop_detection_steps",
Label: "Max Loop Detection Steps",
Type: "number",
DefaultValue: 5,
Min: 1,
Step: 1,
Tags: config.Tags{Section: "AdvancedSettings"},
},
},
MCPServers: []config.Field{
{

View File

@@ -461,6 +461,10 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
opts = append(opts, EnableKnowledgeBaseWithResults(config.KnowledgeBaseResults))
}
if config.LoopDetectionSteps > 0 {
opts = append(opts, WithLoopDetectionSteps(config.LoopDetectionSteps))
}
xlog.Info("Starting agent", "name", name, "config", config)
agent, err := New(opts...)