langchain-ai/langgraph · error · TypeError

An asyncio.Future, a coroutine or an awaitable is required…

Error message

An asyncio.Future, a coroutine or an awaitable is required. Got {type(coro_or_future).__name__} instead.

What it means

_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.

Solutions

  1. Pass a coroutine, an awaitable, or a Future to _ensure_future.
  2. If calling a plain function, call it first to obtain a coroutine (fn() not fn).
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at libs/langgraph/langgraph/_internal/_future.py:159 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26). Data as JSON: /api/errors/22a2ddc01696f55d. Report an issue: GitHub.

Appendix: source

Thrown at libs/langgraph/langgraph/_internal/_future.py:159


def _ensure_future(
    coro_or_future: Coroutine[None, None, T] | Awaitable[T],
    *,
    loop: asyncio.AbstractEventLoop,
    name: str | None = None,
    context: contextvars.Context | None = None,
    lazy: bool = True,
) -> asyncio.Task[T]:
    called_wrap_awaitable = False
    if not asyncio.iscoroutine(coro_or_future):
        if inspect.isawaitable(coro_or_future):
            coro_or_future = cast(
                Coroutine[None, None, T], _wrap_awaitable(coro_or_future)
            )
            called_wrap_awaitable = True
        else:
            raise TypeError(
                "An asyncio.Future, a coroutine or an awaitable is required."
                f" Got {type(coro_or_future).__name__} instead."
            )

    try:
        if CONTEXT_NOT_SUPPORTED:
            return loop.create_task(coro_or_future, name=name)
        elif EAGER_NOT_SUPPORTED or lazy:
            return loop.create_task(coro_or_future, name=name, context=context)
        else:
            return asyncio.eager_task_factory(
                loop, coro_or_future, name=name, context=context
            )
    except RuntimeError:
        if not called_wrap_awaitable:
            coro_or_future.close()
        raise

View on GitHub (pinned to 38031739e5)