diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 52c37c51ee..c27a78cc97 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -782,6 +782,28 @@ async fn submission_loop( } }); } + + Op::SummarizeContext => { + let sess = match sess.as_ref() { + Some(sess) => sess, + None => { + send_no_session_event(sub.id).await; + continue; + } + }; + + // Create a summarization request as user input + let summarization_prompt = vec![InputItem::Text { + text: "Please provide a summary of our conversation so far, highlighting key points, decisions made, and any important context that would be useful for future reference. This summary will be used to replace our conversation history with a more concise version so choose what details you will need to continue your work.".to_string(), + }]; + + // attempt to inject input into current task + if let Err(items) = sess.inject_input(summarization_prompt) { + // no current task, spawn a new one + let task = AgentTask::spawn(Arc::clone(sess), sub.id, items); + sess.set_task(task); + } + } } } debug!("Agent loop exited"); diff --git a/codex-rs/core/src/protocol.rs b/codex-rs/core/src/protocol.rs index fa25a2fe38..dafd001dd6 100644 --- a/codex-rs/core/src/protocol.rs +++ b/codex-rs/core/src/protocol.rs @@ -108,6 +108,11 @@ pub enum Op { /// Request a single history entry identified by `log_id` + `offset`. GetHistoryEntryRequest { offset: usize, log_id: u64 }, + + /// Request the agent to summarize the current conversation context. + /// The agent will use its existing context (either conversation history or previous response id) + /// to generate a summary which will be returned as an AgentMessage event. + SummarizeContext, } /// Determines the conditions under which the user is consulted to approve