mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Record base instructions in incremental tool history (#51188)
## What changed - Record nonempty base instructions as a developer message after tool declarations at the start of each incremental tool context window, and omit the request-level `instructions` field. - Preserve this prefix when rebuilding history after local or remote compaction, while keeping the compaction summary last. - Count recorded base instructions once when estimating context usage and trimming tool outputs. ## Testing Add regression coverage for instruction placement, omission of request-level instructions, compaction ordering, and token accounting. Exercise remote compaction trimming with both request-level and recorded base instructions. GitOrigin-RevId: 6a6fda92c5c6eb33852a77b38d34c028cf78b164
This commit is contained in:
@@ -1117,20 +1117,23 @@ async fn compaction_initial_context_preserves_separate_guardian_developer_messag
|
||||
.await
|
||||
.expect("world state should build"),
|
||||
);
|
||||
let (refreshed, _) =
|
||||
crate::compact::build_compaction_initial_context(&session, &step_context, &world_state)
|
||||
.await;
|
||||
let (refreshed, _) = crate::compact::build_compaction_replacement_history(
|
||||
&session,
|
||||
&step_context,
|
||||
&world_state,
|
||||
Vec::new(),
|
||||
)
|
||||
.await;
|
||||
|
||||
let developer_messages = refreshed
|
||||
.iter()
|
||||
.filter_map(|envelope| match &envelope.item {
|
||||
.map(|item| &item.item)
|
||||
.filter_map(|item| match item {
|
||||
ResponseItem::Message { role, content, .. } if role == "developer" => {
|
||||
crate::content_items_to_text(content).map(|text| {
|
||||
(
|
||||
text,
|
||||
envelope
|
||||
.item
|
||||
.executed_tool_call_metadata()
|
||||
item.executed_tool_call_metadata()
|
||||
.and_then(|metadata| metadata.content_item_kinds.clone()),
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user