Skip to content

Commit 5c6ac0e

Browse files
authored
Merge pull request #1711 from trungutt/gordon-persist-tool-is-error
Persist tool call error state in session messages
2 parents ba7530a + 3d3bd77 commit 5c6ac0e

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

pkg/chat/chat.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type Message struct {
7474
// For Role=tool prompts this should be set to the ID given in the assistant's prior request to call a tool.
7575
ToolCallID string `json:"tool_call_id,omitempty"`
7676

77+
// IsError indicates the tool call failed (only for Role=tool messages).
78+
IsError bool `json:"is_error,omitempty"`
79+
7780
CreatedAt string `json:"created_at,omitempty"`
7881

7982
// Usage tracks token usage for this message (only set for assistant messages)

pkg/model/provider/anthropic/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (c *Client) convertMessages(ctx context.Context, messages []chat.Message) (
457457
var blocks []anthropic.ContentBlockParamUnion
458458
j := i
459459
for j < len(messages) && messages[j].Role == chat.MessageRoleTool {
460-
tr := anthropic.NewToolResultBlock(messages[j].ToolCallID, strings.TrimSpace(messages[j].Content), false)
460+
tr := anthropic.NewToolResultBlock(messages[j].ToolCallID, strings.TrimSpace(messages[j].Content), messages[j].IsError)
461461
blocks = append(blocks, tr)
462462
j++
463463
}

pkg/runtime/runtime.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ func (r *LocalRuntime) executeToolWithHandler(
16671667
Role: chat.MessageRoleTool,
16681668
Content: content,
16691669
ToolCallID: toolCall.ID,
1670+
IsError: res.IsError,
16701671
CreatedAt: time.Now().Format(time.RFC3339),
16711672
}
16721673
addAgentMessage(sess, a, &toolResponseMsg, events)
@@ -1763,6 +1764,7 @@ func (r *LocalRuntime) addToolErrorResponse(_ context.Context, sess *session.Ses
17631764
Role: chat.MessageRoleTool,
17641765
Content: errorMsg,
17651766
ToolCallID: toolCall.ID,
1767+
IsError: true,
17661768
CreatedAt: time.Now().Format(time.RFC3339),
17671769
}
17681770
addAgentMessage(sess, a, &toolResponseMsg, events)

0 commit comments

Comments
 (0)