Skip to content
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

Merged
merged 3 commits into from
Dec 14, 2024

Conversation

violonistahiles
Copy link

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 as openai.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

@rysweet rysweet requested review from ekzhu and jackgerrits December 10, 2024 17:22
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 29.30%. Comparing base (8a8fcd8) to head (61b70b9).
Report is 4 commits behind head on 0.2.

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           
Flag Coverage Δ
unittests 29.30% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ekzhu ekzhu added the 0.2 Issues which are related to the pre 0.4 codebase label Dec 12, 2024
Copy link
Collaborator

@ekzhu ekzhu left a 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.

@ekzhu ekzhu merged commit ee491c0 into microsoft:0.2 Dec 14, 2024
35 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2 Issues which are related to the pre 0.4 codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants