-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: Enhanced async tool support for smolagents #1485
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
base: main
Are you sure you want to change the base?
Conversation
- Convert GoogleSearchTool, ApiWebSearchTool, and WebSearchTool to async - Improve async/sync detection and handling in Tool base class - Enhanced ToolCallingAgent with better async tool execution - Add comprehensive async support for web search tools using aiohttp - Add more tools to TOOL_MAPPING for better discoverability - Maintain backward compatibility with sync tool calls - Support concurrent async tool execution for better performance Key improvements: - All web-based tools (search, webpage visiting) now use async HTTP requests - Tools automatically detect if they're async and handle accordingly - Agents seamlessly handle mixed sync/async tool execution - Better error handling and timeout management for async operations - Full backward compatibility - sync calls on async tools still work
Thank you, will have a look! Meanwhile you'll probably need to do a (complicated) rebase on #1482 that will be merged first |
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.
Pull Request Overview
This PR enhances async tool support in smolagents by converting several tools to async, improving async/sync detection, and improving error handling and performance when executing tools concurrently.
- Converted tool forward methods to async and added acall methods where needed.
- Improved handling of mixed async/sync invocations through event loop detection and thread pool execution.
- Enhanced error messaging and expanded TOOL_MAPPING for better discoverability.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/smolagents/tools.py | Added async support and a new acall method in the Tool base class. |
src/smolagents/default_tools.py | Converted synchronous web search and page visit logic to async, with thread pool wrappers for blocking calls and enhanced error handling. |
src/smolagents/agents.py | Updated agent execution flow to support async tool calls and consolidated async-to-sync handling logic. |
Comments suppressed due to low confidence (1)
src/smolagents/agents.py:1416
- The async-to-sync handling logic via thread pool is duplicated; consider refactoring this pattern into a shared helper function to improve maintainability and reduce code duplication.
# We need to handle this differently - for now we'll use asyncio.run_coroutine_threadsafe
src/smolagents/tools.py
Outdated
if loop.is_running(): | ||
# We're in an async context, but __call__ is sync | ||
# Create a new thread with its own event loop to run the async function | ||
import concurrent.futures |
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.
Consider moving the import of 'concurrent.futures' to the module level to reduce repetitive imports and improve startup performance in call.
import concurrent.futures |
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Key improvements: