From fe8a87dbb177831de8600d704723eb9e3021aaf9 Mon Sep 17 00:00:00 2001 From: Deepankar Mahapatro Date: Sat, 7 Jun 2025 09:56:10 +0530 Subject: [PATCH] feat(tools): run sync tools in a thread --- src/agents/tool.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/agents/tool.py b/src/agents/tool.py index 57272f9f4..2a36a78b8 100644 --- a/src/agents/tool.py +++ b/src/agents/tool.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import inspect import json from collections.abc import Awaitable @@ -382,9 +383,9 @@ async def _on_invoke_tool_impl(ctx: RunContextWrapper[Any], input: str) -> Any: result = await the_func(*args, **kwargs_dict) else: if schema.takes_context: - result = the_func(ctx, *args, **kwargs_dict) + result = await asyncio.to_thread(the_func, ctx, *args, **kwargs_dict) else: - result = the_func(*args, **kwargs_dict) + result = await asyncio.to_thread(the_func, *args, **kwargs_dict) if _debug.DONT_LOG_TOOL_DATA: logger.debug(f"Tool {schema.name} completed.")