Skip to content

Commit 0840da0

Browse files
committed
openai_client: update tool definition to flat shape and require tool call; update test accordingly; ignore /.gocache/
1 parent 51d619c commit 0840da0

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ go.work.sum
3939

4040
/.goagent/
4141

42+
/.gocache/

internal/core/runtime/openai_client.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,18 @@ func (c *OpenAIClient) RequestPlanStreamingResponses(ctx context.Context, histor
113113
"model": c.model,
114114
"input": inputMsgs,
115115
"stream": true,
116-
// Define the function tool using the nested Responses API shape.
117-
// See: tools: [{ "type": "function", "function": { name, description, parameters } }]
116+
// Define the function tool in the flat Responses shape and require a tool call.
118117
"tools": []map[string]any{
119118
{
120-
"type": "function",
121-
"function": map[string]any{
122-
"name": c.tool.Name,
123-
"description": c.tool.Description,
124-
"parameters": c.tool.Parameters,
125-
},
119+
"type": "function",
120+
"name": c.tool.Name,
121+
"description": c.tool.Description,
122+
"parameters": c.tool.Parameters,
126123
},
127124
},
128-
// Force a tool call to our specific function. If you only want to
129-
// require any tool call, you could set "required" instead.
130-
"tool_choice": map[string]any{
131-
"type": "function",
132-
"function": map[string]any{"name": c.tool.Name},
133-
},
125+
// Require a tool call; with only one tool defined, this forces the model
126+
// to call our tool with arguments.
127+
"tool_choice": "required",
134128
}
135129
if c.reasoningEffort != "" {
136130
reqBody["reasoning"] = map[string]any{"effort": c.reasoningEffort}

internal/core/runtime/openai_client_test.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ func TestRequestPlanUsesFunctionToolShape(t *testing.T) {
7171
t.Fatalf("expected request host %s to match server host %s", requestHost, parsedURL.Host)
7272
}
7373

74-
// Validate Responses API function tool shape (nested function entry)
75-
// tools should be: [{ "type": "function", "function": { name, description, parameters } }]
74+
// Validate Responses API function tool shape (flat function entry)
7675
tools, ok := captured["tools"].([]any)
7776
if !ok || len(tools) != 1 {
7877
t.Fatalf("expected tools to contain one entry, got %T (len=%d)", captured["tools"], len(tools))
@@ -84,35 +83,19 @@ func TestRequestPlanUsesFunctionToolShape(t *testing.T) {
8483
if t0["type"] != "function" {
8584
t.Fatalf("expected tools[0].type=function, got %v", t0["type"])
8685
}
87-
fn, ok := t0["function"].(map[string]any)
88-
if !ok || fn == nil {
89-
t.Fatalf("expected tools[0].function to be an object, got %T", t0["function"])
86+
if t0["name"] != schema.ToolName {
87+
t.Fatalf("expected tools[0].name=%s, got %v", schema.ToolName, t0["name"])
9088
}
91-
if fn["name"] != schema.ToolName {
92-
t.Fatalf("expected tools[0].function.name=%s, got %v", schema.ToolName, fn["name"])
93-
}
94-
params, ok := fn["parameters"].(map[string]any)
89+
params, ok := t0["parameters"].(map[string]any)
9590
if !ok {
96-
t.Fatalf("expected tools[0].function.parameters to be an object")
91+
t.Fatalf("expected tools[0].parameters to be an object")
9792
}
9893
if _, ok := params["type"].(string); !ok {
9994
t.Fatalf("expected parameters schema to include a type field")
10095
}
10196

102-
// Validate tool_choice object selecting our function
103-
// tool_choice should be: { "type": "function", "function": { "name": ToolName } }
104-
tc, ok := captured["tool_choice"].(map[string]any)
105-
if !ok {
106-
t.Fatalf("expected tool_choice to be an object, got %T", captured["tool_choice"])
107-
}
108-
if tc["type"] != "function" {
109-
t.Fatalf("expected tool_choice.type=function, got %v", tc["type"])
110-
}
111-
tcf, ok := tc["function"].(map[string]any)
112-
if !ok || tcf == nil {
113-
t.Fatalf("expected tool_choice.function to be an object, got %T", tc["function"])
114-
}
115-
if tcf["name"] != schema.ToolName {
116-
t.Fatalf("expected tool_choice.function.name=%s, got %v", schema.ToolName, tcf["name"])
97+
// Validate tool_choice required
98+
if captured["tool_choice"] != "required" {
99+
t.Fatalf("expected tool_choice=required, got %v", captured["tool_choice"])
117100
}
118101
}

0 commit comments

Comments
 (0)