Skip to content

Commit c5c7c5a

Browse files
authored
[aisdk] Pass correct CallID and args on computer use tool call (#578)
## Summary TSIA ## How was it tested? Unit test; running testpitot locally ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).
1 parent 6a3eb78 commit c5c7c5a

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

aisdk/ai/provider/openai/internal/codec/decode.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,11 @@ func decodeComputerCall(computerCall responses.ResponseComputerToolCall) (*api.T
187187

188188
// Create tool call block with provider metadata
189189
return &api.ToolCallBlock{
190-
ToolCallID: computerCall.ID, // TODO: use computerCall.CallID instead
190+
// The CallID is what's needed to respond to the tool call, not the "ID" field.
191+
// https://platform.openai.com/docs/api-reference/responses/object#responses-object-output-computer_tool_call
192+
ToolCallID: computerCall.CallID,
191193
ToolName: ComputerUseToolID,
192-
Args: json.RawMessage(computerCall.RawJSON()), // TODO: pass the Action instead.
194+
Args: json.RawMessage(computerCall.Action.RawJSON()), // The Action is the only argument to the computer call.
193195
ProviderMetadata: api.NewProviderMetadata(map[string]any{ProviderName: metadata}),
194196
}, nil
195197
}

aisdk/ai/provider/openai/internal/codec/decode_test.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -640,22 +640,24 @@ func TestDecodeToolCalls(t *testing.T) {
640640
},
641641
},
642642
{
643-
name: "computer call",
643+
name: "computer call with no safety checks field",
644644
response: `{
645645
"output": [
646646
{
647647
"type": "computer_call",
648648
"id": "comp1",
649-
"command": "ls -la",
650-
"working_directory": "/tmp"
649+
"call_id": "call_123",
650+
"action": {
651+
"type": "screenshot"
652+
}
651653
}
652654
]
653655
}`,
654656
want: []api.ContentBlock{
655657
&api.ToolCallBlock{
656-
ToolCallID: "comp1",
658+
ToolCallID: "call_123",
657659
ToolName: "openai.computer_use_preview",
658-
Args: json.RawMessage(`{"command":"ls -la","working_directory":"/tmp","id":"comp1","type":"computer_call"}`),
660+
Args: json.RawMessage(`{"type":"screenshot"}`),
659661
ProviderMetadata: api.NewProviderMetadata(map[string]any{
660662
"openai": &Metadata{
661663
ComputerSafetyChecks: []ComputerSafetyCheck{},
@@ -670,9 +672,10 @@ func TestDecodeToolCalls(t *testing.T) {
670672
"output": [
671673
{
672674
"type": "computer_call",
673-
"id": "comp2",
674-
"command": "rm -rf /",
675-
"working_directory": "/",
675+
"call_id": "call_123",
676+
"action": {
677+
"type": "screenshot"
678+
},
676679
"pending_safety_checks": [
677680
{
678681
"id": "check1",
@@ -690,9 +693,9 @@ func TestDecodeToolCalls(t *testing.T) {
690693
}`,
691694
want: []api.ContentBlock{
692695
&api.ToolCallBlock{
693-
ToolCallID: "comp2",
696+
ToolCallID: "call_123",
694697
ToolName: "openai.computer_use_preview",
695-
Args: json.RawMessage(`{"command":"rm -rf /","working_directory":"/","id":"comp2","type":"computer_call","pending_safety_checks":[{"id":"check1","code":"file_access","message":"File access requested"},{"id":"check2","code":"dangerous_command","message":"Potentially dangerous command detected"}]}`),
698+
Args: json.RawMessage(`{"type":"screenshot"}`),
696699
ProviderMetadata: api.NewProviderMetadata(map[string]any{
697700
"openai": &Metadata{
698701
ComputerSafetyChecks: []ComputerSafetyCheck{
@@ -718,18 +721,19 @@ func TestDecodeToolCalls(t *testing.T) {
718721
"output": [
719722
{
720723
"type": "computer_call",
721-
"id": "comp3",
722-
"command": "echo hello",
723-
"working_directory": "/tmp",
724+
"call_id": "call_123",
725+
"action": {
726+
"type": "screenshot"
727+
},
724728
"pending_safety_checks": []
725729
}
726730
]
727731
}`,
728732
want: []api.ContentBlock{
729733
&api.ToolCallBlock{
730-
ToolCallID: "comp3",
734+
ToolCallID: "call_123",
731735
ToolName: "openai.computer_use_preview",
732-
Args: json.RawMessage(`{"command":"echo hello","working_directory":"/tmp","id":"comp3","type":"computer_call","pending_safety_checks":[]}`),
736+
Args: json.RawMessage(`{"type":"screenshot"}`),
733737
ProviderMetadata: api.NewProviderMetadata(map[string]any{
734738
"openai": &Metadata{
735739
ComputerSafetyChecks: []ComputerSafetyCheck{},

0 commit comments

Comments
 (0)