diff --git a/codex-rs/core/src/agent/control.rs b/codex-rs/core/src/agent/control.rs index 49bbab0f87a7..8de64434029b 100644 --- a/codex-rs/core/src/agent/control.rs +++ b/codex-rs/core/src/agent/control.rs @@ -154,12 +154,13 @@ impl AgentControl { state: &Arc, initial_operation: Op, ) -> CodexResult { - let last_task_message = match &initial_operation { - Op::InterAgentCommunication { communication } => { - last_task_message_from_communication(communication) - } - _ => non_empty_task_message(render_input_preview(&initial_operation)), - }; + if let Op::InterAgentCommunication { communication } = initial_operation { + return self + .submit_inter_agent_communication(agent_id, state, communication) + .await; + } + + let last_task_message = non_empty_task_message(render_input_preview(&initial_operation)); let result = self .handle_thread_request_result( agent_id, @@ -182,13 +183,26 @@ impl AgentControl { &self, agent_id: ThreadId, communication: InterAgentCommunication, + ) -> CodexResult { + self.send_input(agent_id, Op::InterAgentCommunication { communication }) + .await + } + + async fn submit_inter_agent_communication( + &self, + agent_id: ThreadId, + state: &Arc, + communication: InterAgentCommunication, ) -> CodexResult { let last_task_message = last_task_message_from_communication(&communication); - let state = self.upgrade()?; - let op = Op::InterAgentCommunication { communication }; - self.ensure_execution_capacity_for_op(agent_id, &op).await?; let result = self - .handle_thread_request_result(agent_id, &state, state.send_op(agent_id, op).await) + .handle_thread_request_result( + agent_id, + state, + state + .send_op(agent_id, Op::InterAgentCommunication { communication }) + .await, + ) .await; if result.is_ok() { match last_task_message {