Skip to content

feat(tools): let the main agent message a headless subagent at runtime - #1465

Merged
edenreich merged 4 commits into
mainfrom
feat/headless-subagent-input
Oct 1, 2026
Merged

edenreich merged 4 commits into
mainfrom
feat/headless-subagent-input

Conversation

@edenreich

@edenreich edenreich commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1456

What

SendSubagentInput only reached interactive (tmux) subagents. A headless subagent, the default, got /dev/null as stdin and exited after its first turn, so the main agent could only wait for its result or kill it.

  • infer headless --keep-alive: after the task it runs each run_agent_input frame read on stdin as a further turn in the same session, reports every finished turn as one subagent_turn line on stdout and exits when stdin closes. --result-file keeps its once-on-exit semantics.
  • The Agent tool spawns async headless subagents this way over an os.Pipe whose write end it keeps. The job reports each turn as its own [Subagent Completed: <label>] note, closes an idle child after tools.agent.idle_timeout with one [Subagent Closed: <label>] note, and reports itself idle between turns (JobIdleReporter) so a headless parent does not wait for it. The composer list and /tasks show an idle subagent as completed and flip it back to running on a follow-up.
  • SendSubagentInput with text writes a message to a headless subagent as its next turn. keys and submit=false stay interactive-only and fail for a headless target.
  • tools.agent.wait: true is unchanged: a blocking subagent returns its first turn and is not kept alive.
  • AskUserQuestion is not offered to a keep-alive subagent: with stdin held open nobody would answer, so it would hang until the idle timeout. Today it is auto-dismissed on EOF, so this only removes a dead tool.

Deviation from the issue's sketch: the child reports turns on stdout instead of rewriting the result file for the parent to poll, since the parent already owns the stdout pipe. The acceptance criteria are unchanged.

Tests

  • go test -race ./... and task precommit:run pass.
  • New: keep-alive job lifecycle (two turns, queued turn stays running, idle close, requested stop is silent, crash reports failure), SendSubagentInput headless cases, agentrunner stdin pass-through, validateOptions keep-alive rows, HasPending skips idle jobs (counterfeiter FakeJobIdleReporter), and an e2e TestHeadlessKeepAlive against the built binary and the mock gateway.

Docs

docs/subagents.md gains a Headless Subagents section. docs/tools-reference.md, docs/configuration-reference.md and docs/commands-reference.md are updated. Tool manifests and the golden file are regenerated.

Impacted repos: inference-gateway/docs, tracked in inference-gateway/docs#894 for the new --keep-alive flag and the headless subagent lifecycle.

SendSubagentInput only reached interactive (tmux) subagents. A headless
subagent, the default, got /dev/null as stdin and exited after its
first turn, so the main agent could only wait for its result or kill it.

infer headless gains --keep-alive: after the task it runs each
run_agent_input frame read on stdin as a further turn in the same
session, reports every finished turn as one subagent_turn line on
stdout and exits when stdin closes. The Agent tool spawns async headless
subagents this way over an os.Pipe it keeps the write end of.

The keep-alive job reports each turn as its own [Subagent Completed]
note, closes an idle child after tools.agent.idle_timeout with one
[Subagent Closed] note and reports itself idle between turns so a
headless parent does not wait for it. SendSubagentInput writes a text
message to a headless subagent as its next turn. keys and submit=false
stay interactive-only. tools.agent.wait: true is unchanged.

Closes #1456
@edenreich
edenreich requested a review from a team as a code owner October 1, 2026 22:22
A keep-alive subagent emitted its turn notes while holding its mutex.
The supervisor hands a note to the UI, whose render reads the job back
through Idle and Stats under the same mutex, so the chat TUI deadlocked
the moment a headless subagent finished its first turn.

Notes are now built under the lock and emitted after it. The task views
also read an idle keep-alive subagent as completed, the way its note
says, and as running again once a follow-up is sent.
@edenreich
edenreich merged commit 9bab65c into main Oct 1, 2026
5 checks passed
@edenreich
edenreich deleted the feat/headless-subagent-input branch October 1, 2026 22:57
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included 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

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant