mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Support typed content in contextual prompt fragments (#54776)
## Why Contextual fragments and extension-owned world-state sections currently return strings, limiting them to text content. ## What changed - Return `ContentItem` from fragment bodies and rendering, preserving classification and attribution. Apply text markers only to `InputText`; pass other content through unchanged. - Allow extension prompt and world-state contributions to carry typed content, and preserve media in context-window hints. - Hash non-text world-state fragments by their serialized content and role while retaining the existing text hashing behavior. - Add shared content-to-tool-output conversion that preserves image references, image detail, and audio. ## Testing Add coverage for typed world-state hashing and preservation of image content and attribution. Expand code-mode output tests to cover input text, output text, file-backed and inline images, and audio. GitOrigin-RevId: 2ed00d466a3f169b151202f3eef71e667ea64be1
This commit is contained in:
@@ -7512,7 +7512,7 @@ await tools.exec_command({ cmd: "printf second", sandbox_permissions: "require_e
|
||||
COMPACTION_SUMMARY
|
||||
);
|
||||
for request in &guardian_requests {
|
||||
assert!(!request.has_content_kinds(&["token_budget.context_window"]));
|
||||
assert!(!request.has_content_kinds(&["token_budget.context_window"; 3]));
|
||||
}
|
||||
}
|
||||
let parent_request = requests.last().expect("parent turn should complete");
|
||||
|
||||
@@ -209,7 +209,7 @@ async fn first_request_item_types_roles_and_content_annotations() -> Result<()>
|
||||
message developer ["model.base_instructions"]
|
||||
message developer ["guardian.approved_action"]
|
||||
message developer ["generic.developer_instructions","token_budget.context_window_guidance","permissions.instructions","environments.instructions"]
|
||||
message developer ["token_budget.context_window"]
|
||||
message developer ["token_budget.context_window","token_budget.context_window","token_budget.context_window"]
|
||||
message developer ["multi_agent.usage_hint"]
|
||||
message developer ["multi_agent.mode_instructions"]
|
||||
message user ["environments.environment_context"]
|
||||
|
||||
@@ -22,6 +22,7 @@ use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
use codex_protocol::request_user_input::RequestUserInputAnswer;
|
||||
use codex_protocol::request_user_input::RequestUserInputResponse;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_protocol_test_support::ContentItemTestExt;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use core_test_support::skip_if_sandbox;
|
||||
@@ -325,7 +326,7 @@ async fn guardian_authorization_revision_survives_compaction_not_user_input() ->
|
||||
InternalContextSource::from_static("goal"),
|
||||
"Inspecting the deployment.",
|
||||
);
|
||||
let notification_text = internal_context.render();
|
||||
let notification_text = internal_context.render().expect_text();
|
||||
test.codex
|
||||
.inject_response_items(vec![ContextualUserFragment::into(internal_context)])
|
||||
.await?;
|
||||
|
||||
@@ -664,11 +664,11 @@ async fn guardian_review_recovers_after_compaction(
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
requests[0].has_content_kinds(&["token_budget.context_window"]),
|
||||
requests[0].has_content_kinds(&["token_budget.context_window"; 3]),
|
||||
!with_parent_checkpoint
|
||||
);
|
||||
for request in &guardian_requests {
|
||||
assert!(!request.has_content_kinds(&["token_budget.context_window"]));
|
||||
assert!(!request.has_content_kinds(&["token_budget.context_window"; 3]));
|
||||
}
|
||||
let compact_requests = requests
|
||||
.iter()
|
||||
|
||||
@@ -63,6 +63,7 @@ use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::models::PermissionProfileSnapshot;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::models::SandboxPermissions;
|
||||
use codex_protocol::models::input_text;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
@@ -209,7 +210,7 @@ impl ContextContributor for ReadyCapabilityRootsTestExtension {
|
||||
Some(RenderedWorldStateFragment::new(
|
||||
"user",
|
||||
("<ready_capability_roots>", "</ready_capability_roots>"),
|
||||
body.clone(),
|
||||
input_text(body.clone()),
|
||||
)),
|
||||
)
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Multi-turn Astra scenarios snapshot the model-visible request history of shipped features.
|
||||
|
||||
use codex_protocol_test_support::ContentItemTestExt;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
@@ -513,7 +514,9 @@ async fn astra_asks_an_async_question_and_receives_the_answer_while_working() ->
|
||||
.await;
|
||||
|
||||
let question_id = json!(["request_user_input_async", "audience-question", 0]).to_string();
|
||||
let answer = AnsweredQuestion::new(&question_id, question, "Customers").render();
|
||||
let answer = AnsweredQuestion::new(&question_id, question, "Customers")
|
||||
.render()
|
||||
.expect_text();
|
||||
test.codex
|
||||
.steer_turn(TurnInputRequest::user_input(vec![text(&answer)]), turn_id)
|
||||
.await?;
|
||||
|
||||
+17
-13
@@ -32,12 +32,14 @@ Settings:
|
||||
<MODEL_INSTRUCTIONS>
|
||||
02:message/developer:
|
||||
<PERMISSIONS_INSTRUCTIONS>
|
||||
03:message/developer:
|
||||
<context_window>
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 1>
|
||||
</context_window>
|
||||
03:message/developer[3]:
|
||||
[01] <context_window>
|
||||
[02]
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 1>
|
||||
|
||||
[03] </context_window>
|
||||
04:message/user:
|
||||
<ENVIRONMENT_CONTEXT>
|
||||
05:message/user:
|
||||
@@ -67,13 +69,15 @@ Settings: same as window 1
|
||||
<MODEL_INSTRUCTIONS>
|
||||
02:message/developer:
|
||||
<PERMISSIONS_INSTRUCTIONS>
|
||||
03:message/developer:
|
||||
<context_window>
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 2>
|
||||
Previous context window id: <UUID 1>
|
||||
</context_window>
|
||||
03:message/developer[3]:
|
||||
[01] <context_window>
|
||||
[02]
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 2>
|
||||
Previous context window id: <UUID 1>
|
||||
|
||||
[03] </context_window>
|
||||
04:message/user:
|
||||
<ENVIRONMENT_CONTEXT>
|
||||
05:message/user:
|
||||
|
||||
+8
-6
@@ -71,12 +71,14 @@ Settings:
|
||||
|
||||
Never use the `request_user_input` tool for permission requests or permission-related escalations.
|
||||
</collaboration_mode>
|
||||
03:message/developer:
|
||||
<context_window>
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 1>
|
||||
</context_window>
|
||||
03:message/developer[3]:
|
||||
[01] <context_window>
|
||||
[02]
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 1>
|
||||
|
||||
[03] </context_window>
|
||||
04:message/developer:
|
||||
<multi_agent_role>You are `/root`, the primary agent in a team of agents collaborating to fulfill the user's goals.
|
||||
|
||||
|
||||
+9
-7
@@ -11,13 +11,15 @@ Scenario: New context window tool installs fresh full context before the next fo
|
||||
01:message/developer[2]:
|
||||
[01] <SKILLS_INSTRUCTIONS>
|
||||
[02] <PERMISSIONS_INSTRUCTIONS>
|
||||
02:message/developer:
|
||||
<context_window>
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 2>
|
||||
Previous context window id: <UUID 1>
|
||||
</context_window>
|
||||
02:message/developer[3]:
|
||||
[01] <context_window>
|
||||
[02]
|
||||
Agent name: /root
|
||||
First context window id: <UUID 1>
|
||||
Current context window id: <UUID 2>
|
||||
Previous context window id: <UUID 1>
|
||||
|
||||
[03] </context_window>
|
||||
03:message/user:
|
||||
<ENVIRONMENT_CONTEXT>
|
||||
04:function_call/update_plan:{"plan":[{"status":"in_progress","step":"Continue in the new context window"}]}
|
||||
|
||||
@@ -1900,8 +1900,9 @@ async fn spawned_full_history_v2_child_uses_model_precedence_without_dropping_co
|
||||
vec![json!("/root"), json!("/root/worker")]
|
||||
);
|
||||
let context_windows = child_request
|
||||
.message_input_texts("developer")
|
||||
.message_input_text_groups("developer")
|
||||
.into_iter()
|
||||
.map(|parts| parts.concat())
|
||||
.filter(|text| text.starts_with("<context_window>\n"))
|
||||
.collect::<Vec<_>>();
|
||||
let identities = context_windows
|
||||
@@ -1946,10 +1947,9 @@ async fn spawned_full_history_v2_child_uses_model_precedence_without_dropping_co
|
||||
);
|
||||
assert!(
|
||||
child_request.has_message_with_input_texts("developer", |message| {
|
||||
matches!(
|
||||
message,
|
||||
[text] if text.starts_with("<context_window>\nAgent name: /root/worker\n")
|
||||
)
|
||||
message
|
||||
.concat()
|
||||
.starts_with("<context_window>\nAgent name: /root/worker\n")
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ async fn token_budget_guidance_precedes_standalone_context_window(
|
||||
"token_budget.context_window_guidance",
|
||||
"permissions.instructions",
|
||||
]));
|
||||
assert!(request.has_content_kinds(&["token_budget.context_window"]));
|
||||
assert!(request.has_content_kinds(&["token_budget.context_window"; 3]));
|
||||
let developer_texts = request.message_input_texts("developer");
|
||||
let context_window_index = developer_texts
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user