Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions codex-rs/codex-api/src/requests/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,25 @@ impl<'a> ChatRequestBuilder<'a> {
name,
arguments,
call_id,
extra_content,
..
} => {
let mut tool_call_obj = json!({
"id": call_id,
"type": "function",
"function": {
"name": name,
"arguments": arguments,
}
});
// Include extra_content (e.g., Gemini's thought_signature) if present
if let Some(extra) = extra_content {
tool_call_obj["extra_content"] = extra.clone();
}
let mut msg = json!({
"role": "assistant",
"content": null,
"tool_calls": [{
"id": call_id,
"type": "function",
"function": {
"name": name,
"arguments": arguments,
}
}]
"tool_calls": [tool_call_obj]
});
if let Some(reasoning) = reasoning_by_anchor_index.get(&idx)
&& let Some(obj) = msg.as_object_mut()
Expand Down
7 changes: 7 additions & 0 deletions codex-rs/codex-api/src/sse/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub async fn process_chat_sse<S>(
struct ToolCallState {
name: Option<String>,
arguments: String,
extra_content: Option<serde_json::Value>,
}

let mut tool_calls: HashMap<String, ToolCallState> = HashMap::new();
Expand Down Expand Up @@ -171,6 +172,11 @@ pub async fn process_chat_sse<S>(
call_state.arguments.push_str(arguments);
}
}

// Capture extra_content (e.g., Gemini's thought_signature)
if let Some(extra) = tool_call.get("extra_content") {
call_state.extra_content = Some(extra.clone());
}
}
}
}
Expand Down Expand Up @@ -231,6 +237,7 @@ pub async fn process_chat_sse<S>(
name: state.name.unwrap_or_default(),
arguments: state.arguments,
call_id: call_id.clone(),
extra_content: state.extra_content,
};
let _ = tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
}
Expand Down
8 changes: 8 additions & 0 deletions codex-rs/core/src/context_manager/history_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fn remove_first_item_removes_matching_output_for_function_call() {
name: "do_it".to_string(),
arguments: "{}".to_string(),
call_id: "call-1".to_string(),
extra_content: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-1".to_string(),
Expand Down Expand Up @@ -192,6 +193,7 @@ fn remove_first_item_removes_matching_call_for_output() {
name: "do_it".to_string(),
arguments: "{}".to_string(),
call_id: "call-2".to_string(),
extra_content: None,
},
];
let mut h = create_history_with_items(items);
Expand Down Expand Up @@ -471,6 +473,7 @@ fn normalize_adds_missing_output_for_function_call() {
name: "do_it".to_string(),
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
extra_content: None,
}];
let mut h = create_history_with_items(items);

Expand All @@ -484,6 +487,7 @@ fn normalize_adds_missing_output_for_function_call() {
name: "do_it".to_string(),
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
extra_content: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-x".to_string(),
Expand Down Expand Up @@ -614,6 +618,7 @@ fn normalize_mixed_inserts_and_removals() {
name: "f1".to_string(),
arguments: "{}".to_string(),
call_id: "c1".to_string(),
extra_content: None,
},
// Orphan output that should be removed
ResponseItem::FunctionCallOutput {
Expand Down Expand Up @@ -657,6 +662,7 @@ fn normalize_mixed_inserts_and_removals() {
name: "f1".to_string(),
arguments: "{}".to_string(),
call_id: "c1".to_string(),
extra_content: None,
},
ResponseItem::FunctionCallOutput {
call_id: "c1".to_string(),
Expand Down Expand Up @@ -709,6 +715,7 @@ fn normalize_adds_missing_output_for_function_call_panics_in_debug() {
name: "do_it".to_string(),
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
extra_content: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history();
Expand Down Expand Up @@ -786,6 +793,7 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
name: "f1".to_string(),
arguments: "{}".to_string(),
call_id: "c1".to_string(),
extra_content: None,
},
ResponseItem::FunctionCallOutput {
call_id: "c2".to_string(),
Expand Down
1 change: 1 addition & 0 deletions codex-rs/core/src/conversation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ mod tests {
name: "tool".to_string(),
arguments: "{}".to_string(),
call_id: "c1".to_string(),
extra_content: None,
},
assistant_msg("a4"),
];
Expand Down
1 change: 1 addition & 0 deletions codex-rs/core/tests/chat_completions_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ fn function_call() -> ResponseItem {
name: "f".to_string(),
arguments: "{}".to_string(),
call_id: "c1".to_string(),
extra_content: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions codex-rs/core/tests/suite/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
name: "do_thing".into(),
arguments: "{}".into(),
call_id: "function-call-id".into(),
extra_content: None,
});
prompt.input.push(ResponseItem::LocalShellCall {
id: Some("local-shell-id".into()),
Expand Down
5 changes: 5 additions & 0 deletions codex-rs/protocol/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ pub enum ResponseItem {
// Chat Completions + Responses API behavior.
arguments: String,
call_id: String,
/// Provider-specific metadata (e.g., Gemini's `thought_signature`).
/// This field is captured from SSE responses and must be echoed back
/// in subsequent requests for multi-turn tool calling to work correctly.
#[serde(default, skip_serializing_if = "Option::is_none")]
extra_content: Option<serde_json::Value>,
},
// NOTE: The input schema for `function_call_output` objects that clients send to the
// OpenAI /v1/responses endpoint is NOT the same shape as the objects the server returns on the
Expand Down