mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Add opt-in item-boundary interrupts for subagents (#61909)
## What changed Add the multi-agent v2 setting `interrupt_at_item_boundary`, disabled by default. When enabled, `interrupt_agent` lets a subagent finish and retain its current output item while cancelling tools immediately. Later output items are discarded, and retained tool calls that have not run receive an aborted result. Wait for the interrupted turn's terminal event before starting follow-up input, and prevent idle contributors from restarting the interrupted child. ## Testing Add streaming tests for retaining an assistant message or tool call, discarding later output, and preserving history and follow-up input when the child resumes. Update configuration and interrupt-routing tests. GitOrigin-RevId: 8b2b9b1383bfb4eefea7369a40012bebc5fff07b
This commit is contained in:
@@ -334,17 +334,14 @@ impl LocalAgentControl {
|
||||
}
|
||||
|
||||
/// Interrupt the current task for an existing agent thread.
|
||||
pub(crate) async fn interrupt_agent(&self, agent_id: ThreadId) -> CodexResult<String> {
|
||||
pub(crate) async fn interrupt_agent(&self, agent_id: ThreadId, op: Op) -> CodexResult<String> {
|
||||
let state = self.runtime.upgrade()?;
|
||||
self.handle_thread_request_result(
|
||||
agent_id,
|
||||
&state,
|
||||
state
|
||||
.send_op(
|
||||
agent_id,
|
||||
Op::Interrupt,
|
||||
/*parent_turn_id*/ None,
|
||||
/*root_turn_id*/ None,
|
||||
agent_id, op, /*parent_turn_id*/ None, /*root_turn_id*/ None,
|
||||
/*message_delivery*/ None,
|
||||
)
|
||||
.await,
|
||||
|
||||
@@ -26,6 +26,7 @@ use codex_protocol::ThreadId;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::Result;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::TokenUsage;
|
||||
use codex_rollout_trace::ThreadTraceContext;
|
||||
@@ -211,7 +212,7 @@ impl AgentControl for LocalAgentControl {
|
||||
match version {
|
||||
MultiAgentVersion::Disabled | MultiAgentVersion::V1 => {
|
||||
let snapshot = self.inspect_agent(target).await?;
|
||||
self.interrupt_agent(target).await?;
|
||||
self.interrupt_agent(target, Op::Interrupt).await?;
|
||||
Ok(snapshot)
|
||||
}
|
||||
MultiAgentVersion::V2 => self.interrupt_spawned_agent(caller, target).await,
|
||||
|
||||
@@ -10,6 +10,7 @@ use codex_protocol::ThreadId;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::CodexErrorDetails;
|
||||
use codex_protocol::error::Result as CodexResult;
|
||||
use codex_protocol::protocol::Op;
|
||||
|
||||
impl LocalAgentControl {
|
||||
/// Interrupts a spawned agent's current task, preserving the status observed before dispatch.
|
||||
@@ -38,7 +39,7 @@ impl LocalAgentControl {
|
||||
CodexErr::UnsupportedOperation("target agent is missing an agent_path".to_string())
|
||||
})?;
|
||||
let snapshot = self.inspect_agent(target).await?;
|
||||
match self.interrupt_agent(target).await {
|
||||
match self.interrupt_agent(target, Op::InterruptAgent).await {
|
||||
Ok(_) => {}
|
||||
Err(err)
|
||||
if matches!(
|
||||
|
||||
Reference in New Issue
Block a user