From f9becce7cc4d9af1853642cd2befb690341034ae Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Mon, 3 Aug 2026 16:26:08 +0200 Subject: [PATCH] fix(agent): refresh outputFormat lookup on each turn The OutputFormat function was set once at runtime build time and stored in ag.runtime.OutputFormat. When tools were dynamically loaded via tool_load, the tool definitions were refreshed but the OutputFormat lookup still used the stale runtime version that didn't know about newly loaded tools. Build the outputFormats map from the fresh tool list on each turn, just like we already do for the tool definitions. This ensures outputFormat (e.g., 'diff' for file_edit) is available immediately after loading a tool. --- agent/turn.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/agent/turn.go b/agent/turn.go index 8ecdd15..b51268d 100644 --- a/agent/turn.go +++ b/agent/turn.go @@ -132,6 +132,18 @@ func (ag *Agent) executeTurn(ctx context.Context, input string) string { return "" } tools := toolInfosToBackend(ti) + + // Build output format lookup from the fresh tool list. This ensures + // dynamically loaded tools (via tool_load) have their outputFormat + // available immediately, not just after a full runtime rebuild. + outputFormats := make(map[string]string, len(ti)) + for _, info := range ti { + outputFormats[info.Name] = info.OutputFormat + } + outputFormatFn := func(name string) string { + return outputFormats[name] + } + ag.cfg = agentConfig{ Backend: ag.runtime.Backend, preamble: ag.runtime.Preamble, @@ -139,7 +151,7 @@ func (ag *Agent) executeTurn(ctx context.Context, input string) string { Tools: tools, Exec: ag.runtime.Exec, ClassifyTool: ag.runtime.ClassifyTool, - OutputFormat: ag.runtime.OutputFormat, + OutputFormat: outputFormatFn, ClassifyTier: ag.runtime.ClassifyTier, GenerationParams: ag.runtime.GenParams, MaxSteps: ag.runtime.MaxSteps,