diff --git a/libs/langchain/langchain/tools/python/tool.py b/libs/langchain/langchain/tools/python/tool.py index d5ae950927..a820ba6140 100644 --- a/libs/langchain/langchain/tools/python/tool.py +++ b/libs/langchain/langchain/tools/python/tool.py @@ -131,3 +131,15 @@ class PythonAstREPLTool(BaseTool): return io_buffer.getvalue() except Exception as e: return "{}: {}".format(type(e).__name__, str(e)) + + async def _arun( + self, + query: str, + run_manager: Optional[AsyncCallbackManagerForToolRun] = None, + ) -> Any: + """Use the tool asynchronously.""" + + loop = asyncio.get_running_loop() + result = await loop.run_in_executor(None, self._run, query) + + return result