executeToolCall dispatches a single tool call from the LLM response and records the result in session history. code_comment handling includes optional async dispatch through CommentWorkerPool plus line-number resolution / re-location.
(ctx context.Context, newPath string, call llm.ToolCall, rec *session.TaskRecord)
| 272 | // optional async dispatch through CommentWorkerPool plus line-number |
| 273 | // resolution / re-location. |
| 274 | func (r *Runner) executeToolCall(ctx context.Context, newPath string, call llm.ToolCall, rec *session.TaskRecord) tool.TaskCheckpoint { |
| 275 | t := tool.OfName(call.Function.Name) |
| 276 | |
| 277 | if !t.IsKnown() { |
| 278 | p, ok := r.deps.Tools.Get(call.Function.Name) |
| 279 | if !ok { |
| 280 | return tool.Of(tool.NotAvailableMsg) |
| 281 | } |
| 282 | r.recordToolCall(call.Function.Name) |
| 283 | dynArgs, err := parseToolArgs(call.Function.Arguments) |
| 284 | if err != nil { |
| 285 | return tool.Of(fmt.Sprintf("Error parsing tool arguments for %s: %v", call.Function.Name, err)) |
| 286 | } |
| 287 | telemetry.PrintToolCallStarted(call.Function.Name, dynArgs) |
| 288 | _, toolSpan := telemetry.StartToolSpan(ctx, call.Function.Name) |
| 289 | startTime := time.Now() |
| 290 | result, err := p.Execute(ctx, dynArgs) |
| 291 | dur := time.Since(startTime) |
| 292 | if err != nil { |
| 293 | telemetry.RecordToolResult(toolSpan, call.Function.Name, dur.Milliseconds(), err) |
| 294 | toolSpan.End() |
| 295 | telemetry.RecordToolCall(ctx, call.Function.Name, dur, false) |
| 296 | telemetry.PrintToolCallError(call.Function.Name, err) |
| 297 | return tool.Of(fmt.Sprintf("Error executing tool %s: %v", call.Function.Name, err)) |
| 298 | } |
| 299 | telemetry.RecordToolResult(toolSpan, call.Function.Name, dur.Milliseconds(), nil) |
| 300 | toolSpan.End() |
| 301 | telemetry.RecordToolCall(ctx, call.Function.Name, dur, true) |
| 302 | telemetry.PrintToolCallFinished(call.Function.Name, dur) |
| 303 | if rec != nil { |
| 304 | rec.AddToolResult(call.Function.Name, call.Function.Arguments, result) |
| 305 | } |
| 306 | return tool.Of(result) |
| 307 | } |
| 308 | |
| 309 | if t == tool.TaskDone { |
| 310 | return tool.Complete() |
| 311 | } |
| 312 | |
| 313 | p := lookupTool(r.deps.Tools, t) |
| 314 | if p == nil { |
| 315 | return tool.Of(tool.NotAvailableMsg) |
| 316 | } |
| 317 | |
| 318 | r.recordToolCall(t.Name()) |
| 319 | |
| 320 | args, err := parseToolArgs(call.Function.Arguments) |
| 321 | if err != nil { |
| 322 | return tool.Of(fmt.Sprintf("Error parsing tool arguments for %s: %v", t.Name(), err)) |
| 323 | } |
| 324 | |
| 325 | // Always inject the current file path for code_comment. |
| 326 | // The model sometimes hallucinates a path, so we override it. |
| 327 | if t == tool.CodeComment && newPath != "" { |
| 328 | args["path"] = newPath |
| 329 | } |
| 330 | |
| 331 | startTime := time.Now() |