mirror of
https://github.com/openai/codex.git
synced 2026-11-20 07:06:24 +00:00
Preserve MCP tool output as content items (#40737)
## What changed - Convert unstructured MCP results into typed function-call output items instead of serializing the entire content array as a text string. - Keep structured MCP results as serialized text and preserve media, encrypted content, and unknown content through their existing item conversions. - Drop empty text items during output truncation so they do not consume API array slots. ## Testing - Cover text-only, mixed unstructured, structured, and image-sanitized MCP results. - Verify empty text items are discarded under byte- and token-based truncation policies. GitOrigin-RevId: fa1c5b7dee6f003a094265379dcabdd060386a48
This commit is contained in:
1 parent
62aacbb2c9
commit
75cb7c903d
12 files changed
+288
-104
No files matched your search
@@ -102,6 +102,10 @@ pub fn truncate_function_output_items_with_policy(
|
||||
for item in items {
|
||||
match item {
|
||||
FunctionCallOutputContentItem::InputText { text } => {
|
||||
// Empty text contributes no model content but still consumes an API array slot.
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if remaining_budget == 0 {
|
||||
omitted_text_items += 1;
|
||||
continue;
|
||||
|
||||
@@ -163,6 +163,45 @@ fn truncates_across_multiple_under_limit_texts_and_reports_omitted() {
|
||||
assert!(summary_text.contains("omitted 2 text items"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truncate_function_output_items_with_policy_discards_empty_text() {
|
||||
let mut items = vec![
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: String::new(),
|
||||
};
|
||||
16_384
|
||||
];
|
||||
for policy in [TruncationPolicy::Bytes(0), TruncationPolicy::Tokens(1)] {
|
||||
assert_eq!(
|
||||
truncate_function_output_items_with_policy(&items, policy, |_| 0),
|
||||
Vec::new()
|
||||
);
|
||||
}
|
||||
|
||||
let content = vec![
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: "caption".to_string(),
|
||||
},
|
||||
FunctionCallOutputContentItem::InputImage {
|
||||
image_url: "img:one".to_string(),
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
FunctionCallOutputContentItem::InputAudio {
|
||||
audio_url: "audio:one".to_string(),
|
||||
},
|
||||
FunctionCallOutputContentItem::EncryptedContent {
|
||||
encrypted_content: "enc_opaque".to_string(),
|
||||
},
|
||||
];
|
||||
items.extend(content.clone());
|
||||
for policy in [TruncationPolicy::Bytes(16), TruncationPolicy::Tokens(4)] {
|
||||
assert_eq!(
|
||||
truncate_function_output_items_with_policy(&items, policy, |_| 1),
|
||||
content
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formatted_truncate_text_content_items_with_policy_returns_original_under_limit() {
|
||||
let items = vec![
|
||||
|
||||
Reference in new issue
Block a user