Skip to content

Sub-agents: the user stops, closes and continues them from the console - #334

Merged
shoom1 merged 10 commits into
developfrom
feature/agent-commands
Nov 20, 2026
Merged

shoom1 merged 10 commits into
developfrom
feature/agent-commands

Conversation

@shoom1

@shoom1 shoom1 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

The user can now see, stop and close the open conversation's sub-agents from the console. The manager gains the entry points behind that, which a view of a sub-agent can build on. Both backends are covered.

The console

  • /agents is a picker of the conversation's sub-agent instances. Each instance is followed by the ones it started, with its id, type, status (running, idle, stopped, closed) and title. Enter shows the one picked. The runs table is gone; /agents <id> still shows one instance or run in full.
  • /agent:
    • /agent <id> shows one instance.
    • /agent stop <id> stops one. Its working run, if any, is cancelled by the user (cancelled_by: user), and the instance is stopped. Its parent's message_agent is then refused, and only the user may start its next run. A one-shot instance whose run is stopped ends closed instead, and the command says so.
    • /agent close <id> closes the instance and its own sub-agents. They take no more runs, and their work stays readable.
    • Each says what it did, or why not. /agent alone says its usage.

The manager's entry points (provisional). Each works on the open conversation, or on the one session_id/user_id name, and on any of its instances. All go through Delegations, as a parent's tools do.

  • run_instance(instance, message) is the user's follow-up, a turn of its own.
    • The run is started_by: user and counts toward no turn's runs. It starts from the conversation's outside-content mark.
    • Stopping its stream (Ctrl+C) is the user's stop, even when the Ctrl+C lands as the run starts. The run works in a shielded task of its own, so it ends cancelled and the instance stopped, not interrupted and idle.
  • stop_instance / close_instance take no turn lock. They cancel the run from outside and wait for its end, so the status is final and the records written when they return.
  • steer_instance(instance, message) gives a running run the user's message before its next step.
  • instance_result returns the envelope of the latest run the user started.
  • tell_root(text) runs a turn of the root on a notice the user did not type.
    • The notice is marked as a job's notice is, so fact extraction and the conversation's title and turns leave it out.
    • The outside-content mark a user's run brought is written with it.
    • The notice after the user worked with a sub-agent is agents/envelope.py::view_notice: "The user worked with directly; its latest result: ".

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

  • the user's follow-up and its Ctrl+C, including one that lands as the run starts;
  • stop and close of a running and an idle instance, and after a restart;
  • a parent's message refused after the user's stop;
  • steering;
  • the root's notice left out of the conversation's messages and row;
  • the conversation named.

Each new async path also runs once under the loop guard. Unit tests cover Delegations' user stop and close (including a run that finishes as the stop comes), the notice on each backend's sessions, and the CLI commands.

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 contract suite and the touched tests also pass on CI's library versions (google-adk 2.15, deepagents 0.7.41) in a scratch virtualenv.

stop_by_user cancels a running instance's run by the user and waits for its end, which leaves the instance stopped; an idle one is stopped at once. close_by_user closes an instance and its descendants, a running one as its run ends. Only the user may start a stopped instance's next run.
…(failing)

The harness makes the crew's conversation the manager's open one and stops any turn a failed scenario left running before the manager is cleaned up. The scenarios drive run_instance, stop_instance, close_instance and steer_instance on both backends.
run_instance runs the user's follow-up as a turn of its own, in a task it shields so that stopping its stream is the user's stop of the run (cancelled by the user, the instance stopped). stop_instance and close_instance cancel from outside, wait for the run's end and the records, and take no turn lock. steer_instance gives a running run the user's line. Each acts on the open conversation or the one session_id and user_id name. A run the user starts begins from the conversation's outside-content mark (_conversation_state, one hook per backend).
…text

tell_root runs the root on a notice the user did not type, marked as a job's notice is so recent_messages and the conversation's row leave it out; the outside-content mark a run the user started brought is written with it. On ADK the run carries RunConfig.custom_metadata, which ADK stamps on each event including the notice's user event; on Deep Agents the message's response_metadata says so. view_notice words what the root is told after the user worked with a sub-agent.
/agents is a picker of the conversation's instances, each followed by the ones it started; Enter shows the one picked as /agents <id> does. /agent <id> shows one, /agent stop <id> and /agent close <id> are the user's stop and close, each saying what it did or why not and acting on the app's own conversation. The runs table goes; its row checks move to the panel's tests.
A cancel of run_instance's consumer that came after the pump was made but before the follow-up's first step found the instance idle and cancelled nothing, so the run completed and the instance stayed idle. The source looks again when it is cancelled. Also pins that stop_instance and close_instance load the records first, that the base tell_root refuses without a notice hook, and that a blank steer is a ValueError.
…d alone

The manager's hold of a mark a user's run changed, and ADK's write of the held mark with the notice (the root's model call fails, so the permission plugin never writes it), each fail a test when removed.
A type that takes no more runs closes as its stopped run ends; the line is worded from the instance's status after the stop. Also a blank-line slip in two test files.
PR-order of the Added bullets (the roster and brief bullets first), the comma in the base manager's delete clause, and run_instance and tell_root among what enters through _turn.
@shoom1
shoom1 merged commit c113b91 into develop Nov 20, 2026
6 checks passed
@shoom1
shoom1 deleted the feature/agent-commands branch November 20, 2026 13:19
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