langchain-ai/deepagents · error · ValueError

A thread id and workspace context are required for execution

Error message

A thread id and workspace context are required for execution.

What it means

ValueError raised by make_graph when the execution runtime is present but the request lacks the two things needed to run: a workspace context in the execution payload and a non-empty thread_id in config.configurable. Without both, the server cannot resolve the thread's bound workspace.

Source

Thrown at libs/code/deepagents_code/server_graph.py:634

    return await _get_runtime()


async def make_graph(
    config: dict[str, Any] | None = None,
    runtime: LangGraphServerRuntime[CLIContextSchema] | None = None,
) -> Any:  # noqa: ANN401
    """Return the graph after validating execution workspace context.

    Raises:
        ValueError: If execution context is missing or malformed.
    """
    execution = runtime.execution_runtime if runtime is not None else None
    if execution is not None:
        context = CLIContextSchema.from_payload(execution.context)
        thread_id = (config or {}).get("configurable", {}).get("thread_id")
        if context is None or not isinstance(thread_id, str) or not thread_id:
            msg = "A thread id and workspace context are required for execution."
            raise ValueError(msg)
        from deepagents_code.workspace import require_thread_workspace

        binding = await require_thread_workspace(thread_id, context.workspace)
        return (await _workspace_runtime(binding)).agent
    return (await get_server_runtime()).agent

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Pass a non-empty thread_id: config={"configurable": {"thread_id": "<id>"}}
  2. Ensure the execution context payload includes valid workspace context before invoking
  3. If you intended no workspace execution, invoke without an execution runtime so it uses the default server runtime

Example fix

// before
agent = await make_graph({})  # no thread id

// after
agent = await make_graph({"configurable": {"thread_id": thread_id}})
# with execution.context containing workspace info
Defensive patterns

Strategy: validation

Validate before calling

thread_id = (config or {}).get("configurable", {}).get("thread_id")
if not isinstance(thread_id, str) or not thread_id:
    raise ValueError("thread_id is required in config.configurable")
if execution_context_payload.get("workspace") is None:
    raise ValueError("workspace context is required in execution context")

Type guard

def has_thread_id(config: dict | None) -> TypeGuard[dict]:
    tid = (config or {}).get("configurable", {}).get("thread_id")
    return isinstance(tid, str) and bool(tid)

Try / catch

try:
    agent = await make_graph(config)
except ValueError as e:
    if "thread id" in str(e):
        config = {"configurable": {"thread_id": new_thread_id()}}
        agent = await make_graph(config)
    else:
        raise

Prevention

When it happens

Trigger: Invoking the graph with an execution context whose payload yields context=None, or with config missing / containing an empty or non-string configurable.thread_id.

Common situations: Calling the agent programmatically without a thread_id; a client that lost its session state; race where context payload was cleared; test harness invoking execution path without proper configurable.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/54dca49f56a94a72. Report an issue: GitHub.