@@ -242,20 +242,23 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
242242 case * runtime.ToolCallEvent :
243243 spinnerCmd := p .setWorking (true )
244244 cmd := p .messages .AddOrUpdateToolCall (msg .AgentName , msg .ToolCall , msg .ToolDefinition , types .ToolStatusRunning )
245+ return p , tea .Batch (cmd , p .messages .ScrollToBottom (), spinnerCmd )
246+ case * runtime.ToolCallResponseEvent :
247+ spinnerCmd := p .setWorking (true )
248+ cmd := p .messages .AddToolResult (msg , types .ToolStatusCompleted )
245249
246250 // Check if this is a todo-related tool call and update sidebar
251+ // Only update after successful execution (in response, not during call)
247252 toolName := msg .ToolCall .Function .Name
248253 if toolName == "create_todo" || toolName == "create_todos" ||
249254 toolName == "update_todo" || toolName == "list_todos" {
250- // Log error but don't fail the tool call
251- // Could add logging here if needed
252- _ = p .sidebar .SetTodos (msg .ToolCall )
255+ // Only update if the response doesn't contain an error
256+ // Response starting with "Error calling tool:" indicates failure
257+ if len (msg .Response ) < 19 || msg .Response [:19 ] != "Error calling tool:" {
258+ _ = p .sidebar .SetTodos (msg .ToolCall )
259+ }
253260 }
254261
255- return p , tea .Batch (cmd , p .messages .ScrollToBottom (), spinnerCmd )
256- case * runtime.ToolCallResponseEvent :
257- spinnerCmd := p .setWorking (true )
258- cmd := p .messages .AddToolResult (msg , types .ToolStatusCompleted )
259262 return p , tea .Batch (cmd , p .messages .ScrollToBottom (), spinnerCmd )
260263 case * runtime.MaxIterationsReachedEvent :
261264 spinnerCmd := p .setWorking (false )
0 commit comments