fix(common): async execution helper for awaitable coroutine objects#1248
fix(common): async execution helper for awaitable coroutine objects#1248dipeshbabu wants to merge 3 commits intoagentscope-ai:mainfrom
Conversation
Summary of ChangesHello @dipeshbabu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the reliability and correctness of asynchronous function execution within AgentScope by addressing how awaitable objects are handled. It refines the core utility for executing both synchronous and asynchronous functions, ensuring that pre-existing awaitables are correctly awaited rather than mistakenly invoked as callables. Additionally, it improves the robustness of temporary file operations in the configuration loading mechanism, preventing potential resource leaks. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request provides a much-needed fix for the _execute_async_or_sync_func helper, making it more robust in handling various awaitable and callable types. The new implementation correctly distinguishes between awaitable objects and callables, preventing runtime errors that could occur with the previous logic. The changes in src/agentscope/tuner/_config.py to handle temporary files are also a good improvement, especially for cross-platform compatibility.
My review focuses on ensuring adherence to the repository's coding standards. I've identified a couple of instances where the docstrings for the updated functions in _utils/_common.py do not conform to the required format specified in the style guide. I've provided suggestions to align them with the project's standards.
Overall, this is a solid contribution that improves the reliability of asynchronous execution within the library.
ad1b5d4 to
1417ed3
Compare
|
@DavdGao could you review this one as well? |
AgentScope version
0.1.5
Description
_execute_async_or_sync_funccan mis-handle coroutine objects and other awaitables. If an already-created awaitable (such as a coroutine returned by calling an async function, or an asyncio Task/Future) is passed in, the previous logic may treat it like a callable and attemptawait func(*args, **kwargs), which can raise runtime errors because awaitable objects are not callable. The previous_is_async_funclogic also had operator precedence pitfalls and mixed generator checks that could lead to incorrect classification.Purpose
Make
_execute_async_or_sync_funcreliable for all supported async and sync execution paths, including async callables, sync callables that return awaitables, and already-created awaitable objects, while keeping behavior unchanged for normal synchronous functions.Changes made
Add a robust execution strategy:
If
funcis an awaitable object (coroutine, Task, Future), await it directly and disallow args and kwargs. Otherwise requirefuncto be callable, call it, and if the return value is awaitable, await the result. Replace the previous async classification helper with a simpler_is_async_callablethat only checks coroutine functions (including partials).How to test
Run a small script that calls
_execute_async_or_sync_funcwith an async function, a sync function, a sync function that returns a coroutine, a coroutine object (af()), and an asyncio Task. Confirm all return expected results without TypeError.Checklist
Please check the following items before code is ready to be reviewed.
pre-commit run --all-filescommand