Files
codex/codex-rs/prompts/src/multi_agent_instructions_tests.rs
T
tongzhou wang 1b6e0d8145 Track content provenance through prompt assembly and compaction (#53831)
## Why

Message roles and content classifications do not identify who supplied each context part. Source attribution needs to survive prompt assembly and history truncation, including messages that combine text from different producers.

## What changed

- Add per-part `ContentItemMetadata` for user input, developer instructions, `AGENTS.md`, skills, harness context, command hooks, and tool context with optional callable namespaces.
- Carry attribution alongside content and classifications through contextual fragments, extension prompts, hook output, and agent messages. Keep tool-provided context-window hints separate from harness text.
- Preserve the source of retained text slices during compaction and attribute generated truncation notices to the harness. Default missing historical attribution to unknown.
- Attribute host MCP calls using cached tool namespaces only when catalog revisions remain stable, without starting servers or refreshing catalogs for attribution.
- Send the new metadata to Responses Lite and strip it from requests to endpoints that do not support it.

## Testing

Extend compaction tests to cover mixed sources, missing or extra metadata entries, and discarded media. Update Responses Lite request assertions to verify endpoint-specific attribution handling.

GitOrigin-RevId: b0ebc929b7c60f3ec49d1affbf897312d63edcc8
2026-10-14 02:01:49 +00:00

45 lines
1.7 KiB
Rust

//! Covers role composition and attribution for captured model instructions.
use super::*;
use codex_context_fragments::AnnotatedContent;
use codex_context_fragments::RenderedFragment;
use codex_protocol::models::ContentItemMetadata;
use pretty_assertions::assert_eq;
#[test]
fn role_segment_filters_base_and_appends_bundled_guidance() {
let shared = DEFAULT_MULTI_AGENT_V2_SHARED_USAGE_HINT_TEXT;
let wait = DEFAULT_MULTI_AGENT_V2_WAIT_AGENT_USAGE_HINT_TEXT;
let model_override = DEFAULT_MULTI_AGENT_V2_MODEL_OVERRIDE_USAGE_HINT_TEXT;
let expected_body = format!(
"Role.\n## Work\nContinue.\n{shared}\n{wait}\n\nThere are 2 available concurrency slots, meaning that up to 2 agents can be active at once, including you.\n\n{model_override}"
);
for marked in [false, true] {
let instructions = MultiAgentRoleInstructions::Composed {
base: "Role.\n## Plan tool\nOmit role checklist guidance.\n## Work\nContinue."
.to_string(),
marked,
omit_update_plan_instructions: true,
max_concurrency: 2,
wait_agent_enabled: true,
expose_model_overrides: true,
};
let expected_text = if marked {
format!("<multi_agent_role>{expected_body}</multi_agent_role>")
} else {
expected_body.clone()
};
assert_eq!(
instructions.render_fragment(),
RenderedFragment::new(
"developer",
AnnotatedContent::text(
expected_text,
ContentItemKind("multi_agent.role_instructions".to_string()),
ContentItemMetadata::harness(),
),
),
);
}
}