langchain-ai/deepagents · error · TypeError

context.auto_approve must be a boolean or null, got {type(au

Error message

context.auto_approve must be a boolean or null, got {type(auto_approve).__name__}.

What it means

`context.auto_approve` controls whether offload operations are auto-approved and must be strictly a bool or null. Passing a truthy value like "true", 1, or "yes" is rejected because the SDK does not coerce — silent coercion of config strings is a common source of misconfiguration. The check runs inside _validate_context during payload preparation.

Source

Thrown at libs/code/deepagents_code/offload_api.py:481

        if value is not None and not isinstance(value, dict):
            msg = f"context.{key} must be an object, got {type(value).__name__}."
            raise TypeError(msg)
    limit = context.get("model_context_limit")
    # bool is an int subclass, so exclude it explicitly: JSON `true` is not a
    # token limit.
    if limit is not None and (isinstance(limit, bool) or not isinstance(limit, int)):
        msg = (
            "context.model_context_limit must be an integer or null, "
            f"got {type(limit).__name__}."
        )
        raise TypeError(msg)
    auto_approve = context.get("auto_approve")
    if auto_approve is not None and not isinstance(auto_approve, bool):
        msg = (
            f"context.auto_approve must be a boolean or null, "
            f"got {type(auto_approve).__name__}."
        )
        raise TypeError(msg)
    events = context.get("hooks_server_events")
    if events is not None and (
        not isinstance(events, list)
        or any(not isinstance(event, str) for event in events)
    ):
        msg = "context.hooks_server_events must be a list of strings or null."
        raise TypeError(msg)


def _checkpoint_id(state: Mapping[str, object]) -> str:
    checkpoint = state.get("checkpoint")
    value = checkpoint.get("checkpoint_id") if isinstance(checkpoint, Mapping) else None
    if not isinstance(value, str) or not value:
        msg = "The thread has no checkpoint to offload."
        raise _OffloadConflictError(msg)
    return value

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Coerce deliberately: auto_approve = str(value).lower() in ('1','true','yes') before building context.
  2. If loaded from env, map {'true','1','yes'} -> True, {'false','0','no'} -> False, missing -> None.
  3. Remove the key or pass None when auto-approval behavior is not being configured.
  4. Audit your config source so the field is serialized as a real JSON boolean, not a string.

Example fix

// before
context = {"auto_approve": os.environ.get("AUTO_APPROVE", "true")}
// after
raw = os.environ.get("AUTO_APPROVE")
context = {"auto_approve": raw.lower() in ("1", "true", "yes") if raw is not None else None}
Defensive patterns

Strategy: validation

Validate before calling

def validate_auto_approve(value):
    return value is None or isinstance(value, bool)
# call before offload: assert validate_auto_approve(ctx.get("auto_approve"))

Type guard

def is_bool_or_none(value) -> bool:
    return value is None or isinstance(value, bool)

Try / catch

try:
    state = await offload(thread_id, payload)
except TypeError as exc:
    if "auto_approve" in str(exc):
        raw = payload["context"].get("auto_approve")
        payload["context"]["auto_approve"] = str(raw).lower() in ("1", "true", "yes")
        state = await offload(thread_id, payload)
    else:
        raise

Prevention

When it happens

Trigger: Calling offload() with context={'auto_approve': 'true'}, {'auto_approve': 1}, {'auto_approve': 'yes'}, or any non-bool object; JSON configs where auto_approve was serialized as a string.

Common situations: YAML/JSON config files that quote booleans (auto_approve: "true"), environment variables (all env vars are strings), older configs written before strict typing was enforced, or frontend forms sending 'on'/'off' strings.

Related errors


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