added condition to check whether _run function returns a coroutine ob… (#2570)

* added condition to check whether _run function returns a coroutine object

* Cleaned the code

* Fixed the test modules, Class -> Functions
This commit is contained in:
Vidit Ostwal
2025-04-11 22:26:37 +05:30
committed by GitHub
parent 0cd524af86
commit ea5ae9086a
2 changed files with 79 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import warnings
from abc import ABC, abstractmethod
from inspect import signature
@@ -65,7 +66,13 @@ class BaseTool(BaseModel, ABC):
**kwargs: Any,
) -> Any:
print(f"Using Tool: {self.name}")
return self._run(*args, **kwargs)
result = self._run(*args, **kwargs)
# If _run is async, we safely run it
if asyncio.iscoroutine(result):
return asyncio.run(result)
return result
@abstractmethod
def _run(