feat(agents): add watchdog and forked-agent support

Add watchdog scheduling and forked-agent spawn/resume support across the agent control plane, schemas, rollout metadata, and TUI surfaces.

Rolls up follow-up fixes for watchdog lifecycle behavior and guidance: helper cleanup/one-shot enforcement, wait semantics for watchdog check-in agents, and clarified tool descriptions so models align with runtime behavior.
This commit is contained in:
Friel
2026-02-24 14:05:06 -08:00
parent fefdc03b25
commit 993d3874e1
41 changed files with 5727 additions and 313 deletions
+15
View File
@@ -73,6 +73,11 @@ pub enum ResponseInputItem {
role: String,
content: Vec<ContentItem>,
},
FunctionCall {
name: String,
arguments: String,
call_id: String,
},
FunctionCallOutput {
call_id: String,
output: FunctionCallOutputPayload,
@@ -664,6 +669,16 @@ impl From<ResponseInputItem> for ResponseItem {
end_turn: None,
phase: None,
},
ResponseInputItem::FunctionCall {
name,
arguments,
call_id,
} => Self::FunctionCall {
id: None,
name,
arguments,
call_id,
},
ResponseInputItem::FunctionCallOutput { call_id, output } => {
Self::FunctionCallOutput { call_id, output }
}
+50
View File
@@ -33,6 +33,7 @@ use crate::message_history::HistoryEntry;
use crate::models::BaseInstructions;
use crate::models::ContentItem;
use crate::models::MessagePhase;
use crate::models::ResponseInputItem;
use crate::models::ResponseItem;
use crate::models::WebSearchAction;
use crate::num_format::format_with_separators;
@@ -72,6 +73,27 @@ pub const ENVIRONMENT_CONTEXT_CLOSE_TAG: &str = "</environment_context>";
pub const COLLABORATION_MODE_OPEN_TAG: &str = "<collaboration_mode>";
pub const COLLABORATION_MODE_CLOSE_TAG: &str = "</collaboration_mode>";
pub const USER_MESSAGE_BEGIN: &str = "## My request for Codex:";
pub const COLLAB_INBOX_KIND: &str = "collab_inbox";
pub const COLLAB_INBOX_MESSAGE_PREFIX: &str = "[collab_inbox:";
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
pub struct CollabInboxPayload {
pub injected: bool,
pub kind: String,
pub sender_thread_id: ThreadId,
pub message: String,
}
impl CollabInboxPayload {
pub fn new(sender_thread_id: ThreadId, message: String) -> Self {
Self {
injected: true,
kind: COLLAB_INBOX_KIND.to_string(),
sender_thread_id,
message,
}
}
}
/// Submission Queue Entry - requests from user
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
@@ -161,6 +183,14 @@ pub enum Op {
final_output_json_schema: Option<Value>,
},
/// Inject non-user input items (tool output or assistant/developer messages).
///
/// Used for agent-to-agent inbox delivery without re-encoding as a user message.
InjectResponseItems {
/// Response input items to inject and optionally run.
items: Vec<ResponseInputItem>,
},
/// Similar to [`Op::UserInput`], but contains additional context required
/// for a turn of a [`crate::codex_thread::CodexThread`].
UserTurn {
@@ -2071,10 +2101,17 @@ pub struct SessionMetaLine {
pub git: Option<GitInfo>,
}
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, TS)]
pub struct ForkReferenceItem {
pub rollout_path: PathBuf,
pub nth_user_message: usize,
}
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, TS)]
#[serde(tag = "type", content = "payload", rename_all = "snake_case")]
pub enum RolloutItem {
SessionMeta(SessionMetaLine),
ForkReference(ForkReferenceItem),
ResponseItem(ResponseItem),
Compacted(CompactedItem),
TurnContext(TurnContextItem),
@@ -2855,6 +2892,16 @@ pub struct CollabAgentSpawnBeginEvent {
pub prompt: String,
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS, Default)]
#[serde(rename_all = "snake_case")]
#[ts(rename_all = "snake_case")]
pub enum CollabAgentSpawnMode {
#[default]
Spawn,
Fork,
Watchdog,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
pub struct CollabAgentRef {
/// Thread ID of the receiver/new agent.
@@ -2898,6 +2945,9 @@ pub struct CollabAgentSpawnEndEvent {
/// Initial prompt sent to the agent. Can be empty to prevent CoT leaking at the
/// beginning.
pub prompt: String,
/// Spawn mode used for this agent.
#[serde(default)]
pub spawn_mode: CollabAgentSpawnMode,
/// Last known status of the new agent reported to the sender agent.
pub status: AgentStatus,
}