-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix: No context vars for async agents replies #4640
fix: No context vars for async agents replies #4640
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 0.2 #4640 +/- ##
=======================================
Coverage 29.30% 29.30%
=======================================
Files 117 117
Lines 13013 13021 +8
Branches 2469 2470 +1
=======================================
+ Hits 3813 3816 +3
- Misses 8854 8859 +5
Partials 346 346
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Looks good to me. @davorrunje FYI.
Why are these changes needed?
The Autogen currently utilizes the
asyncio.get_event_loop().run_in_executor()
method for generating async agent replies. However, this approach presents a challenge if the application decorates OpenAI calls (such asopenai.resources.chat.completions.AsyncCompletions.create
) for purposes like call tracing or statistics measurement. The problem is that context variables cannot be accessed in this setup.To address this issue, suggested to use
contextvars.copy_context().run()
method. This change will allow context variables to be properly propagated and accessed.Related issue number
Checks