Skip to content

Sub-agents: a sub-agent's view, /agent <id> and /back - #335

Merged
shoom1 merged 17 commits into
developfrom
feature/agent-view
Nov 20, 2026
Merged

shoom1 merged 17 commits into
developfrom
feature/agent-view

Conversation

@shoom1

@shoom1 shoom1 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

The user can now work with one of the conversation's sub-agents directly, in its view.

Opening it: /agent <id> (or Enter in /agents' picker) opens the view.

  • It starts with a rule, ── researcher-2 · researcher · idle ──.
  • Then a recap: the instance's title and objective, its last run's status, the first lines of its result, and its tokens. Nothing is replayed.
  • The prompt becomes researcher-2> .
  • The status bar names the instance, its status, and its own ctx and tokens. The jobs segment is kept.

Working in it

  • A line typed there is the instance's next run, a turn whose reply is its text (run_instance, started_by: user).
  • A line typed while that run works is given to it before its next model step (steer_instance). It is never queued as a turn.
  • The run works outside the input handler, so the prompt stays open for steering.
  • Ctrl+C stops the run. This is a key binding of the view's own, active only while its run works. It is the user's stop: the sub-agent becomes stopped. A Ctrl+C that lands as the run starts still stops it.
  • One dialog at a time. The app's session takes one lock around its dialog methods, so an app's own commands are covered too. A permission question from the run waits for a picker or dialog a command opened, and a command's dialog waits for an open question. A question is never answered without the user seeing it.

Leaving it: /back waits for a run still working, then prints ── back to main ──.

  • If a run the user started there ended, the main agent gets one notice turn carrying its latest envelope (tell_root with "The user worked with directly; its latest result: …"). The turn is drawn as a job's notice is.
  • The main agent's own notices (finished jobs) wait while a view is open. They are counted in ↻N and told after /back.

Commands inside a view

  • /status shows the sub-agent's model and context.
  • /compact is refused.
  • /new, /resume and /agent <another id> leave the view first, waiting for its run.
  • /exit with a run working is the user's stop, waited for before the workflow is cleaned up.
  • A line typed while the workflow is down starts it, as a turn does.

A closed sub-agent's view is read-only: there is no prompt, a typed line is refused, and commands work.

The app's API (provisional): agent_view, open_agent_view(id) and leave_agent_view().

Also: the main conversation's turns and the view's runs now share one write frame in ConversationCore. Before, there were two copies.

Tests: written first and seen failing.

  • Unit tests cover the view: opening, recap and status bar, a line as a run or a steer, Ctrl+C, /back with its notice once per run, the notices that wait, the commands in a view, a closed view, a model switch in a view, and the dialog lock in both orders.
  • Console tests over a pty cover Ctrl+C in a view on a real console, and /exit with a run working.
  • Each new async path runs once under the loop guard.

The full offline suite passes in the worktree, except TestChildImportOrigin::test_child_resolves_the_checkout, which fails the same way on develop under the worktree wrapper. The CLI tests, the render tests and the shared contract suite also pass on CI's library versions (google-adk 2.15, deepagents 0.7.41) in a scratch virtualenv, apart from the LangGraph deprecation test, which fails only in that virtualenv.

…urns

process_instance draws the user's line in a sub-agent's view as a turn whose
source is run_instance: the instance's text is the reply and its lines name
nobody, and each event of its run draws the status bar again. process_notice
draws the main agent's notice after a view (tell_root) as a job's notice turn
is.
…er, /back

/agent <id> (and Enter in /agents' picker) opens one instance's view: a rule,
a recap, the prompt <id>> and a status bar naming the instance, its status,
its own ctx and tokens. A line typed there is the instance's next run, started
in a task of its own outside the input handler so the prompt stays open, or,
while its run works, is given to that run before its next model step. /back
leaves it. A closed instance's view is read-only.
…, /new, /resume, /status there

Leaving a view tells the main agent once, in a notice turn, when a run the
user started there ended since it last heard of the instance. The main agent's
own notices (finished jobs) wait while a view is open and are told after
/back. In a view /compact is refused, /new and /resume leave it first, and
/status shows the instance's context.
…l working

The view's run works outside the input handler, which thinking-prompt's Ctrl+C
does not reach, so the session gets one more key binding, active only while
that run works. A run still working at exit is the user's stop, waited for
before the workflow is cleaned up.
A sub-agent's view runs its run outside the input handler, so a command may
open a dialog while the run asks its question. thinking-prompt raises on a
second dialog, which would turn a permission prompt into a denial the user
never saw, or fail the command. Every dialog now takes the session's one lock
while it is open: the commands' through show_dialog, a run's question inside
the message processor. Whichever comes second waits for the first.
_write was a copy of run_turn's frame without the echo. run_turn now calls it
with the line to echo, shown once the turn lock is taken and before the
cancelled line when the wait for the lock is stopped, so every write to the
conversation follows the same rules for held, turned and written.
…urn does

After a model switch whose rebuild failed, a line typed in a sub-agent's view
was refused where the main conversation retries the start, and /back skipped
the main agent's notice. A line is now the instance's next run all the same
(its start retries the workflow), and /back retries the start before it
tells the main agent.
…rather than hangs

A second line typed before the first run ended waited for the turn lock and
said "Operation cancelled..." again when Ctrl+C stopped it. A queued line now
waits for the run before it inside the view, where a stop is silent. The Ctrl+C
test waits for the run with a bound and cancels what is left, so a stop that
stops working fails the test instead of stalling teardown.
…versation keeps

run() logs at info when the session takes no Ctrl+C binding (Ctrl+C in a view
is then thinking-prompt's own and the run goes on until it ends or /exit stops
it). New tests: the main agent's ctx stays put after a view run, finished jobs
are not told in a view (resume_finished_jobs, and the bar counts them).
The context rows are read after the Model, App Name, Session ID and Services
rows again, so rows that fail to read leave those shown. Only in a sub-agent's
view are the instance's rows read first, to drop the main Model row.
An app's command that calls app.session.show_dialog itself skipped the helper
the framework's commands used, so a question of a view's run could still be
refused. BaseCLIApp.session now wraps a real session's dialog methods once, on
assignment: every caller is serialized. The commands call the session directly
again, the helper is gone, and the lock lets the same task take it again, so
the message processor's question lock and the wrapper never wait for each
other. The one-dialog tests wait on conditions (the run's record reading
input_required, the command's picker built), not on a sleep.
@shoom1
shoom1 merged commit 3da3f16 into develop Nov 20, 2026
6 checks passed
@shoom1
shoom1 deleted the feature/agent-view branch November 20, 2026 15:16
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