-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: (AG-UI) Support service-managed thread on AG-UI #3136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Python: (AG-UI) Support service-managed thread on AG-UI #3136
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for service-managed threads in AG-UI to properly handle scenarios where backend services (like Foundry Agent) manage thread IDs. The changes address issues where conversations weren't being properly continued because service thread IDs weren't recognized.
Key changes:
- Adds
supplied_thread_idandsupplied_run_idproperties toExecutionContextto distinguish user/system-provided IDs from auto-generated ones - Introduces
use_service_threadparameter toAgentFrameworkAgentandAgentConfigto enable service-managed thread creation - Delays emission of initial AG-UI events until after receiving the first backend update, allowing dynamic ID updates from service responses
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/ag-ui/tests/test_service_thread_id.py |
New test file for service thread ID tracking, verifying that conversation IDs from service responses are properly reflected in events |
python/packages/ag-ui/tests/test_orchestrators.py |
Enhanced existing tests with proper type hints and assertions for event types; updated DummyAgent to return proper conversation/response IDs |
python/packages/ag-ui/agent_framework_ag_ui/_utils.py |
Added utility function to extract conversation IDs from AgentRunResponseUpdate objects |
python/packages/ag-ui/agent_framework_ag_ui/_orchestrators.py |
Core changes: added supplied ID tracking, ID update methods, event bridge recreation logic, and delayed initial event emission |
python/packages/ag-ui/agent_framework_ag_ui/_agent.py |
Added use_service_thread parameter to configuration classes with proper documentation |
84f26bf to
11761fe
Compare
Motivation and Context
Currently, when using AG-UI with a service-managed thread (like, Foundry Agent), every message is seen as a new conversation because the service_thread_id is not being recognized.
There are a few implementation issues with the current AG-UI integration in Agent Framework when it comes to service-managed threads:
service_thread_idon every request/process, disregarding what's in theExecutionContext.ExecutionContextcannot distringuish if the thread id is supplied by the user/system or randomly generated, so it cannot reliably set theservice_thread_idvalue to theAgentThread(setting an id that's auto-generated as theservice_thread_idwill result in an exception).RunStartEvent) is sent back to the user at the start of the process before any real response is received from the agent backend, so a conversation will get a random GUID and not the real thread/conversation id.AgentFrameworkEventBridge, the mechanism that translates MAF updates to AG-UI events, is also created at the beginning of the process. The thread_id and run_id is set during instantiation, so the ids cannot (and should not) be changed after the event bridge is created.Description
Changes:
supplied_thread_idandsupplied_run_idinExecutionContext. This helps resolve Issue 2 as it helps distinguish if the id is auto-generated or supplied by an external source (user or system).use_service_threadargument to AG-UIAgentFrameworkAgent. This helps resolve Issue 1. Only if this option is set, is whenAgentThreadis created withservice_thread_id=context.supplied_thread_id.See below for a visual representation of the changes (left side is

main, right side is this PR):(Scenario: New conversation)
(Scenario: Continuing the conversation)

Contribution Checklist