Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ func toResponseMessages(content []Content) []Message {
Output: result.Result,
ProviderExecuted: result.ProviderExecuted,
ProviderOptions: ProviderOptions(result.ProviderMetadata),
ClientMetadata: result.ClientMetadata,
}
if result.ProviderExecuted {
// Provider-executed tool results (e.g. web search)
Expand Down
7 changes: 5 additions & 2 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1918,8 +1918,9 @@ func TestToResponseMessages_ProviderExecutedRouting(t *testing.T) {
},
// Regular tool result.
&ToolResultContent{
ToolCallID: "toolu_02",
Result: ToolResultOutputContentText{Text: "2"},
ToolCallID: "toolu_02",
Result: ToolResultOutputContentText{Text: "2"},
ClientMetadata: `{"precision":"high"}`,
},
// Some trailing text.
&TextContent{Text: "Done."},
Expand Down Expand Up @@ -1967,9 +1968,11 @@ func TestToResponseMessages_ProviderExecutedRouting(t *testing.T) {
require.Equal(t, MessageRoleTool, toolMsg.Role)
require.Len(t, toolMsg.Content, 1)

// Verify regular tool result is in tool message and client metadata survived.
tr2, ok := AsMessagePart[ToolResultPart](toolMsg.Content[0])
require.True(t, ok)
require.Equal(t, "toolu_02", tr2.ToolCallID)
require.Equal(t, `{"precision":"high"}`, tr2.ClientMetadata)
require.False(t, tr2.ProviderExecuted)
}

Expand Down
1 change: 1 addition & 0 deletions content.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ type ToolResultPart struct {
Output ToolResultOutputContent `json:"output"`
ProviderExecuted bool `json:"provider_executed"`
ProviderOptions ProviderOptions `json:"provider_options"`
ClientMetadata string `json:"client_metadata,omitempty"`
}

// GetType returns the type of the tool result part.
Expand Down
4 changes: 4 additions & 0 deletions content_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,13 @@ func (t ToolResultPart) MarshalJSON() ([]byte, error) {
Output ToolResultOutputContent `json:"output"`
ProviderExecuted bool `json:"provider_executed"`
ProviderOptions ProviderOptions `json:"provider_options,omitempty"`
ClientMetadata string `json:"client_metadata,omitempty"`
}{
ToolCallID: t.ToolCallID,
Output: t.Output,
ProviderExecuted: t.ProviderExecuted,
ProviderOptions: t.ProviderOptions,
ClientMetadata: t.ClientMetadata,
})
if err != nil {
return nil, err
Expand All @@ -743,6 +745,7 @@ func (t *ToolResultPart) UnmarshalJSON(data []byte) error {
Output json.RawMessage `json:"output"`
ProviderExecuted bool `json:"provider_executed"`
ProviderOptions map[string]json.RawMessage `json:"provider_options,omitempty"`
ClientMetadata string `json:"client_metadata,omitempty"`
}

if err := json.Unmarshal(mpj.Data, &aux); err != nil {
Expand All @@ -751,6 +754,7 @@ func (t *ToolResultPart) UnmarshalJSON(data []byte) error {

t.ToolCallID = aux.ToolCallID
t.ProviderExecuted = aux.ProviderExecuted
t.ClientMetadata = aux.ClientMetadata

// Unmarshal the Output field
output, err := UnmarshalToolResultOutputContent(aux.Output)
Expand Down
4 changes: 4 additions & 0 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestMessageJSONSerialization(t *testing.T) {
Output: ToolResultOutputContentText{
Text: "The weather is sunny, 72°F",
},
ClientMetadata: `{"units":"imperial"}`,
},
},
},
Expand Down Expand Up @@ -245,6 +246,9 @@ func compareMessagePart(t *testing.T, index int, original, decoded MessagePart)
if orig.ToolCallID != dec.ToolCallID {
t.Errorf("content[%d] tool result call id mismatch: got %q, want %q", index, dec.ToolCallID, orig.ToolCallID)
}
if orig.ClientMetadata != dec.ClientMetadata {
t.Errorf("content[%d] tool result client metadata mismatch: got %q, want %q", index, dec.ClientMetadata, orig.ClientMetadata)
}
compareToolResultOutput(t, index, orig.Output, dec.Output)
}
}
Expand Down
Loading