Skip to content

[FEATURE] Main agent should be able to inject a message to the sub agent at runtime #1456

Description

@edenreich

Summary

The main agent can delegate work with the Agent tool, but once a subagent is running the only way to talk to it is SendSubagentInput, and that tool only works for interactive (tmux pane) subagents. For a headless subagent it fails with Subagent <label> is headless and has no TUI to send input to. Headless is the default (tools.agent.mode: headless in DefaultConfig()), and it is the only mode outside tmux, so in the common case the main agent cannot steer a subagent after spawning it: it can only wait for the [Subagent Completed] note or kill it with CloseSubagent and start over.

This issue asks for a runtime message channel to a running or just-finished subagent in both modes, so the main agent can hand it new information ("the user changed the requirement, also cover X"), correct its course ("stop editing that file, the schema lives in Y"), or ask a follow-up on its result without respawning and losing its context.

Current behaviour

  • Interactive mode: SendSubagentInput types into the pane and re-arms the completion watcher when submit=true. Text typed mid-turn is queued by the subagent's chat and runs as its next turn. This already covers the ask for tmux users.
  • Headless mode: AgentTool.executeOne runs the child through agentrunner.Run, which opens a stdin pipe only when RequireApproval && Approval != nil. The Agent tool passes neither, so the child's stdin is /dev/null. The child's headlessControl reads EOF at once, awaitTurn returns false after the first turn, and the process exits. There is nowhere to write a message.

What already exists to build on

  • infer headless (any non-text format) already reads newline-delimited control frames on stdin in headlessControl.dispatchLine. A run_agent_input frame enqueues its messages on the session message queue, and awaitTurn picks them up as the next turn while stdin stays open. This is the same frame the daemon sends to infer headless --serve workers, so no new protocol is needed.
  • The interactive job already has the per-turn result file with done: true, the completion watcher, [Subagent Idle], tools.agent.idle_timeout auto-close and SendSubagentInput's re-arm. The headless job needs the same lifecycle once the child can outlive its first turn.

Proposed shape

  • Keep SendSubagentInput as the single tool the model calls, and make it work for headless subagents too. text is the message. keys and submit=false stay interactive-only and return a clear error for a headless target, since there is no TUI to drive.
  • For a headless subagent, agentrunner.Run keeps a stdin pipe open for the subagent's lifetime and exposes a writer to the job. SendSubagentInput writes one run_agent_input frame with a single user message on it.
  • A headless subagent that has finished its turn stays alive and idle until the parent sends a follow-up, the idle timeout closes it, or CloseSubagent stops it. Lifecycle mirrors the interactive job: the child writes the result file with done: true at the end of every turn (--result-file today writes it once on exit), the job delivers one [Subagent Completed: <label>] note per turn, re-arms when a message is sent, and [Subagent Idle] and [Subagent Closed] apply unchanged.
  • tools.agent.wait: true (blocking fan-in) is unaffected: a blocking subagent returns its first turn and is closed, the way it works today. Only async headless subagents become addressable.
  • The subagent's run stats keep accumulating across turns so the stats line stays meaningful.

Open question for the implementer: whether an idle headless subagent should hold a slot against tools.agent.max_parallel. Interactive panes do today. Holding the slot is the simplest consistent answer and the idle timeout already bounds the cost.

Out of scope

  • Streaming the subagent's partial output back to the parent mid-turn (ReadSubagentScreen stays interactive-only).
  • Subagent to parent messages other than the existing completion, idle and approval notes.
  • Messaging A2A tasks. A2A_SubmitTask already resumes input-required tasks and has its own follow-up path.

Acceptance Criteria

  • With tools.agent.mode: headless, after the [Subagent Completed: <label>] note arrives, SendSubagentInput with text runs a second turn in the same subagent session, and the parent receives a second [Subagent Completed: <label>] note carrying that turn's final message.
  • SendSubagentInput sent while a headless subagent is mid-turn is queued and runs as its next turn, with no message lost and no duplicate completion note.
  • SendSubagentInput with keys or submit=false against a headless subagent fails with an error that says these are interactive-only, without affecting the subagent.
  • An idle headless subagent is closed after tools.agent.idle_timeout seconds with one [Subagent Closed: <label>] note, and 0 disables the auto-close, matching the interactive behaviour.
  • CloseSubagent stops an idle or running headless subagent and releases its slot.
  • tools.agent.wait: true behaviour is unchanged: the blocking call returns after the first turn and the subagent is not kept alive.
  • The stats line in the completion note and in the job list reflects all turns of the subagent, not only the last one.
  • docs/subagents.md and docs/tools-reference.md describe SendSubagentInput as working for both modes and document the keep-alive lifecycle for headless subagents. The tool definition golden file is updated.
  • go test -race ./... and task precommit:run pass.

Activity

  1. added
    enhancement
    on Oct 1, 2026
  2. added theissue type on Oct 1, 2026
  3. moved this to Todo in 2026on Oct 1, 2026
  4. inference-gateway-releaser commented on Oct 2, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.222.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions