agent: nil-check ToolServer before ListTools in turn

Prevents nil pointer dereference when a newly created agent's
tool server connection failed to establish (keeper.Dial returned
nil, or session was restored with a dead toolsConn).
This commit is contained in:
Levi Neely 2026-08-03 15:45:57 +02:00
parent c9c76d51c0
commit aa84cd1c9f
1 changed files with 6 additions and 2 deletions

View File

@ -125,8 +125,12 @@ func (ag *Agent) executeTurn(ctx context.Context, input string) string {
// Refresh tool definitions from the tool server so dynamically loaded
// tools (via tool_load) are available on the next turn without a rebuild.
var tools []backend.Tool
if ti, err := ag.runtime.ToolServer.ListTools(); err == nil {
tools = toolInfosToBackend(ti)
if ag.runtime.ToolServer != nil {
if ti, err := ag.runtime.ToolServer.ListTools(); err == nil {
tools = toolInfosToBackend(ti)
} else {
tools = ag.runtime.Tools
}
} else {
tools = ag.runtime.Tools
}