fix: correctly stop agents

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-03-20 22:46:54 +01:00
parent 86d3596f41
commit 638eedc2a0
3 changed files with 2 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ type ActionContext struct {
} }
func (ac *ActionContext) Cancel() { func (ac *ActionContext) Cancel() {
if ac.cancelFunc == nil { if ac.cancelFunc != nil {
ac.cancelFunc() ac.cancelFunc()
} }
} }

View File

@@ -198,6 +198,7 @@ var ErrContextCanceled = fmt.Errorf("context canceled")
func (a *Agent) Stop() { func (a *Agent) Stop() {
a.Lock() a.Lock()
defer a.Unlock() defer a.Unlock()
xlog.Debug("Stopping agent", "agent", a.Character.Name)
a.context.Cancel() a.context.Cancel()
} }

View File

@@ -369,7 +369,6 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
go func() { go func() {
if err := agent.Run(); err != nil { if err := agent.Run(); err != nil {
xlog.Error("Agent stopped", "error", err.Error(), "name", name) xlog.Error("Agent stopped", "error", err.Error(), "name", name)
panic(err)
} }
}() }()