@@ -382,6 +382,9 @@ func (a *Agent) runAgent(ctx context.Context, acpSess *Session) error {
382382
383383 eventsChan := acpSess .rt .RunStream (ctx , acpSess .sess )
384384
385+ // Tracks tool call arguments so that we can extract useful information
386+ // once the tool call was made.
387+ toolCallArgs := map [string ]string {}
385388 for event := range eventsChan {
386389 if ctx .Err () != nil {
387390 return ctx .Err ()
@@ -411,6 +414,7 @@ func (a *Agent) runAgent(ctx context.Context, acpSess *Session) error {
411414 }
412415
413416 case * runtime.ToolCallEvent :
417+ toolCallArgs [e .ToolCall .ID ] = e .ToolCall .Function .Arguments
414418 if err := a .conn .SessionUpdate (ctx , acp.SessionNotification {
415419 SessionId : acp .SessionId (acpSess .id ),
416420 Update : buildToolCallStart (e .ToolCall , e .ToolDefinition ),
@@ -419,15 +423,21 @@ func (a *Agent) runAgent(ctx context.Context, acpSess *Session) error {
419423 }
420424
421425 case * runtime.ToolCallResponseEvent :
426+ args , ok := toolCallArgs [e .ToolCallID ]
427+ // Should never happend but you know...
428+ if ! ok {
429+ return fmt .Errorf ("missing tool call arguments for tool call ID %s" , e .ToolCallID )
430+ }
431+ delete (toolCallArgs , e .ToolCallID )
422432 if err := a .conn .SessionUpdate (ctx , acp.SessionNotification {
423433 SessionId : acp .SessionId (acpSess .id ),
424- Update : buildToolCallComplete (e . ToolCall , e . Response ),
434+ Update : buildToolCallComplete (args , e ),
425435 }); err != nil {
426436 return err
427437 }
428438
429439 // Check if this is a todo tool response and emit plan update
430- if isTodoTool (e .ToolCall . Function .Name ) && e .Result != nil && e .Result .Meta != nil {
440+ if isTodoTool (e .ToolDefinition .Name ) && e .Result != nil && e .Result .Meta != nil {
431441 if planUpdate := buildPlanUpdateFromTodos (e .Result .Meta ); planUpdate != nil {
432442 if err := a .conn .SessionUpdate (ctx , acp.SessionNotification {
433443 SessionId : acp .SessionId (acpSess .id ),
@@ -666,24 +676,24 @@ func determineToolKind(toolName string, tool tools.Tool) acp.ToolKind {
666676}
667677
668678// buildToolCallComplete creates a tool call completion update
669- func buildToolCallComplete (toolCall tools. ToolCall , output string ) acp.SessionUpdate {
679+ func buildToolCallComplete (arguments string , event * runtime. ToolCallResponseEvent ) acp.SessionUpdate {
670680 // Check if this is a file edit operation and try to extract diff info
671- if isFileEditTool (toolCall . Function .Name ) {
672- if diffContent := extractDiffContent (toolCall , output ); diffContent != nil {
681+ if isFileEditTool (event . ToolDefinition .Name ) {
682+ if diffContent := extractDiffContent (event . ToolDefinition . Name , arguments ); diffContent != nil {
673683 return acp .UpdateToolCall (
674- acp .ToolCallId (toolCall . ID ),
684+ acp .ToolCallId (event . ToolCallID ),
675685 acp .WithUpdateStatus (acp .ToolCallStatusCompleted ),
676686 acp .WithUpdateContent ([]acp.ToolCallContent {* diffContent }),
677- acp .WithUpdateRawOutput (map [string ]any {"content" : output }),
687+ acp .WithUpdateRawOutput (map [string ]any {"content" : event . Response }),
678688 )
679689 }
680690 }
681691
682692 return acp .UpdateToolCall (
683- acp .ToolCallId (toolCall . ID ),
693+ acp .ToolCallId (event . ToolCallID ),
684694 acp .WithUpdateStatus (acp .ToolCallStatusCompleted ),
685- acp .WithUpdateContent ([]acp.ToolCallContent {acp .ToolContent (acp .TextBlock (output ))}),
686- acp .WithUpdateRawOutput (map [string ]any {"content" : output }),
695+ acp .WithUpdateContent ([]acp.ToolCallContent {acp .ToolContent (acp .TextBlock (event . Response ))}),
696+ acp .WithUpdateRawOutput (map [string ]any {"content" : event . Response }),
687697 )
688698}
689699
@@ -693,8 +703,8 @@ func isFileEditTool(toolName string) bool {
693703}
694704
695705// extractDiffContent tries to create a diff content block from edit tool arguments
696- func extractDiffContent (toolCall tools. ToolCall , _ string ) * acp.ToolCallContent {
697- args := parseToolCallArguments (toolCall . Function . Arguments )
706+ func extractDiffContent (toolCallName , arguments string ) * acp.ToolCallContent {
707+ args := parseToolCallArguments (arguments )
698708
699709 // Get the path from arguments
700710 path , ok := args ["path" ].(string )
@@ -703,7 +713,7 @@ func extractDiffContent(toolCall tools.ToolCall, _ string) *acp.ToolCallContent
703713 }
704714
705715 // For edit_file, extract the edits
706- if toolCall . Function . Name == "edit_file" {
716+ if toolCallName == "edit_file" {
707717 edits , ok := args ["edits" ].([]any )
708718 if ! ok || len (edits ) == 0 {
709719 return nil
@@ -735,7 +745,7 @@ func extractDiffContent(toolCall tools.ToolCall, _ string) *acp.ToolCallContent
735745 }
736746
737747 // For write_file, the entire content is new
738- if toolCall . Function . Name == "write_file" {
748+ if toolCallName == "write_file" {
739749 if content , ok := args ["content" ].(string ); ok {
740750 diff := acp .ToolDiffContent (path , content )
741751 return & diff
0 commit comments