mirror of
https://github.com/openai/codex.git
synced 2026-04-30 11:21:34 +03:00
feat: add post-compaction sub-agent infos (#12774)
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -238,15 +238,34 @@ fn canonicalize_snapshot_text(text: &str) -> String {
|
||||
return "<AGENTS_MD>".to_string();
|
||||
}
|
||||
if text.starts_with("<environment_context>") {
|
||||
let subagent_count = text
|
||||
.split_once("<subagents>")
|
||||
.and_then(|(_, rest)| rest.split_once("</subagents>"))
|
||||
.map(|(subagents, _)| {
|
||||
subagents
|
||||
.lines()
|
||||
.filter(|line| line.trim_start().starts_with("- "))
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0);
|
||||
let subagents_suffix = if subagent_count > 0 {
|
||||
format!(":subagents={subagent_count}")
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
if let (Some(cwd_start), Some(cwd_end)) = (text.find("<cwd>"), text.find("</cwd>")) {
|
||||
let cwd = &text[cwd_start + "<cwd>".len()..cwd_end];
|
||||
return if cwd.ends_with("PRETURN_CONTEXT_DIFF_CWD") {
|
||||
"<ENVIRONMENT_CONTEXT:cwd=PRETURN_CONTEXT_DIFF_CWD>".to_string()
|
||||
format!("<ENVIRONMENT_CONTEXT:cwd=PRETURN_CONTEXT_DIFF_CWD{subagents_suffix}>")
|
||||
} else {
|
||||
"<ENVIRONMENT_CONTEXT:cwd=<CWD>>".to_string()
|
||||
format!("<ENVIRONMENT_CONTEXT:cwd=<CWD>{subagents_suffix}>")
|
||||
};
|
||||
}
|
||||
return "<ENVIRONMENT_CONTEXT>".to_string();
|
||||
return if subagent_count > 0 {
|
||||
format!("<ENVIRONMENT_CONTEXT{subagents_suffix}>")
|
||||
} else {
|
||||
"<ENVIRONMENT_CONTEXT>".to_string()
|
||||
};
|
||||
}
|
||||
if text.starts_with("You are performing a CONTEXT CHECKPOINT COMPACTION.") {
|
||||
return "<SUMMARIZATION_PROMPT>".to_string();
|
||||
@@ -308,6 +327,28 @@ mod tests {
|
||||
assert_eq!(rendered, "00:message/user:<AGENTS_MD>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redacted_text_mode_normalizes_environment_context_with_subagents() {
|
||||
let items = vec![json!({
|
||||
"type": "message",
|
||||
"role": "user",
|
||||
"content": [{
|
||||
"type": "input_text",
|
||||
"text": "<environment_context>\n <cwd>/tmp/example</cwd>\n <shell>bash</shell>\n <subagents>\n - agent-1: atlas\n - agent-2\n </subagents>\n</environment_context>"
|
||||
}]
|
||||
})];
|
||||
|
||||
let rendered = format_response_items_snapshot(
|
||||
&items,
|
||||
&ContextSnapshotOptions::default().render_mode(ContextSnapshotRenderMode::RedactedText),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
rendered,
|
||||
"00:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>:subagents=2>"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_only_message_is_rendered_as_non_text_span() {
|
||||
let items = vec![json!({
|
||||
|
||||
Reference in New Issue
Block a user