mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Update guardian output schema (#17061)
## Summary - Update guardian output schema to separate risk, authorization, outcome, and rationale. - Feed guardian rationale into rejection messages. - Split the guardian policy into template and tenant-config sections. ## Validation - `cargo test -p codex-core mcp_tool_call` - `env -u CODEX_SANDBOX_NETWORK_DISABLED INSTA_UPDATE=always cargo test -p codex-core guardian::` --------- Co-authored-by: Owen Lin <owen@openai.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
//! The guardian clones the parent config, so it inherits any managed
|
||||
//! network proxy / allowlist that the parent turn already had.
|
||||
//! 3. Fail closed on timeout, execution failure, or malformed output.
|
||||
//! 4. Approve only low- and medium-risk actions (`risk_score < 80`).
|
||||
//! 4. Apply the guardian's explicit allow/deny outcome.
|
||||
|
||||
mod approval_request;
|
||||
mod prompt;
|
||||
@@ -24,7 +24,7 @@ use serde::Serialize;
|
||||
pub(crate) use approval_request::GuardianApprovalRequest;
|
||||
pub(crate) use approval_request::GuardianMcpAnnotations;
|
||||
pub(crate) use approval_request::guardian_approval_request_to_json;
|
||||
pub(crate) use review::GUARDIAN_REJECTION_MESSAGE;
|
||||
pub(crate) use review::guardian_rejection_message;
|
||||
pub(crate) use review::is_guardian_reviewer_source;
|
||||
pub(crate) use review::review_approval_request;
|
||||
pub(crate) use review::review_approval_request_with_cancel;
|
||||
@@ -39,24 +39,24 @@ const GUARDIAN_MAX_TOOL_TRANSCRIPT_TOKENS: usize = 10_000;
|
||||
const GUARDIAN_MAX_MESSAGE_ENTRY_TOKENS: usize = 2_000;
|
||||
const GUARDIAN_MAX_TOOL_ENTRY_TOKENS: usize = 1_000;
|
||||
const GUARDIAN_MAX_ACTION_STRING_TOKENS: usize = 16_000;
|
||||
const GUARDIAN_APPROVAL_RISK_THRESHOLD: u8 = 80;
|
||||
const GUARDIAN_RECENT_ENTRY_LIMIT: usize = 40;
|
||||
const TRUNCATION_TAG: &str = "truncated";
|
||||
|
||||
/// Evidence item returned by the guardian reviewer.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub(crate) struct GuardianEvidence {
|
||||
pub(crate) message: String,
|
||||
pub(crate) why: String,
|
||||
/// Final allow/deny outcome returned by the guardian reviewer.
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub(crate) enum GuardianAssessmentOutcome {
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
/// Structured output contract that the guardian reviewer must satisfy.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub(crate) struct GuardianAssessment {
|
||||
pub(crate) risk_level: codex_protocol::protocol::GuardianRiskLevel,
|
||||
pub(crate) risk_score: u8,
|
||||
pub(crate) user_authorization: codex_protocol::protocol::GuardianUserAuthorization,
|
||||
pub(crate) outcome: GuardianAssessmentOutcome,
|
||||
pub(crate) rationale: String,
|
||||
pub(crate) evidence: Vec<GuardianEvidence>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -78,6 +78,8 @@ use prompt::guardian_output_schema;
|
||||
#[cfg(test)]
|
||||
pub(crate) use prompt::guardian_policy_prompt;
|
||||
#[cfg(test)]
|
||||
pub(crate) use prompt::guardian_policy_prompt_with_config;
|
||||
#[cfg(test)]
|
||||
use prompt::guardian_truncate_text;
|
||||
#[cfg(test)]
|
||||
use prompt::parse_guardian_assessment;
|
||||
|
||||
Reference in New Issue
Block a user