Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pyagentspec/src/pyagentspec/adapters/langgraph/mcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ class AsyncContext(Enum):
SYNC_WORKER = "sync_worker"


# anyio.NoEventLoopError was added in anyio 4.11. anyio 4.10 is still supported
# (via the langgraph/evaluation extras), where the attribute does not exist.
# Once the minimum anyio version is ≥ 4.11, replace this with a plain
# tuple and catch anyio.NoEventLoopError directly (commented out below)
_NO_LOOP_ERRORS: tuple[type[BaseException], ...] = (AsyncLibraryNotFoundError,)
if hasattr(anyio, "NoEventLoopError"):
_NO_LOOP_ERRORS = (*_NO_LOOP_ERRORS, anyio.NoEventLoopError)


def get_execution_context() -> AsyncContext:
"""
Return one of:
Expand All @@ -93,7 +102,8 @@ def get_execution_context() -> AsyncContext:
try:
anyio.get_current_task()
return AsyncContext.ASYNC
except AsyncLibraryNotFoundError:
# except (AsyncLibraryNotFoundError, anyio.NoEventLoopError): # anyio>4.10
except _NO_LOOP_ERRORS:
current_thread = from_thread.current_thread() # type: ignore
worker_name = current_thread.name.lower()
if "worker" in worker_name and "anyio" in worker_name:
Expand Down
Loading