mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add aggregate budget enforcement for Guardian context (#44166)
## What changed Add `ComposedContext::enforce_budget` to fit evidence within the input token allowance after reserving existing context. Preserve required content and message boundaries, reserve an omission notice, and return an error if required evidence cannot fit. Carry retention policies through transcript rendering and composition. Protect user messages, protected messages, and the newest five tool entries. Remove oversized optional items first, then evict commentary, older tool evidence, and images in priority order. Add image admission support and record omitted content in truncation observations. ## Testing Add tests for existing-context reservations, required-message preservation, image omission, framing costs, and protection of the newest five tool entries in both context profiles. GitOrigin-RevId: 8a0f245bad82f562323b4533442385ddbcb6e541
This commit is contained in:
1 parent
d3ffbbed5a
commit
17e64839eb
13 files changed
+666
-76
No files matched your search
@@ -30,8 +30,11 @@ fn profiles_preserve_distinct_retention_and_original_numbering() {
|
||||
(sync.items, sync.omission_note),
|
||||
(
|
||||
vec![
|
||||
"[8] user: inspect only".to_owned(),
|
||||
"[10] assistant: working".to_owned()
|
||||
Budgeted::required("[8] user: inspect only".to_owned()),
|
||||
Budgeted::optional(
|
||||
"[10] assistant: working".to_owned(),
|
||||
BudgetPriority::Commentary
|
||||
)
|
||||
],
|
||||
Some("Some conversation entries were omitted.".to_owned()),
|
||||
),
|
||||
@@ -40,8 +43,8 @@ fn profiles_preserve_distinct_retention_and_original_numbering() {
|
||||
(asynchronous.items, asynchronous.omission_note),
|
||||
(
|
||||
vec![
|
||||
"[1] user: inspect only\n".to_owned(),
|
||||
"[2] developer: approved action\n".to_owned()
|
||||
Budgeted::required("[1] user: inspect only\n".to_owned()),
|
||||
Budgeted::required("[2] developer: approved action\n".to_owned())
|
||||
],
|
||||
None,
|
||||
),
|
||||
@@ -59,3 +62,37 @@ fn profiles_preserve_distinct_retention_and_original_numbering() {
|
||||
vec![("transcript_message", "working".len(), 0)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn profiles_reserve_the_newest_five_tool_entries_for_aggregate_enforcement() {
|
||||
let entries = (0..8)
|
||||
.map(|index| ConversationTranscriptEntry {
|
||||
kind: ConversationTranscriptEntryKind::ToolOutput("tool result".to_owned()),
|
||||
text: format!("result {index}"),
|
||||
original_bytes: 8,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
for profile in [
|
||||
ContextProfile::synchronous(),
|
||||
ContextProfile::asynchronous(),
|
||||
] {
|
||||
let transcript = profile.render_transcript(&entries, /*entry_number_offset*/ 0);
|
||||
assert_eq!(
|
||||
transcript
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| item.retention)
|
||||
.collect::<Vec<_>>(),
|
||||
vec![
|
||||
Retention::Optional(BudgetPriority::Tool),
|
||||
Retention::Optional(BudgetPriority::Tool),
|
||||
Retention::Optional(BudgetPriority::Tool),
|
||||
Retention::Required,
|
||||
Retention::Required,
|
||||
Retention::Required,
|
||||
Retention::Required,
|
||||
Retention::Required
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user