Skip to content

Conversation

h9-tec
Copy link

@h9-tec h9-tec commented Jun 25, 2025

  • 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

- 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
@aymeric-roucher
Copy link
Collaborator

aymeric-roucher commented Jun 26, 2025

Thank you, will have a look! Meanwhile you'll probably need to do a (complicated) rebase on #1482 that will be merged first

@albertvillanova albertvillanova requested a review from Copilot June 26, 2025 14:07
Copy link
Contributor

@Copilot Copilot AI left a 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

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
Copy link
Preview

Copilot AI Jun 26, 2025

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.

Suggested change
import concurrent.futures

Copilot uses AI. Check for mistakes.

h9-tec and others added 3 commits July 2, 2025 16:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants