mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Use input items for Responses Lite tools (#27946)
When using Responses Lite, we should all use `additional_tools` and a developer item instead of the top level tools array & instructions field. This keeps things 1-to-1. Forced namespacing for _all_ tools will land in a following PR after some coordination & fixes in Responses API (around collisions & return items). The goal is to eventually expand the scope of this to _all_ requests from codex, but that will require larger coordination across providers & slower rollout.
This commit is contained in:
@@ -932,6 +932,14 @@ impl InternalChatMessageMetadataPassthrough {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema, TS)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum ResponseItem {
|
||||
#[schemars(skip)]
|
||||
#[ts(skip)]
|
||||
AdditionalTools {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
id: Option<String>,
|
||||
role: String,
|
||||
tools: Vec<serde_json::Value>,
|
||||
},
|
||||
Message {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
@@ -1160,7 +1168,8 @@ impl ResponseItem {
|
||||
/// Returns the non-empty Responses API item ID, if present.
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Message { id, .. }
|
||||
Self::AdditionalTools { id, .. }
|
||||
| Self::Message { id, .. }
|
||||
| Self::AgentMessage { id, .. }
|
||||
| Self::LocalShellCall { id, .. }
|
||||
| Self::FunctionCall { id, .. }
|
||||
@@ -1181,7 +1190,8 @@ impl ResponseItem {
|
||||
/// Sets or clears the Responses API item ID for variants that carry one.
|
||||
pub fn set_id(&mut self, new_id: Option<String>) {
|
||||
match self {
|
||||
Self::Message { id, .. }
|
||||
Self::AdditionalTools { id, .. }
|
||||
| Self::Message { id, .. }
|
||||
| Self::AgentMessage { id, .. }
|
||||
| Self::LocalShellCall { id, .. }
|
||||
| Self::FunctionCall { id, .. }
|
||||
@@ -1282,7 +1292,7 @@ impl ResponseItem {
|
||||
internal_chat_message_metadata_passthrough: metadata,
|
||||
..
|
||||
} => metadata.as_ref(),
|
||||
Self::CompactionTrigger { .. } | Self::Other => None,
|
||||
Self::CompactionTrigger { .. } | Self::AdditionalTools { .. } | Self::Other => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1346,7 +1356,7 @@ impl ResponseItem {
|
||||
internal_chat_message_metadata_passthrough: metadata,
|
||||
..
|
||||
} => Some(metadata),
|
||||
Self::CompactionTrigger { .. } | Self::Other => None,
|
||||
Self::CompactionTrigger { .. } | Self::AdditionalTools { .. } | Self::Other => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2237,6 +2247,14 @@ mod tests {
|
||||
item.set_id(/*new_id*/ None);
|
||||
|
||||
assert_eq!(item.id(), None);
|
||||
|
||||
let mut additional_tools = ResponseItem::AdditionalTools {
|
||||
id: None,
|
||||
role: "developer".to_string(),
|
||||
tools: Vec::new(),
|
||||
};
|
||||
additional_tools.set_id(Some("at_test".to_string()));
|
||||
assert_eq!(additional_tools.id(), Some("at_test"));
|
||||
}
|
||||
|
||||
fn response_item_with_passthrough_metadata(
|
||||
|
||||
Reference in New Issue
Block a user