Skip to content

An AI Agent that interacts with Windows OS at GUI level.

Python

fix: handle async tools in synchronous Tool.invoke()

jeomon36b0c65b658e
diff --git a/windows_use/tools/service.py b/windows_use/tools/service.py
index 66a64fa..f1c1c04 100644
--- a/windows_use/tools/service.py
+++ b/windows_use/tools/service.py
@@ -87,7 +87,10 @@ class Tool(ABC):
def invoke(self, *args, **kwargs):
"""Synchronous invocation. Use ainvoke for async tools."""
try:
- return self.function(*args, **kwargs)
+ result = self.function(*args, **kwargs)
+ if asyncio.iscoroutine(result):
+ return asyncio.run(result)
+ return result
except Exception as e:
logger.error(f"Error invoking tool {self.name}: {e}")
raise