Conversation
Adds opt-in background execution to the AG-UI interface. Foreground runs are untouched and remain the default. A client opts in per run with forwardedProps.agnoBackground.enabled. The interface starts the run detached, then streams it by tailing Agno's buffered indexed event stream rather than the live producer. Every emitted AG-UI event carries a resume cursor in metadata.agnoBackground: the index of the Agno event it came from plus its ordinal within that event's expansion. A client that drops the connection reconnects with that cursor, receives the buffered remainder exactly once in canonical order, and continues live to completion. Ordinary messages, tool calls, tool results, state snapshots and deltas, errors and terminal events all survive the round trip. Message ids are minted deterministically for background runs so a replay reproduces the ids the first connection saw; foreground keeps random ids. Both agents and teams are covered. Support is probed at runtime rather than by version, and a request the entity cannot honor is refused with a run error instead of being silently downgraded or re-run. A cursor that points past a trimmed buffer is refused rather than answered with a gap. Consumes Agno's existing detached execution, event buffer, replay and tailing without modifying them. Tests cover replay ordering and exactly-once delivery deterministically, plus a real uvicorn server with an actual mid-stream disconnect and reconnect over HTTP, for both agents and teams.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in background execution to the AG-UI interface, so a run can outlive the request that started it and a client that disconnects can reconnect and pick up exactly where it left off.
Today an AG-UI run is executed inside the HTTP request handler. If the client goes away mid-run, the request is cancelled and the run dies with it. A long run is therefore only as durable as the browser tab that started it.
Agno already has everything needed to fix that: detached execution, a buffer of indexed run events, replay and tailing. This change consumes those from the AG-UI interface rather than adding anything alongside them.
How it works
A client opts in per run through
forwardedProps.agnoBackground.enabled. Foreground stays the default and is untouched, down to carrying no added metadata. The interface starts the run detached and streams it by tailing the buffered event stream instead of the live producer, stamping a resume cursor on every event undermetadata.agnoBackground. The cursor has two parts, the index of the Agno event and the ordinal within its expansion, because one Agno event can become several AG-UI events and a resuming client has to be able to land in the middle of one.To resume, the client sends the same
runIdback with its last cursor. Everything up to that point is filtered out, the rest of the buffer is replayed in canonical order, and the stream continues live to completion. Messages, tool calls, tool results, state, errors and terminal events all survive the round trip, and message ids are minted deterministically for background runs so a replay reproduces the ids the first connection already saw.Support is probed at runtime rather than inferred from a version, and a request that cannot be honored is refused with a run error rather than silently re-executed.
Agents and teams are both covered.
Type of change
Checklist
./scripts/format.shand./scripts/validate.sh)Duplicate and AI-Generated PR Check