Skip to content

Python: emit AG-UI RUN_STARTED before the agent runs when thread and run IDs are supplied - #8541

Open
Christian Glessner (ltwlf) wants to merge 1 commit into
microsoft:mainfrom
ltwlf:issue-8540
Open

Christian Glessner (ltwlf) wants to merge 1 commit into
microsoft:mainfrom
ltwlf:issue-8540

Conversation

@ltwlf

Copy link
Copy Markdown
Contributor

Motivation & Context

RUN_STARTED is held back until the agent's first update so that service-generated IDs can be used. When the request already supplies both threadId and runId that wait isn't needed. Context providers and the first model call can take seconds, and during that time the client gets no event at all. Since AG-UI requires RUN_STARTED first, the server can't send anything else in the meantime either (progress or activity events, for example).

Description & Review Guide

  • What are the major changes? The events that open a run (RUN_STARTED, PredictState, the initial state snapshot, approval results) are built in one helper. If both IDs are supplied they're emitted before the agent is called; otherwise they're still emitted on the first update, as before. The provider conversation id is still captured from the first update in both cases.
  • What is the impact of these changes? Clients that send both IDs see the run start right away. The IDs they receive don't change, since supplied IDs were never replaced. Requests without both IDs behave as before.
  • What do you want reviewers to focus on? That nothing else relied on RUN_STARTED being emitted after agent.run() had started streaming.

Related Issue

Fixes #8540

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

…run IDs are supplied

RUN_STARTED waited for the first agent update so that service-generated IDs could be used. When the request already carries both threadId and runId there is nothing to wait for, so emit it (with PredictState, the initial state snapshot and approval results) before calling the agent. Requests missing either ID keep the previous behaviour.

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

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AG-UI RUN_STARTED waits for the first agent update even when threadId and runId are supplied

1 participant