mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-24 17:31:41 +00:00

<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? ## Prevent Async Event Loop from Running Indefinitely ### Description This pull request addresses a bug in the python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py `async send_message` function where messages were being queued for recipients that were not recognized. The current implementation sets an exception on the future object when the recipient is not found, but continues to enqueue the message, potentially leading to inconsistent states. ### Changes Made - Added a return statement immediately after setting the exception when the recipient is not found. This ensures that the function exits early, preventing further processing of the message and avoiding unnecessary operations. - This fix also addresses an issue where the asynchronous event loop could potentially continue running indefinitely without terminating, due to the future not being properly handled when an unknown recipient is encountered. ### Impact This fix prevents messages from being sent to unknown recipients. It also ensures that the event loop can terminate correctly without being stuck in an indefinite state. ### Testing Ensure that the function correctly handles cases where the recipient is not recognized by returning the exception without enqueuing the message, and verify that the event loop terminates as expected. <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed. Co-authored-by: Wanfeng Ge (葛万峰) <wf.ge@trip.com> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
AutoGen Core
AutoGen core offers an easy way to quickly build event-driven, distributed, scalable, resilient AI agent systems. Agents are developed by using the Actor model. You can build and run your agent system locally and easily move to a distributed system in the cloud when you are ready.