huggingface / huggingface/smolagents
Async tool support
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 29.4k
- Forks
- 3k
- Avg merge
- 17m
- Merged PRs (30d)
- 2
Description
Are async functions currently unsupported, or is there a workaround for tools that rely on asynchronous behaviour?
For example, I have a tool that retrieves data asynchronously from various web resources, and the agent needs to await these responses:
@tool
async def retrieve_datasets(query: str, retriever: RepoRetriever) -> dict:
"""
This tool can be used to retrieve metadata from different repositories.
Note this is a async function and needs to be awaited.
Args:
query: The query string to search for.
retriever: An instance of the RepoRetriever class.
"""
response = await(retriever.query_all_repos(query))
top_5_results = response.get("results", [])[:5]
return top_5_results
Attempting to use this tool results in the following error:
─ Executing this code: ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
precipitation_data = await retrieve_datasets(query="precipitation data", retriever=retriever)
print(precipitation_data)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Code execution failed at line 'precipitation_data = await retrieve_datasets(query="precipitation data", retriever=retriever)' because of the following error:
Await is not supported.
Is there a recommended approach to handle asynchronous tools in such scenarios? Any guidance would be greatly appreciated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example async tool and tracing the tool execution path to the code-execution handling that reports "Await is not supported." Check existing tool-execution tests or documentation for related behavior; done should mean async tools have a defined supported behavior or a documented workaround, backed by a regression test if execution behavior changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100