mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
multi-agent: add path-based v2 activity tracking (#27007)
## Why Multi-agent v2 identifies agents by canonical paths, but its tool handlers still emitted the larger legacy collaboration begin/end events built around nickname and role metadata. App-server, rollout-trace, analytics, and TUI consumers therefore lacked one compact path-based completion signal that behaved consistently across live events and replay. The TUI also needs a bounded `/agent` status surface for v2 agents. It should use recent local activity for previews, refresh liveness without loading full histories, and keep the legacy picker available when no path-backed v2 agent is known. ## What changed - Replace the v2 `spawn_agent`, `send_message`, `followup_task`, and `interrupt_agent` legacy lifecycle emissions with a success-only `SubAgentActivity` event. The event records the tool call ID, occurrence time, affected thread, canonical agent path, and `started`, `interacted`, or `interrupted` kind. - Expose the activity as a completion-only app-server v2 `subAgentActivity` thread item in live notifications and reconstructed history, regenerate the protocol schemas, and count it in sub-agent tool analytics. - Track canonical paths from live activity and loaded-thread metadata in the TUI, and render the activity in live and replayed transcripts. - Make `/agent` list running path-backed agents with summaries from bounded local event buffers. Each summary is capped at 240 graphemes, the scan is capped at six recent items, only the last three wrapped lines are shown, and command output is omitted. Liveness falls back to metadata-only `thread/read` when local turn state is unavailable. - Persist the activity as a terminal rollout-trace runtime payload and reduce it to the corresponding spawn, send, follow-up, or close interaction edge. `interrupt_agent` is classified as a close-edge operation. - Preserve the legacy picker when no path-backed v2 agent is known. ## Compatibility App-server v2 clients that consumed `collabAgentToolCall` begin/end pairs for these tools must handle the new completion-only `subAgentActivity` item. Legacy v1 collaboration behavior is unchanged. ## Screenshot <img width="684" height="288" alt="Screenshot 2026-06-08 at 15 40 47" src="https://github.com/user-attachments/assets/194b3cd0-619d-45fb-b587-cf3e2b1b8a1d" /> ## Testing - `just test -p codex-app-server-protocol` - `just test -p codex-rollout-trace` - Added focused coverage for activity analytics, terminal trace serialization, spawn-edge reduction, `interrupt_agent` classification, TUI status rendering without aggregated command output, and clearing stale running state after a completed turn.
This commit is contained in:
57 files changed
+2070
-176
No files matched your search
@@ -8,6 +8,60 @@ use super::*;
|
||||
|
||||
impl App {
|
||||
pub(super) async fn open_agent_picker(&mut self, app_server: &mut AppServerSession) {
|
||||
self.backfill_loaded_subagent_threads(app_server).await;
|
||||
// V2 subagents are identified by canonical paths observed from activity events or loaded
|
||||
// thread metadata. Prefer local buffered turn state for liveness, and fall back to
|
||||
// thread/read only when no local event channel exists.
|
||||
let path_backed_thread_ids: Vec<_> = self
|
||||
.agent_navigation
|
||||
.ordered_path_backed_subagent_threads(self.primary_thread_id)
|
||||
.into_iter()
|
||||
.map(|(thread_id, _)| thread_id)
|
||||
.collect();
|
||||
for thread_id in path_backed_thread_ids {
|
||||
if let Some(channel) = self.thread_event_channels.get(&thread_id)
|
||||
&& channel.attachment() == ThreadEventAttachment::Live
|
||||
{
|
||||
let is_running = channel.store.lock().await.active_turn_id().is_some();
|
||||
self.agent_navigation.set_running(thread_id, is_running);
|
||||
} else {
|
||||
self.refresh_agent_picker_thread_liveness(app_server, thread_id)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
let path_backed_threads = self
|
||||
.agent_navigation
|
||||
.ordered_path_backed_subagent_threads(self.primary_thread_id);
|
||||
if !path_backed_threads.is_empty() {
|
||||
let running_threads: Vec<_> = path_backed_threads
|
||||
.into_iter()
|
||||
.filter_map(|(thread_id, entry)| {
|
||||
if !entry.is_running || entry.is_closed {
|
||||
return None;
|
||||
}
|
||||
Some((thread_id, entry.agent_path.as_deref()?.trim().to_string()))
|
||||
})
|
||||
.collect();
|
||||
let mut entries = Vec::new();
|
||||
for (thread_id, agent_path) in running_threads {
|
||||
let preview = if let Some(channel) = self.thread_event_channels.get(&thread_id) {
|
||||
let store = channel.store.lock().await;
|
||||
super::agent_status_feed::AgentStatusThreadPreview::from_store(
|
||||
agent_path, &store,
|
||||
)
|
||||
} else {
|
||||
super::agent_status_feed::AgentStatusThreadPreview::empty(agent_path)
|
||||
};
|
||||
entries.push(preview);
|
||||
}
|
||||
|
||||
self.chat_widget
|
||||
.add_to_history(super::agent_status_feed::AgentStatusHistoryCell::new(
|
||||
entries,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
let mut thread_ids = self.agent_navigation.tracked_thread_ids();
|
||||
for thread_id in self.thread_event_channels.keys().copied() {
|
||||
if !thread_ids.contains(&thread_id) {
|
||||
@@ -44,14 +98,14 @@ impl App {
|
||||
let items: Vec<SelectionItem> = self
|
||||
.agent_navigation
|
||||
.ordered_threads()
|
||||
.iter()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, (thread_id, entry))| {
|
||||
if self.active_thread_id == Some(*thread_id) {
|
||||
if self.active_thread_id == Some(thread_id) {
|
||||
initial_selected_idx = Some(idx);
|
||||
}
|
||||
let id = *thread_id;
|
||||
let is_primary = self.primary_thread_id == Some(*thread_id);
|
||||
let id = thread_id;
|
||||
let is_primary = self.primary_thread_id == Some(thread_id);
|
||||
let name = format_agent_picker_item_name(
|
||||
entry.agent_nickname.as_deref(),
|
||||
entry.agent_role.as_deref(),
|
||||
@@ -62,7 +116,7 @@ impl App {
|
||||
name: name.clone(),
|
||||
name_prefix_spans: agent_picker_status_dot_spans(entry.is_closed),
|
||||
description: Some(uuid.clone()),
|
||||
is_current: self.active_thread_id == Some(*thread_id),
|
||||
is_current: self.active_thread_id == Some(thread_id),
|
||||
actions: vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::SelectAgentThread(id));
|
||||
})],
|
||||
@@ -145,6 +199,14 @@ impl App {
|
||||
.await
|
||||
{
|
||||
Ok(thread) => {
|
||||
let is_running = matches!(
|
||||
thread.status,
|
||||
codex_app_server_protocol::ThreadStatus::Active { .. }
|
||||
);
|
||||
let is_closed = matches!(
|
||||
thread.status,
|
||||
codex_app_server_protocol::ThreadStatus::NotLoaded
|
||||
);
|
||||
self.upsert_agent_picker_thread(
|
||||
thread_id,
|
||||
thread.agent_nickname.or_else(|| {
|
||||
@@ -157,11 +219,9 @@ impl App {
|
||||
.as_ref()
|
||||
.and_then(|entry| entry.agent_role.clone())
|
||||
}),
|
||||
matches!(
|
||||
thread.status,
|
||||
codex_app_server_protocol::ThreadStatus::NotLoaded
|
||||
),
|
||||
is_closed,
|
||||
);
|
||||
self.agent_navigation.set_running(thread_id, is_running);
|
||||
true
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -186,6 +246,8 @@ impl App {
|
||||
is_closed,
|
||||
);
|
||||
}
|
||||
self.agent_navigation
|
||||
.set_running(thread_id, /*is_running*/ false);
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -248,6 +310,9 @@ impl App {
|
||||
}
|
||||
};
|
||||
let channel = self.ensure_thread_channel(thread_id);
|
||||
if !live_attached {
|
||||
channel.mark_replay_only();
|
||||
}
|
||||
let mut store = channel.store.lock().await;
|
||||
store.set_session(session, turns);
|
||||
Ok(live_attached)
|
||||
@@ -610,13 +675,17 @@ impl App {
|
||||
}
|
||||
|
||||
for thread in find_loaded_subagent_threads_for_primary(threads, primary_thread_id) {
|
||||
let agent_path = thread.agent_path;
|
||||
self.upsert_agent_picker_thread(
|
||||
thread.thread_id,
|
||||
thread.agent_nickname,
|
||||
thread.agent_role,
|
||||
/*is_closed*/ false,
|
||||
);
|
||||
self.agent_navigation
|
||||
.set_agent_path(thread.thread_id, agent_path);
|
||||
}
|
||||
self.sync_active_agent_label();
|
||||
|
||||
!had_read_error
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user