{"record":{"id":"22a2ddc01696f55d","repo":"langchain-ai/langgraph","slug":"an-asyncio-future-a-coroutine-or-an-awaitable-is","errorCode":null,"errorMessage":"An asyncio.Future, a coroutine or an awaitable is required. Got {type(coro_or_future).__name__} instead.","messagePattern":"An asyncio\\.Future, a coroutine or an awaitable is required\\. Got (.+?) instead\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/langgraph/langgraph/_internal/_future.py","lineNumber":159,"sourceCode":"\n\ndef _ensure_future(\n    coro_or_future: Coroutine[None, None, T] | Awaitable[T],\n    *,\n    loop: asyncio.AbstractEventLoop,\n    name: str | None = None,\n    context: contextvars.Context | None = None,\n    lazy: bool = True,\n) -> asyncio.Task[T]:\n    called_wrap_awaitable = False\n    if not asyncio.iscoroutine(coro_or_future):\n        if inspect.isawaitable(coro_or_future):\n            coro_or_future = cast(\n                Coroutine[None, None, T], _wrap_awaitable(coro_or_future)\n            )\n            called_wrap_awaitable = True\n        else:\n            raise TypeError(\n                \"An asyncio.Future, a coroutine or an awaitable is required.\"\n                f\" Got {type(coro_or_future).__name__} instead.\"\n            )\n\n    try:\n        if CONTEXT_NOT_SUPPORTED:\n            return loop.create_task(coro_or_future, name=name)\n        elif EAGER_NOT_SUPPORTED or lazy:\n            return loop.create_task(coro_or_future, name=name, context=context)\n        else:\n            return asyncio.eager_task_factory(\n                loop, coro_or_future, name=name, context=context\n            )\n    except RuntimeError:\n        if not called_wrap_awaitable:\n            coro_or_future.close()\n        raise\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/langchain-ai/langgraph/blob/38031739e551638e373fb553453256c23feeb41f/libs/langgraph/langgraph/_internal/_future.py#L141-L177","documentation":"_ensure_future accepts coroutines and awaitables; if the argument is neither a coroutine nor an inspect-able awaitable (and not a future), TypeError is raised naming the actual type received, since it cannot be scheduled on the loop.","triggerScenarios":"Thrown at libs/langgraph/langgraph/_internal/_future.py:159 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a coroutine, an awaitable, or a Future to _ensure_future.","If calling a plain function, call it first to obtain a coroutine (fn() not fn)."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"38031739e551638e373fb553453256c23feeb41f","analyzedAt":"2026-08-26T18:02:49.312Z","contentChangedAt":"2026-08-26T18:02:49.312Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}