Skip to content

Commit 9e34cf1

Browse files
authored
Merge pull request #498 from trungutt/fix/todo-id-normalization
Fix todo update failures by removing ID from create_todos schema
2 parents 675b523 + 9055491 commit 9e34cf1

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

pkg/tools/builtin/todo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ type Todo struct {
2424
Status string `json:"status" jsonschema:"New status (pending, in-progress,completed)"`
2525
}
2626

27+
type CreateTodoItem struct {
28+
Description string `json:"description" jsonschema:"Description of the todo item"`
29+
}
30+
2731
type CreateTodoArgs struct {
2832
Description string `json:"description" jsonschema:"Description of the todo item"`
2933
}
3034

3135
type CreateTodosArgs struct {
32-
Todos []Todo `json:"todos" jsonschema:"List of todo items"`
36+
Todos []CreateTodoItem `json:"todos" jsonschema:"List of todo items"`
3337
}
3438

3539
type UpdateTodoArgs struct {

pkg/tools/builtin/todo_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,12 @@ func TestTodoTool_Tools(t *testing.T) {
7777
"items": {
7878
"type": "object",
7979
"required": [
80-
"id",
81-
"description",
82-
"status"
80+
"description"
8381
],
8482
"properties": {
8583
"description": {
8684
"type": "string",
8785
"description": "Description of the todo item"
88-
},
89-
"id": {
90-
"type": "string",
91-
"description": "ID of the todo item"
92-
},
93-
"status": {
94-
"type": "string",
95-
"description": "New status (pending, in-progress,completed)"
9686
}
9787
},
9888
"additionalProperties": false
@@ -191,7 +181,7 @@ func TestTodoTool_CreateTodos(t *testing.T) {
191181

192182
// Create multiple todos
193183
args := CreateTodosArgs{
194-
Todos: []Todo{
184+
Todos: []CreateTodoItem{
195185
{Description: "First todo item"},
196186
{Description: "Second todo item"},
197187
{Description: "Third todo item"},
@@ -222,7 +212,7 @@ func TestTodoTool_CreateTodos(t *testing.T) {
222212

223213
// Create multiple todos
224214
args = CreateTodosArgs{
225-
Todos: []Todo{
215+
Todos: []CreateTodoItem{
226216
{Description: "Last todo item"},
227217
},
228218
}

pkg/tui/page/chat/chat.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)