mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Preserve native multi-agent calls in Guardian review history (#57448)
## Why Native multi-agent calls must stay intact for backend decryption during Guardian review. ## What changed When `guardian_native_multi_agent_history` is enabled for multi-agent v2, preserve `spawn_agent`, `send_message`, `followup_task`, and `interrupt_agent` function calls in the configured tool namespace as native transcript items. Use `functions` when no namespace is configured. Include the paired evidence-only output in token accounting, and omit native evidence whole when limits require it. ## Testing Extend transcript tests to cover native call ordering, paired-output budgeting, and whole-item omission. Add a native-history snapshot alongside the existing text-history delegation handoff scenario. GitOrigin-RevId: e7d9b4f5ea772890bf14b79fdb53b0f9d0a842e4
This commit is contained in:
@@ -149,7 +149,7 @@ fn required_context(text: String) -> ComposedContext {
|
||||
};
|
||||
let context = super::super::prompt::collect_guardian_context(
|
||||
&Vec::<ResponseItem>::new(),
|
||||
super::super::GUARDIAN_MAX_TOOL_ENTRY_TOKENS,
|
||||
&ContextProfile::synchronous(),
|
||||
&[],
|
||||
&[],
|
||||
Some(&action),
|
||||
|
||||
@@ -68,10 +68,11 @@ pub(crate) use codex_guardian_reviewer::REVIEW_TIMEOUT as GUARDIAN_REVIEW_TIMEOU
|
||||
pub(crate) const GUARDIAN_REVIEWER_NAME: &str = "guardian";
|
||||
pub(crate) const AUTO_REVIEW_DENIED_ACTION_APPROVAL_DEVELOPER_PREFIX: &str =
|
||||
codex_guardian_context::MANUAL_APPROVAL_DEVELOPER_PREFIX;
|
||||
const GUARDIAN_MAX_TOOL_ENTRY_TOKENS: usize = codex_guardian_context::ContextProfile::synchronous()
|
||||
.transcript
|
||||
.entry_limits
|
||||
.tool_tokens;
|
||||
const GUARDIAN_MAX_TOOL_ENTRY_TOKENS: usize = {
|
||||
const PROFILE: &codex_guardian_context::ContextProfile =
|
||||
&codex_guardian_context::ContextProfile::synchronous();
|
||||
PROFILE.transcript.entry_limits.tool_tokens
|
||||
};
|
||||
pub(crate) const GUARDIAN_MAX_ROOT_MESSAGE_TOKENS: usize = 900;
|
||||
pub(crate) const GUARDIAN_MAX_NODE_REPL_TOOL_RESULT_TOKENS: usize = 6_000;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use codex_extension_api::ConversationHistorySnapshot;
|
||||
use codex_features::Feature;
|
||||
use codex_guardian_context::Budgeted;
|
||||
use codex_guardian_context::CollectedContext;
|
||||
use codex_guardian_context::ComposedContext;
|
||||
@@ -174,12 +175,35 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
|
||||
.map_or(reviewed_node_repl_evidence_sequence, |snapshot| {
|
||||
snapshot.sequence
|
||||
});
|
||||
let config = session.get_config().await;
|
||||
let mut profile = ContextProfile::synchronous();
|
||||
profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit;
|
||||
profile.transcript.options.native_multi_agent_namespace = parent_context
|
||||
.is_some_and(|context| {
|
||||
let turn = context.turn();
|
||||
turn.config
|
||||
.features
|
||||
.enabled(Feature::GuardianNativeMultiAgentHistory)
|
||||
&& turn.multi_agent_version == codex_protocol::protocol::MultiAgentVersion::V2
|
||||
})
|
||||
.then(|| {
|
||||
config
|
||||
.multi_agent_v2
|
||||
.tool_namespace
|
||||
.clone()
|
||||
.filter(|namespace| !namespace.is_empty())
|
||||
.unwrap_or_else(|| "functions".to_owned())
|
||||
});
|
||||
profile.transcript_format = match parent_context {
|
||||
Some(context) => context.turn().config.guardian_transcript_mode,
|
||||
None => config.guardian_transcript_mode,
|
||||
};
|
||||
let sections = collect_guardian_context(
|
||||
&GuardianReviewHistory {
|
||||
history,
|
||||
use_parent_checkpoint,
|
||||
},
|
||||
node_repl_result_token_limit,
|
||||
&profile,
|
||||
root_authorization.as_deref().unwrap_or_default(),
|
||||
&trusted_user_inputs,
|
||||
Some(&planned_action),
|
||||
@@ -213,12 +237,6 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
|
||||
},
|
||||
),
|
||||
};
|
||||
let mut profile = ContextProfile::synchronous();
|
||||
profile.transcript_format = match parent_context {
|
||||
Some(context) => context.turn().config.guardian_transcript_mode,
|
||||
None => session.get_config().await.guardian_transcript_mode,
|
||||
};
|
||||
profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit;
|
||||
let mut transcript = profile.prepare_transcript(transcript_entries, offset);
|
||||
if transcript_entries.is_empty() {
|
||||
transcript.items.push(Budgeted::required(
|
||||
@@ -256,7 +274,7 @@ pub(crate) fn render_guardian_transcript_entries(
|
||||
.map(|item| match item.content {
|
||||
codex_guardian_context::TranscriptContent::Text(text) => text,
|
||||
codex_guardian_context::TranscriptContent::Record(record) => record.to_string(),
|
||||
codex_guardian_context::TranscriptContent::AgentMessage(_) => {
|
||||
codex_guardian_context::TranscriptContent::NativeMessage(_) => {
|
||||
panic!("expected text transcript")
|
||||
}
|
||||
})
|
||||
@@ -277,15 +295,13 @@ pub(crate) fn render_guardian_transcript_entries(
|
||||
/// The cursor counts every non-empty evidence entry.
|
||||
pub(super) fn collect_guardian_context(
|
||||
history: &dyn SectionHistory,
|
||||
node_repl_result_token_limit: usize,
|
||||
profile: &ContextProfile,
|
||||
root_conversation: &[GuardianRootMessage],
|
||||
trusted_user_answers: &[codex_guardian_context::TrustedUserAnswer],
|
||||
planned_action: Option<&PlannedAction>,
|
||||
permissions: Option<&GuardianPermissionContext>,
|
||||
node_repl: Option<&codex_guardian_context::NodeReplContext<'_>>,
|
||||
) -> Result<CollectedContext, SectionError> {
|
||||
let mut profile = ContextProfile::synchronous();
|
||||
profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit;
|
||||
default_registry().prepare(&SectionInput {
|
||||
target: profile.target,
|
||||
history: &FilteredGuardianHistory(history),
|
||||
|
||||
@@ -1032,9 +1032,11 @@ fn collect_guardian_transcript_entries(
|
||||
history: &dyn codex_guardian_context::SectionHistory,
|
||||
node_repl_result_token_limit: usize,
|
||||
) -> Vec<ConversationTranscriptEntry> {
|
||||
let mut profile = codex_guardian_context::ContextProfile::synchronous();
|
||||
profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit;
|
||||
prompt::collect_guardian_context(
|
||||
history,
|
||||
node_repl_result_token_limit,
|
||||
&profile,
|
||||
&[],
|
||||
&[],
|
||||
/*planned_action*/ None,
|
||||
|
||||
Reference in New Issue
Block a user