Skip to content

Sub-agents: /agent new, the user's own start - #340

Merged
shoom1 merged 12 commits into
developfrom
feature/agent-new
Nov 23, 2026
Merged

shoom1 merged 12 commits into
developfrom
feature/agent-new

Conversation

@shoom1

@shoom1 shoom1 commented Nov 22, 2026

Copy link
Copy Markdown
Owner

The user can now start a sub-agent themselves: /agent new <type> <objective> starts an instance of a type the app lets the user start, opens its view and shows its first run there. Both backends.

/agent new

  • /agent new researcher Find what changed in the 2.0 release. starts an instance of a type whose spawnable_by and the policy's spawn_sources both name "user". The objective is the rest of the line as typed.
  • The instance's parent is the main agent, its run is started_by: user, and it counts toward no turn's runs. Its brief is the objective; brief_required is not asked. A type that inherits the conversation reads the open one.
  • The new instance's view opens on the run's first event, and the run streams there as a follow-up does: a line typed steers it, Ctrl+C is the user's stop (the instance stopped, also when it lands before the run started, which then never runs), and /back tells the main agent once.
  • /agent new typed inside a view leaves that view first.
  • Refusals: a type the user may not start (You cannot start '<type>' here. Types you can start: ...), an app that lets the user start none (This app lets you start no agent types., the default policy), and the usage line for a missing type or objective. A refusal starts nothing.

The manager

  • BaseWorkflowManager.start_instance(agent_type, objective, *, session_id=None, user_id=None): a turn of its own on the conversation, through the one entry for a first run.
  • A conversation whose first work is a start is stored as one, titled from the objective with 0 turns, so /resume, --continue and the exit's --resume hint reach it. On both backends it keeps that title after the main agent's first turn, and is never marked as a conversation from before 0.7.0.
  • run_instance and start_instance share one stream of the user's run; a stop before either run starts cancels it before it enters the agent.

Tests: written first and seen failing. The shared contract suite runs on both backends and covers:

  • a start, with its view's events and records;
  • the stop before and after the run starts (the agent never entered);
  • an inheriting type;
  • the refusals;
  • the stored conversation, its title and turns, and its outside-content mark.

There are unit tests for Delegations' user start, run_for without a call, the processor's start drawn in its view, /agent new's parsing and the view, plus a run on a real console over a pty. Reviewed, with three rounds of review fixes.

The full offline suite passes in the worktree (10955 passed), except TestChildImportOrigin::test_child_resolves_the_checkout, which fails the same way on develop under the worktree wrapper. On CI's library versions the contract suites, the session suites and every touched file pass (1203).

AgentRuns.run_for names a run per (conversation, parent run, call id) so a repeated call is the same run while it is open. A start with no call (the user's) has no such key: it is a new instance each time, and nothing is remembered under an empty call id.
Delegations.start_by_user starts a type for the user (/agent new): through start, with no caller and no call, so its parent is the root at depth 1, started_by user, counted toward no turn's runs, its brief the objective titled with its first line. Only a type whose spawnable_by and the policy's spawn_sources both name the user (startable_by_user); another is refused naming those the user may start, and a blank objective is refused (user_start_refused), with no run.
start_instance(agent_type, objective) starts a sub-agent the user asked for as a turn of its own on the open conversation, as run_instance continues one: its first event is the run's start, which names the instance; a type the user may not start, or a blank objective, is one ERROR. Stopping the stream is the user's stop of the run, also before the run started (it is stopped as it starts), and interrupt_instance ends it as a process exit does. An inheriting type reads the conversation as the root's task would hand it, through a new backend hook (_inherited_history: ADK's session events, Deep Agents' root messages). run_instance and start_instance share one stream (_users_run).
MessageProcessor.process_start runs the workflow's start_instance as a turn: once the run's start names the new instance, opens is told it (its view opens there) before the start is drawn, and from then on the instance's text is the reply and its lines name nobody, as in a follow-up's view. A refusal is the turn's one error, and nothing opens.
The /agent command takes new <type> <objective>, the objective the rest of the line as typed, and hands them to the app's start_agent; without a type or an objective it says Usage: /agent new <type> <objective>. /agent alone, the command's usage and its examples (/help agent) name it.
start_view (BaseCLIApp.start_agent) leaves a view that is open, then starts the instance (ConversationCore.start_instance) in a task of its own; once the run's start names the instance its view opens, holding that task and the processor drawing it (AgentView.adopt, AgentView(processor=)), so the first run streams there, a line steers it, Ctrl+C is the user's stop and /back tells the main agent, as for a follow-up. A refusal opens nothing; Ctrl+C before the view opened stops the run and opens none.
The console app's scripted workflow starts a researcher for /agent new; over a pty the new sub-agent's view opens on its first run, a line typed steers it, and /back tells the main agent once.
The CHANGELOG, the README's user's control and commands table, and CLAUDE.md's lines for the agents command, the view, the message processor, the conversation core, the manager and the delegations say how the user starts a sub-agent and where its first run streams.
…s its conversation

until_started awaits one future, resolved by the report of the run's start or the end of its work, so a stop before the start cancels the run before its hook is entered. start_instance stores a conversation that is not yet (ADK: the session with one state-only event, Deep Agents: an index row, titled from the objective, no turns), so /resume, --continue and --resume reach a conversation whose only work is a start. The processors' shared body is one helper (_user_turn). The docs say the main agent continues the user's instance only with the follow-up tools.
Deep Agents' record keeps the title of a row keep wrote (the objective's) when a notice or the first typed prompt rewrites it, and a turn that stored no message leaves that row instead of deleting it, as ADK does. The state-only event keep_conversation writes on ADK is authored by the root agent, so the router logs no unknown-agent warning at the next turn. A CHANGELOG line and a docstring paragraph are moved.
…ts row

The state-only event keep_conversation writes on ADK carries an unmarked outside-content record, so the conversation is not read as one from before 0.7.0 and marked, nor its new instance. The Deep Agents backfill leaves a row keep wrote as it is.
The stop-as-the-stream-starts scenario of the user's new instance started on a manager that was not initialized, so its worker-thread service build ran inside the window search and the hop budget ran out on a slow runner. The manager is brought up first, the search runs to a deadline, and a miss says whether the start ended first.
@shoom1
shoom1 merged commit 00db039 into develop Nov 23, 2026
6 checks passed
@shoom1
shoom1 deleted the feature/agent-new branch November 23, 2026 00:23
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