open_ai: Disable parallel_tool_calls (#28056)

This PR disables `parallel_tool_calls` for the models that support it,
as the Agent currently expects at most one tool use per turn.

It was a bit of trial and error to figure this out. OpenAI's API
annoyingly will return an error if passing `parallel_tool_calls` to a
model that doesn't support it.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-03 18:07:37 -04:00 committed by GitHub
parent c6e2d20a02
commit 819bb8fffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 6 deletions

View file

@ -162,6 +162,23 @@ impl Model {
_ => None,
}
}
/// Returns whether the given model supports the `parallel_tool_calls` parameter.
///
/// If the model does not support the parameter, do not pass it up, or the API will return an error.
pub fn supports_parallel_tool_calls(&self) -> bool {
match self {
Self::ThreePointFiveTurbo
| Self::Four
| Self::FourTurbo
| Self::FourOmni
| Self::FourOmniMini
| Self::O1
| Self::O1Preview
| Self::O1Mini => true,
_ => false,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
@ -176,6 +193,9 @@ pub struct Request {
pub temperature: f32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tool_choice: Option<ToolChoice>,
/// Whether to enable parallel function calling during tool use.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tools: Vec<ToolDefinition>,
}