Skip to content

Commit 591cb61

Browse files
authored
Always send entire request context (openai#1641)
Always store the entire conversation history. Request encrypted COT when not storing Responses. Send entire input context instead of sending previous_response_id
1 parent d6c4083 commit 591cb61

File tree

8 files changed

+101
-325
lines changed

8 files changed

+101
-325
lines changed

codex-rs/core/src/chat_completions.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) async fn stream_chat_completions(
4141

4242
for item in &prompt.input {
4343
match item {
44-
ResponseItem::Message { role, content } => {
44+
ResponseItem::Message { role, content, .. } => {
4545
let mut text = String::new();
4646
for c in content {
4747
match c {
@@ -58,6 +58,7 @@ pub(crate) async fn stream_chat_completions(
5858
name,
5959
arguments,
6060
call_id,
61+
..
6162
} => {
6263
messages.push(json!({
6364
"role": "assistant",
@@ -259,6 +260,7 @@ async fn process_chat_sse<S>(
259260
content: vec![ContentItem::OutputText {
260261
text: content.to_string(),
261262
}],
263+
id: None,
262264
};
263265

264266
let _ = tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
@@ -300,6 +302,7 @@ async fn process_chat_sse<S>(
300302
"tool_calls" if fn_call_state.active => {
301303
// Build the FunctionCall response item.
302304
let item = ResponseItem::FunctionCall {
305+
id: None,
303306
name: fn_call_state.name.clone().unwrap_or_else(|| "".to_string()),
304307
arguments: fn_call_state.arguments.clone(),
305308
call_id: fn_call_state.call_id.clone().unwrap_or_else(String::new),
@@ -402,6 +405,7 @@ where
402405
}))) => {
403406
if !this.cumulative.is_empty() {
404407
let aggregated_item = crate::models::ResponseItem::Message {
408+
id: None,
405409
role: "assistant".to_string(),
406410
content: vec![crate::models::ContentItem::OutputText {
407411
text: std::mem::take(&mut this.cumulative),

codex-rs/core/src/client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ impl ModelClient {
117117
let full_instructions = prompt.get_full_instructions(&self.config.model);
118118
let tools_json = create_tools_json_for_responses_api(prompt, &self.config.model)?;
119119
let reasoning = create_reasoning_param_for_request(&self.config, self.effort, self.summary);
120+
121+
// Request encrypted COT if we are not storing responses,
122+
// otherwise reasoning items will be referenced by ID
123+
let include = if !prompt.store && reasoning.is_some() {
124+
vec!["reasoning.encrypted_content".to_string()]
125+
} else {
126+
vec![]
127+
};
128+
120129
let payload = ResponsesApiRequest {
121130
model: &self.config.model,
122131
instructions: &full_instructions,
@@ -125,10 +134,10 @@ impl ModelClient {
125134
tool_choice: "auto",
126135
parallel_tool_calls: false,
127136
reasoning,
128-
previous_response_id: prompt.prev_id.clone(),
129137
store: prompt.store,
130138
// TODO: make this configurable
131139
stream: true,
140+
include,
132141
};
133142

134143
trace!(

codex-rs/core/src/client_common.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const BASE_INSTRUCTIONS: &str = include_str!("../prompt.md");
2222
pub struct Prompt {
2323
/// Conversation context input items.
2424
pub input: Vec<ResponseItem>,
25-
/// Optional previous response ID (when storage is enabled).
26-
pub prev_id: Option<String>,
2725
/// Optional instructions from the user to amend to the built-in agent
2826
/// instructions.
2927
pub user_instructions: Option<String>,
@@ -133,11 +131,10 @@ pub(crate) struct ResponsesApiRequest<'a> {
133131
pub(crate) tool_choice: &'static str,
134132
pub(crate) parallel_tool_calls: bool,
135133
pub(crate) reasoning: Option<Reasoning>,
136-
#[serde(skip_serializing_if = "Option::is_none")]
137-
pub(crate) previous_response_id: Option<String>,
138134
/// true when using the Responses API.
139135
pub(crate) store: bool,
140136
pub(crate) stream: bool,
137+
pub(crate) include: Vec<String>,
141138
}
142139

143140
use crate::config::Config;

0 commit comments

Comments
 (0)