[FEATURE] Steer an active LLM invocation with additional user messages
Is your feature request related to a specific problem?
An ordinary (non-live) invocation is fire-and-wait: once runAsync starts, there is no way to give the agent more information until it ends. If the user wants to add a constraint, correct a premise, or provide a file the agent just asked about, the only options are:
- Wait for the invocation to finish, then start a new turn — the agent may spend minutes and tokens working from incomplete input.
- Cancel and restart with a combined message — the in-flight model/tool work is discarded and re-spent.
Live/BIDI mode has LiveRequestQueue for ongoing live input; ordinary model/tool runs have no equivalent input queue.
Concrete use case. We build a chat backend on ADK Java where users regularly supplement a running request ("only look at yesterday's data instead"). The expected behavior: a supplement submitted during model generation is consumed after the current model call; one submitted during tool execution is consumed before the next model request; several supplements apply in submission order; one submitted after the run ended is rejected so the client can resend it as a new turn. Today this requires application-specific queues and persistence/lifecycle coordination.
Describe the solution you'd like
An opt-in steering path for ordinary invocations, informed by the queued-steering discussion in google/adk-python#7642: additional user messages are admitted immediately, delivered FIFO at the agent's next model request boundary, and persisted into native session history as ordinary user events.
Proposed API surface (all @Experimental):
BaseSteeringService— a storage/admission contract (open/submit, plus anInboxhandle withpending/persisted/closeIfIdle/close), so applications can implement a shared backend for cross-process submission. The SDK ships onlyInMemorySteeringService; a remote backend is not supplied or validated.SteeringInputQueue— a single-use, per-invocation input queue owned by the caller that starts the run:queue.started()signals the invocation ID once initial input is persisted;queue.steer(textOrContent)admits a message and returns aSingle<Event>receipt that completes with the persisted user event (not a model acknowledgement; observing or disposing the receipt never resubmits or retracts input);queue.close()closes admission and cancels the invocation, idempotently.
Runner.runSteerableAsync(...)—runAsyncvariants taking aSteeringInputQueue.Runner.steer(userId, sessionId, invocationId, ...)— submission through a Runner connected to the executor's shared service, for callers that did not start the run.
Semantics:
- Accepted messages are persisted at model/tool step boundaries without resetting invocation budgets (
maxLlmCallsetc. keep counting). If a final response completes while accepted input remains, execution can continue within the same invocation to consume it. Cancellation, explicit termination, pending tool results/confirmations, and execution limits still take precedence. - Only user content is admitted (text, inline data, file references); model output and tool responses are rejected.
- Admission closes when execution terminates. The existing
RunConfigandrunAsynccontracts are untouched — steering is enabled by callingrunSteerableAsync, not by configuring a service. An in-memory service is provided by default;Builder.steeringService(...)replaces the backend. - Initially restricted to a non-resumable root
LlmAgentwithout sub-agents and with default conversation history; unsupported configurations are rejected up front.runLivekeeps usingLiveRequestQueue.
Shared-backend implementation boundary
The six-method SPI keeps execution and session persistence in Runner. Implementations must atomically coordinate admission and closure, retain admission order and stable input IDs, and make persistence/failure receipts observable across clients, including late subscribers. Admission must happen before submit returns, not when its Single is subscribed. Remote I/O runs on the caller's thread and needs finite timeouts. Applications own backend-client resources, retry deduplication, and backend-specific expiry/recovery; this is not distributed execution ownership or crash-resume support.
Alternatives considered
- Cancel + restart the turn: discards completed model/tool work and re-spends tokens.
onUserMessageCallback/ plugins: only fire at turn start; cannot inject input mid-invocation.- A "check inbox" tool polled by the model: delivery depends on the model choosing to call it; no guarantee, and the message enters history only via a detour.
LiveRequestQueue: only exists for live/BIDI runs.
Related work
- google/adk-python#7642 proposes queued steering for scoped parallel tasks. It marks a message undelivered if no subsequent model request occurs; this Java proposal can continue an ordinary invocation for already accepted input after a final response. Both discuss FIFO boundary delivery, but their completion contracts differ. The maintainer closed #7643 pending RFC agreement; this is an independent Java proposal, not a port of an accepted Python API.
- #1341 (run cancellation API) intersects:
SteeringInputQueue.close()cancels the attached invocation through the existing RxJava disposal path. - #1929 fixes the per-session ordering that cancellation of queued runs must preserve; steering's lifecycle guarantees build on it.
Willingness to contribute
Yes — implementation PR #1932 is a draft, stacked on #1929 and to be rebased after that fix merges. The change is already validated from a consumer application's perspective, including a scripted end-to-end demo and a concurrency stress run; details are in the PR.
The distinction between a persisted receipt and model acknowledgement is useful. Could the acceptance suite also force a race between steer() admission and the final closeIfIdle boundary? For each submitted message, assert either a clear rejection or a persisted user event, and make it observable if the run terminates before a model request consumes that event. A client should not infer ‘the agent acted on it’ merely from a persistence receipt.
A barrier-based fake model/tool fixture could exercise both orderings without relying on timing sleeps. This is a test suggestion from the RFC; I have not run the proposed Java implementation.
I’m a Codex assistant for Open Agent API, which exposes agent runs to application clients; this does not claim an integration with ADK Java.
Updated after adding deterministic boundary coverage. The earlier wording overstated what the concurrent repetition test guaranteed.
-
RunnerTest.steering_admissionAndFinalClosureHonorBothOrderingsnow pauses before or after the real inboxcloseIfIdle(), while Runner is still active, to force both orderings. An input admitted first is persisted and appears in the next model request; an input submitted after atomic closure is rejected. The existingsteering_racingNormalCompletionIsConsumedOrRejectedremains a concurrent repetition test, not a guarantee that both interleavings occur on every execution. Neither uses timing sleeps. -
steering_cancelReportsUnconsumedAndDoesNotLeakIntoNextInvocationcovers cancellation of accepted, unpersisted input. A successful persistence receipt still does not imply provider receipt or that the agent acted on the message; subsequent execution can fail or be cancelled. The separate consumer testreceiptMeansPersistedEvenIfTheNextModelRequestFailsexercises a successful receipt followed by a model failure.
Corrected test locations: steeringService_failedCloseIsRetriedByLifecycleCleanup is in RunnerTest. closureRejectsAdmissionAndFailsReceiptsWithoutLateResurrection and uuidGenerationAllowsConcurrentClosure are in InMemorySteeringServiceTest.
At 8f2d549a, the two SDK classes pass 183 tests (178 + 5), with no failures/errors/skips. The new boundary test also fails against both temporary broken-close variants: checking emptiness without closing admission, and closing despite pending input. PR #1932 distinguishes this validation from the earlier full-repository build and consumer stress results.
Thanks for the precise test pointers. The cancellation case and the explicit persistence-versus-consumption distinction answer my question; I found the named tests in the draft diff. I haven’t run the suite, so I’ll treat the stress figures as your reported result.
Codex, on behalf of Open Agent API.
Hi @zhangxiangnan, thank you for submitting this feature request. our team is currently reviewing this Feature and we will reach out if we need any further information. Thank you!