feat: wire loop detector into agent tool execution pipeline

- Inject session key into context before LLM iteration loop
- Register LoopDetector as ToolHook per agent in registerSharedTools
- Uses production defaults: warn@10, block@20, circuit breaker@30
This commit is contained in:
Leandro Barbosa 2026-02-18 17:00:36 -03:00
parent 239dcea724
commit 076f526ac6

View file

@ -212,6 +212,10 @@ func registerSharedTools(cfg *config.Config, msgBus *bus.MessageBus, registry *A
})
}
// Register loop detector hook (per-agent, session-isolated via context key).
// Uses production defaults: warn@10 repeats, block@20, circuit breaker@30.
agent.Tools.AddHook(tools.NewLoopDetector(tools.DefaultLoopDetectorConfig()))
// Update context builder with the (possibly filtered) tools registry
agent.ContextBuilder.SetToolsRegistry(agent.Tools)
}
@ -503,7 +507,10 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt
// 3. Save user message to session
agent.Sessions.AddMessage(opts.SessionKey, "user", opts.UserMessage)
// 4. Run LLM iteration loop
// 4. Inject session key into context for loop detection
ctx = tools.WithSessionKey(ctx, opts.SessionKey)
// 5. Run LLM iteration loop
finalContent, iteration, err := al.runLLMIteration(ctx, agent, messages, opts)
if err != nil {
return "", err