langchain-ai/deepagents · error · ValueError

Invalid recent startup mode: {mode!r}

Error message

Invalid recent startup mode: {mode!r}

What it means

save_recent_startup_mode persists the last explicitly chosen startup mode ('manual' or 'auto') to the `startup.recent` TOML field. Before saving it validates the mode against RECENT_STARTUP_MODES and raises ValueError('Invalid recent startup mode: {mode!r}') for anything else. `yolo` and other modes are deliberately excluded because they must remain explicitly configured, never stored as a recent mode.

Source

Thrown at libs/code/deepagents_code/model_config.py:6316


def save_recent_startup_mode(mode: str, config_path: Path | None = None) -> bool:
    """Save the most recently selected safe startup approval mode.

    Args:
        mode: `"manual"` or `"auto"`.
        config_path: Path to config file.

    Returns:
        `True` when the preference was saved, otherwise `False`.

    Raises:
        ValueError: If `mode` is not `"manual"` or `"auto"`. `yolo` must stay
            explicitly configured, so it is never stored as a recent mode.
    """
    if mode not in RECENT_STARTUP_MODES:
        msg = f"Invalid recent startup mode: {mode!r}"
        raise ValueError(msg)
    return _save_toml_field("startup", "recent", mode, config_path)


def save_thread_sort_order(sort_order: str, config_path: Path | None = None) -> bool:
    """Save the sort order preference for the thread selector.

    Args:
        sort_order: `"updated_at"` or `"created_at"`.
        config_path: Path to config file.

    Returns:
        True if save succeeded, False on I/O error.

    Raises:
        ValueError: If `sort_order` is not a recognised value.
    """
    if sort_order not in {"updated_at", "created_at"}:
        msg = (

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Only call with "manual" or "auto"; map other startup modes (like yolo) to one of the two or skip saving.
  2. Normalize case before calling: mode.lower() and validate membership in RECENT_STARTUP_MODES.
  3. Check the caller is not persisting a legacy config value; filter it through is_recent_startup_mode_restorable first.

Example fix

// before
save_recent_startup_mode(mode)  # mode may be "yolo"
// after
if mode in RECENT_STARTUP_MODES:
    save_recent_startup_mode(mode)
Defensive patterns

Strategy: type-guard

Validate before calling

RECENT_STARTUP_MODES = {"manual", "auto"}
if not isinstance(mode, str) or mode not in RECENT_STARTUP_MODES:
    return  # skip saving instead of raising

Type guard

def is_recent_startup_mode(mode: object) -> TypeGuard[str]:
    return isinstance(mode, str) and mode in {"manual", "auto"}

Try / catch

try:
    save_recent_startup_mode(mode)
except ValueError:
    logging.warning("Ignored non-restorable startup mode %r", mode)

Prevention

When it happens

Trigger: Calling save_recent_startup_mode("yolo"), save_recent_startup_mode(""), or any value other than "manual"/"auto" (case-sensitive), with an optional config_path.

Common situations: Passing a UI enum value straight through (e.g. 'yolo') without mapping to a restorable recent mode; capitalization mistakes ('Auto'); reading a stale/legacy value from config and echoing it back to save.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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