mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Support plaintext collaboration tool messages (#35845)
## What changed - Preserve `encrypted_function_args` on function calls so an empty list can mark plaintext collaboration arguments across request replay. - Deliver `spawn_agent`, `send_message`, and `followup_task` payloads as structured plaintext agent messages when that marker is present; retain encrypted delivery otherwise. - Redact plaintext collaboration arguments from tool and communication logs, and omit the metadata when sending requests to non-OpenAI providers. ## Testing - Cover serialization of empty encrypted-argument metadata and plaintext versus encrypted subagent message delivery. - Verify plaintext tool arguments are redacted and provider-specific metadata is removed from non-OpenAI requests. GitOrigin-RevId: 64db98ff0b61a3af2f04ed609292363f2e2362a8
This commit is contained in:
1 parent
166658a34a
commit
03edf16f0b
36 files changed
+390
-76
No files matched your search
@@ -2,6 +2,9 @@
|
||||
|
||||
use crate::agent::AgentStatus;
|
||||
use crate::agent::agent_resolver::resolve_agent_target;
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::context::InterAgentMessage;
|
||||
use crate::context::InterAgentMessageType;
|
||||
use crate::function_tool::FunctionCallError;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
use crate::tools::context::ToolOutput;
|
||||
@@ -51,16 +54,31 @@ pub(crate) async fn emit_sub_agent_activity(
|
||||
session.emit_turn_item_completed(turn, item).await;
|
||||
}
|
||||
|
||||
pub(super) fn communication_from_tool_message(
|
||||
fn communication_from_tool_message(
|
||||
author: AgentPath,
|
||||
recipient: AgentPath,
|
||||
message: String,
|
||||
source: &crate::tools::context::ToolCallSource,
|
||||
trigger_turn: bool,
|
||||
) -> InterAgentCommunication {
|
||||
InterAgentCommunication::new_encrypted(
|
||||
author,
|
||||
recipient,
|
||||
Vec::new(),
|
||||
message,
|
||||
/*trigger_turn*/ true,
|
||||
)
|
||||
if !matches!(
|
||||
source,
|
||||
crate::tools::context::ToolCallSource::DirectPlaintextMessage
|
||||
) {
|
||||
return InterAgentCommunication::new_encrypted(
|
||||
author,
|
||||
recipient,
|
||||
Vec::new(),
|
||||
message,
|
||||
trigger_turn,
|
||||
);
|
||||
}
|
||||
let message_type = if trigger_turn {
|
||||
InterAgentMessageType::NewTask
|
||||
} else {
|
||||
InterAgentMessageType::Message
|
||||
};
|
||||
let content =
|
||||
InterAgentMessage::new(message_type, recipient.clone(), author.clone(), message).render();
|
||||
InterAgentCommunication::new(author, recipient, Vec::new(), content, trigger_turn)
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use super::*;
|
||||
use crate::agent_communication::AgentCommunicationContext;
|
||||
use crate::agent_communication::AgentCommunicationKind;
|
||||
use crate::tools::context::FunctionToolOutput;
|
||||
use codex_protocol::protocol::InterAgentCommunication;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum MessageDeliveryMode {
|
||||
@@ -16,17 +15,10 @@ pub(crate) enum MessageDeliveryMode {
|
||||
}
|
||||
|
||||
impl MessageDeliveryMode {
|
||||
/// Returns whether the produced communication should start a turn immediately.
|
||||
fn apply(self, communication: InterAgentCommunication) -> InterAgentCommunication {
|
||||
fn trigger_turn(self) -> bool {
|
||||
match self {
|
||||
Self::QueueOnly => InterAgentCommunication {
|
||||
trigger_turn: false,
|
||||
..communication
|
||||
},
|
||||
Self::TriggerTurn => InterAgentCommunication {
|
||||
trigger_turn: true,
|
||||
..communication
|
||||
},
|
||||
Self::QueueOnly => false,
|
||||
Self::TriggerTurn => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +60,7 @@ pub(crate) async fn handle_message_string_tool(
|
||||
session,
|
||||
turn,
|
||||
call_id,
|
||||
source,
|
||||
..
|
||||
} = invocation;
|
||||
let receiver_thread_id = resolve_agent_target(&session, &turn, &target).await?;
|
||||
@@ -100,8 +93,13 @@ pub(crate) async fn handle_message_string_tool(
|
||||
.session_source
|
||||
.get_agent_path()
|
||||
.unwrap_or_else(AgentPath::root);
|
||||
let communication =
|
||||
communication_from_tool_message(author, receiver_agent_path.clone(), message);
|
||||
let communication = communication_from_tool_message(
|
||||
author,
|
||||
receiver_agent_path.clone(),
|
||||
message,
|
||||
&source,
|
||||
mode.trigger_turn(),
|
||||
);
|
||||
let kind = match mode {
|
||||
MessageDeliveryMode::QueueOnly => AgentCommunicationKind::Message,
|
||||
MessageDeliveryMode::TriggerTurn => AgentCommunicationKind::Followup,
|
||||
@@ -112,12 +110,7 @@ pub(crate) async fn handle_message_string_tool(
|
||||
let result = session
|
||||
.services
|
||||
.agent_control
|
||||
.send_inter_agent_communication(
|
||||
receiver_thread_id,
|
||||
mode.apply(communication),
|
||||
context,
|
||||
parent_turn_id,
|
||||
)
|
||||
.send_inter_agent_communication(receiver_thread_id, communication, context, parent_turn_id)
|
||||
.await
|
||||
.map_err(|err| collab_agent_error(receiver_thread_id, err));
|
||||
result?;
|
||||
|
||||
@@ -44,18 +44,19 @@ async fn handle_spawn_agent(
|
||||
turn,
|
||||
payload,
|
||||
call_id,
|
||||
source,
|
||||
..
|
||||
} = invocation;
|
||||
let arguments = function_arguments(payload)?;
|
||||
let args: SpawnAgentArgs = parse_arguments(&arguments)?;
|
||||
let fork_mode = args.fork_mode()?;
|
||||
let message = message_content(args.message)?;
|
||||
let role_name = args
|
||||
.agent_type
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|role| !role.is_empty());
|
||||
|
||||
let message = message_content(args.message)?;
|
||||
let session_source = turn.session_source.clone();
|
||||
let child_depth = next_thread_spawn_depth(&session_source);
|
||||
let mut config =
|
||||
@@ -103,7 +104,13 @@ async fn handle_spawn_agent(
|
||||
.session_source
|
||||
.get_agent_path()
|
||||
.unwrap_or_else(AgentPath::root);
|
||||
let communication = communication_from_tool_message(author, new_agent_path.clone(), message);
|
||||
let communication = communication_from_tool_message(
|
||||
author,
|
||||
new_agent_path.clone(),
|
||||
message,
|
||||
&source,
|
||||
/*trigger_turn*/ true,
|
||||
);
|
||||
let context = AgentCommunicationContext::new(AgentCommunicationKind::Spawn, session.thread_id);
|
||||
let spawned_agent = Box::pin(
|
||||
session
|
||||
|
||||
Reference in new issue
Block a user