Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Avoid unwanted exception chaining when running async tool in sync context (#9092)

YR Chend42f29ef4489
diff --git a/dspy/adapters/types/tool.py b/dspy/adapters/types/tool.py
index 16f2cb580..e6614837d 100644
--- a/dspy/adapters/types/tool.py
+++ b/dspy/adapters/types/tool.py
@@ -166,8 +166,11 @@ class Tool(Type):
try:
loop = asyncio.get_running_loop()
except RuntimeError:
- return asyncio.run(coroutine)
+ # Run the coroutine outside of "except" block to avoid propagation
+ loop = None
+ if loop is None:
+ return asyncio.run(coroutine)
return loop.run_until_complete(coroutine)
@with_callbacks