fix(openai): fix missing tools and instructions in Responses API
Some checks failed
CI / Check (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Formatting (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Release Build (push) Has been cancelled

- Add 'tools' and 'tool_choice' parameters to streaming Responses API
- Include 'name' field in message items for Responses API input
- Use string content for text-only messages to improve instruction following
- Fix subagents not triggering and files not being created
This commit is contained in:
2026-03-18 13:51:36 +00:00
parent cb5b921550
commit 275ce34d05

View File

@@ -190,15 +190,20 @@ impl super::Provider for OpenAIProvider {
}
}
} else if let Some(text) = content.as_str() {
let new_type = if mapped_role == "assistant" { "output_text" } else { "input_text" };
content = serde_json::json!([{ "type": new_type, "text": text }]);
// If it's just a string, send it as a string instead of an array of objects
// as it's safer for standard conversational messages.
content = serde_json::json!(text);
}
input_parts.push(serde_json::json!({
let mut msg_item = serde_json::json!({
"type": "message",
"role": mapped_role,
"content": content
}));
});
if let Some(name) = m.get("name") {
msg_item["name"] = name.clone();
}
input_parts.push(msg_item);
}
let mut body = serde_json::json!({
@@ -223,6 +228,9 @@ impl super::Provider for OpenAIProvider {
if let Some(tools) = &request.tools {
body["tools"] = serde_json::json!(tools);
}
if let Some(tool_choice) = &request.tool_choice {
body["tool_choice"] = serde_json::json!(tool_choice);
}
let resp = self
.client
@@ -529,15 +537,20 @@ impl super::Provider for OpenAIProvider {
}
}
} else if let Some(text) = content.as_str() {
let new_type = if mapped_role == "assistant" { "output_text" } else { "input_text" };
content = serde_json::json!([{ "type": new_type, "text": text }]);
// If it's just a string, send it as a string instead of an array of objects
// as it's safer for standard conversational messages.
content = serde_json::json!(text);
}
input_parts.push(serde_json::json!({
let mut msg_item = serde_json::json!({
"type": "message",
"role": mapped_role,
"content": content
}));
});
if let Some(name) = m.get("name") {
msg_item["name"] = name.clone();
}
input_parts.push(msg_item);
}
let mut body = serde_json::json!({
@@ -560,6 +573,13 @@ impl super::Provider for OpenAIProvider {
}
}
if let Some(tools) = &request.tools {
body["tools"] = serde_json::json!(tools);
}
if let Some(tool_choice) = &request.tool_choice {
body["tool_choice"] = serde_json::json!(tool_choice);
}
let url = format!("{}/responses", self.config.base_url);
let api_key = self.api_key.clone();
let model = request.model.clone();