Skip to content

Building AI agents, atomically

error handling for persistent session none, raise exception if not present

jon foxcde6838f6495
diff --git a/atomic-agents/atomic_agents/lib/factories/mcp_tool_factory.py b/atomic-agents/atomic_agents/lib/factories/mcp_tool_factory.py
index 8c8d947..b2b0fff 100644
--- a/atomic-agents/atomic_agents/lib/factories/mcp_tool_factory.py
+++ b/atomic-agents/atomic_agents/lib/factories/mcp_tool_factory.py
@@ -216,7 +216,10 @@ class MCPToolFactory:
if persistent_session is not None:
# Use the always‑on session/loop supplied at construction time.
- return cast(asyncio.AbstractEventLoop, loop).run_until_complete(self.arun(params))
+ try:
+ return cast(asyncio.AbstractEventLoop, loop).run_until_complete(self.arun(params))
+ except AttributeError as e:
+ raise RuntimeError(f"Failed to execute MCP tool '{tool_name}': {e}") from e
else:
# Legacy behaviour – run in new event loop.
return asyncio.run(self.arun(params))