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 a initiate chats #1938

Merged
merged 10 commits into from
Mar 17, 2024
Merged

Fix a initiate chats #1938

merged 10 commits into from
Mar 17, 2024

Conversation

randombet
Copy link
Collaborator

Why are these changes needed?

TLDR. The bug is at https://github.com/microsoft/autogen/blob/main/autogen/agentchat/chat.py#L214
When I used await inside an '''async with condition block'' that's controlling access to a shared resource with an asyncio.Condition, the coroutine will pause at the await and yield control back to the event loop. This does not block the entire program; rather, it allows other coroutines to run while this one is waiting.
However, the async with block will hold onto the condition's lock until the block is exited, which means other coroutines that want to acquire the condition (for example, to notify waiting coroutines that something has happened) will have to wait until the lock is released.

To fix the bug, the new approach is to use asyncio.Task to create a Task per chat. Chat Tasks will be executed once it is created. In detail,

await sender.a_initiate_chat(**chat_info) is wrapped inside Task.
None dependent chats could execute concurrently.
"await" the prerequisite chat results before create the new chat when necessary.

Related issue number

Checks

@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 56.09%. Comparing base (b4fb3c7) to head (f706d8a).
Report is 2 commits behind head on main.

Files Patch % Lines
autogen/agentchat/chat.py 95.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1938       +/-   ##
===========================================
+ Coverage   36.90%   56.09%   +19.18%     
===========================================
  Files          66       66               
  Lines        7031     7058       +27     
  Branches     1538     1668      +130     
===========================================
+ Hits         2595     3959     +1364     
+ Misses       4210     2768     -1442     
- Partials      226      331      +105     
Flag Coverage Δ
unittests 56.00% <95.23%> (+19.09%) ⬆️

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.

Copy link
Contributor

@qingyun-wu qingyun-wu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@qingyun-wu qingyun-wu added this pull request to the merge queue Mar 17, 2024
Merged via the queue into main with commit 96cbaf7 Mar 17, 2024
60 of 68 checks passed
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
* Fix async a_initiate_chats

* Fix type compatibility for python 3.8

* Use partial func to fix context error

* website/docs/tutorial/assets/conversable-agent.jpg: convert to Git LFS

* Update notebook examples

---------

Co-authored-by: Chi Wang <wang.chi@microsoft.com>
Co-authored-by: Davor Runje <davor@airt.ai>
@jackgerrits jackgerrits deleted the fix_a_initiate_chats branch September 25, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants