Skip to content

feat(subagents): Add messageAgent and drop spawnAgent name reuse - #2135

Merged
dcramer merged 3 commits into
mainfrom
feat/message-agent
Oct 14, 2026
Merged

dcramer merged 3 commits into
mainfrom
feat/message-agent

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Add a messageAgent tool so an agent can send work or information to an agent that already exists. This is the first part of the agent coordination tools in #2105.

  • spawnAgent only starts a new child. A name that is already used fails with AgentNameInUseError and points the model to messageAgent. Before this change, name reuse was how a parent gave a child more work.
  • messageAgent(to, text) takes "parent", or the name or conversation_id of a direct child.
    • Parent to child: the message starts a new agent invocation on the child, which keeps its history. An idle or stopped child returns delivery: "started". A busy child returns delivery: "queued" and runs the message after its current work; the earlier work ends as replaced, so the parent gets one result for both.
    • Child to parent: the message is a junior / agent.message Event on the same mailbox and Actor path as child results. It is marked as not from a person, so it gives no user approval.
  • listAgents returns status (pending | running | paused | idle | stopped) and last_result (completed | blocked | failed) instead of the raw agent invocation status. The dashboard API does not change.
  • stopAgent does not change. A stopped child keeps its name, and messageAgent can start new work on it. A stop of a child tree drops messages that were sent into that tree.

Limits: at most 4 open agent invocations per child, and message text up to 8,000 characters. The active-child limit per parent now counts children, not agent invocations, so queued messages do not count twice.

Not in this PR (tracked in #2105): mid-turn delivery to a running child, messages to siblings, idle notices, and message previews in the dashboard. The local CLI does not give messageAgent to child runs, because it does not send child output back to the root.

store.ts was over the 1,000-line limit, so child listing moved to agent-invocations/list.ts and the tree-stop SQL moved to agent-invocations/stop.ts. TERMINOLOGY.md and agent-invocations/README.md describe agent messages.

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Oct 14, 2026 8:05pm UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

spawnAgent now only starts a new child agent. A name that is already
used fails with AgentNameInUseError and points to messageAgent.

messageAgent sends an agent message to "parent" or to a direct child,
by name or conversation_id.

- Parent to child: the message starts a new agent invocation on the
  child, and the child keeps its history. A busy child runs it after its
  current work, and one result covers both.
- Child to parent: the message wakes the parent as a junior/agent.message
  Event. It uses the same mailbox and Actor path as child results.

A stop of the sender keeps a message that it already sent. A stop of the
parent drops it.

listAgents returns status (pending, running, paused, idle, stopped) and
last_result (completed, blocked, failed) instead of the raw agent
invocation status.

Child listing moves to list.ts and the tree stop SQL moves to stop.ts,
so store.ts stays under the file length limit.

Refs #2105

Co-Authored-By: David Cramer <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 375f745. Configure here.

@dcramer
dcramer merged commit 2d160d8 into main Oct 14, 2026
48 checks passed
@dcramer
dcramer deleted the feat/message-agent branch October 14, 2026 20:54
dcramer added a commit that referenced this pull request Oct 14, 2026
A child agent's watches failed. A timer that a child set went to the
root turn worker, which needs a Destination, and a child has none. The
event dead-lettered after five retries (Sentry issue 7792281477).

Child watch events now take the same path as child results and messages
from #2135: each batch starts an agent invocation on the child, and its
result goes to the parent. It follows the root rules for an Event Turn:
the same burst window, the event system actor, and a timer's own grants.

- A child's watch turns count toward its automated-turn limit. A
`spawnAgent` task or `messageAgent` message from the parent resets the
count.
- The `child_agent` prompt, `reportBlocked`, and `messageAgent` depend
on `parentConversationId`, not on the input source, so a child woken by
a watch keeps them.
- `listAgents` does not show a watch event as the child's task.

**Session stop.** A new `junior_conversations.stopped_at` column
(migration 0053) records a stop the same way for roots and children. A
stop ends the watches of the conversation and everything under it, then
records `stopped_at`. The worker drops watch events, agent results, and
agent messages received at or before it, so an event already queued for
an idle child no longer runs. `stopAgent` and the Slack `stop` keyword
both use it; the stop button still only interrupts the current turn. A
stopped idle child now shows `stopped` in `listAgents`, and
`messageAgent` starts it again.

**Tool audit:** `handoff`, `interactive-auth`, and nesting past
`maxAgentDepth` stay off for children. Automation tools,
`slackPublicSearch`, and `addReaction` already need a Slack source.
Slack write tools such as `sendFiles` stay on, so a child can post in
the root thread, as a root event run can.

**Follow-up:** a limit for parent → child → parent loops (#881).

Tests: a child timer runs as the event actor, reports to the parent,
counts toward the turn limit, is dropped after a stop, and works again
after `messageAgent`. A root timer is dropped after a session stop, and
a watch set later still fires.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1791993640.607069 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1791993640.607069)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1791993640.607069/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 18a25503 Deployed Oct 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant