Skip to content

feat: surface sub-agent lifecycle events in chat#41

Open
chetan-guevara wants to merge 1 commit intomoazbuilds:masterfrom
chetan-guevara:feat/agent-lifecycle-tracking
Open

feat: surface sub-agent lifecycle events in chat#41
chetan-guevara wants to merge 1 commit intomoazbuilds:masterfrom
chetan-guevara:feat/agent-lifecycle-tracking

Conversation

@chetan-guevara
Copy link
Copy Markdown
Contributor

Summary

When Claude uses the Agent tool to spawn a sub-agent, the chat UI now shows real-time activity bubbles tracking the spawn and completion of those agents.

Depends on: #40 (chat tab)

  • Spawn acknowledgment — a 🤖 Sub-agent started: [description] bubble appears immediately when an Agent tool call is detected in the stream, so you know a background task was dispatched
  • Completion result — when the sub-agent finishes, its result text is posted back to the chat as a new assistant bubble
  • Agent activity bubbles are styled distinctly from regular chat messages and are excluded from localStorage persistence while running

Architecture

The stream-json event stream is parsed for two new event types:

  • assistant events with content[].type === "tool_use" and name === "Agent" → spawn
  • user events with content[].type === "tool_result" matching a tracked tool_use_id → done

These are surfaced as new SSE event types from /api/chat:

  • { type: "agent_spawn", id, description }
  • { type: "agent_done", id, description, result }

A Map<tool_use_id, description> tracks pending agents across events in streamClaude.

New types

export interface AgentStreamEvent {
  type: "spawn" | "done";
  id: string;
  description: string;
  result?: string;
}

Test plan

  • Ask the daemon to do a research task that spawns a sub-agent
  • Verify a 🤖 Sub-agent started: ... bubble appears immediately in chat
  • Verify the input unblocks so you can continue chatting while the agent runs
  • Verify ✅ Sub-agent done: ... bubble appears when complete, followed by the result
  • Reload page — verify running agent bubbles are not persisted to localStorage; completed ones are

Builds on the chat tab feature by adding real-time visibility into
sub-agent spawning and completion. The stream-json parser detects
Agent tool_use blocks (spawn) and their matching tool_result blocks
(done), forwarding typed AgentStreamEvent objects through the SSE
pipeline to the browser, where they render as transient activity
bubbles between conversation turns.

- runner.ts: AgentStreamEvent interface; streamClaude() tracks pending
  Agent tool calls via tool_use_id map, emits spawn/done events to
  optional onAgentEvent callback; streamUserMessage() passes it through
- ui/types.ts: re-exports AgentStreamEvent; onChat callback gains
  onAgentEvent parameter
- ui/server.ts: idleTimeout:0; /api/chat SSE endpoint forwards
  agent_spawn and agent_done events alongside chunk/unblock/done/error
- commands/start.ts: wires onAgentEvent through to streamUserMessage
- ui/page/template.ts: tab nav, dashboard-panel wrapper, chat-panel
  with messages container and chat form
- ui/page/script.ts: handles agent_spawn/agent_done SSE events,
  renders agent activity bubbles, filters running agents from
  localStorage persistence
- ui/page/styles.ts: [hidden] override, tab nav, chat panel, and
  agent bubble CSS (.chat-msg-agent, -running, -done, .chat-agent-spinner)
Fenrur added a commit to Fenrur/claudeclaw that referenced this pull request Mar 17, 2026
- AgentStreamEvent type for spawn/done events
- Sub-agent cards in chat UI with descriptions
- onAgentEvent callback through streaming pipeline

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant