datawhalechina/hello-agents · error · ValueError

Unsupported latency_mode: {latency_mode}

Error message

Unsupported latency_mode: {latency_mode}

What it means

`_resolve_latency_mode` normalizes the latency_mode parameter (strip + lowercase) and raises ValueError if it is not one of the allowed enum values {'auto', 'quality', 'fast'}. It is a strict API-contract guard for the agent runner's latency/cost trade-off setting.

Source

Thrown at Co-creation-projects/healer-666-Academic-Data-Agent/src/data_analysis_agent/agent_runner.py:361

                    line += f" | {url}"
                if snippet:
                    line += f" | {snippet}"
                result_lines.append(line)
            if result_lines:
                parts.append("Top search results:\n" + "\n".join(result_lines))
            if len(results) > 3:
                parts.append(f"... {len(results) - 3} more result(s) omitted.")
        return "\n\n".join(parts)

    if text:
        parts.append(f"Observation text:\n{_truncate_text(text, 1200)}")
    return "\n\n".join(parts)


def _resolve_latency_mode(latency_mode: str) -> str:
    normalized_mode = latency_mode.strip().lower()
    if normalized_mode not in {"auto", "quality", "fast"}:
        raise ValueError(f"Unsupported latency_mode: {latency_mode}")
    return normalized_mode


def _resolve_vision_review_mode(vision_review_mode: str) -> str:
    normalized_mode = vision_review_mode.strip().lower()
    if normalized_mode not in {"off", "auto", "on"}:
        raise ValueError(f"Unsupported vision_review_mode: {vision_review_mode}")
    return normalized_mode


def _is_small_simple_dataset(data_context: DataContextSummary) -> bool:
    try:
        file_size_bytes = data_context.absolute_path.stat().st_size
    except OSError:
        file_size_bytes = 0
    rows, cols = data_context.shape
    return file_size_bytes <= 512 * 1024 and rows <= 2000 and cols <= 50

View on GitHub (pinned to 606a07d341)

Solutions

  1. Set latency_mode to one of 'auto', 'quality', or 'fast' (case-insensitive; surrounding whitespace is tolerated).
  2. If the field is optional on your side, omit it entirely rather than sending None/empty.
  3. Harden the resolver: `if not latency_mode: return 'auto'` before stripping, to give None a sane default.

Example fix

// before
normalized_mode = latency_mode.strip().lower()
if normalized_mode not in {"auto", "quality", "fast"}:
    raise ValueError(f"Unsupported latency_mode: {latency_mode}")

# after
normalized_mode = (latency_mode or "auto").strip().lower()
if normalized_mode not in {"auto", "quality", "fast"}:
    raise ValueError(f"Unsupported latency_mode: {latency_mode}")
Defensive patterns

Strategy: type-guard

Validate before calling

LATENCY_MODES = {"auto", "quality", "fast"}

def validate_latency_mode(mode: str | None) -> str:
    normalized = (mode or "auto").strip().lower()
    if normalized not in LATENCY_MODES:
        raise ValueError(f"latency_mode must be one of {sorted(LATENCY_MODES)}, got {mode!r}")
    return normalized

Type guard

from typing import Literal

LatencyMode = Literal["auto", "quality", "fast"]

def is_latency_mode(value: object) -> TypeGuard[LatencyMode]:
    return isinstance(value, str) and value.strip().lower() in {"auto", "quality", "fast"}

Try / catch

try:
    run_analysis(data_path, latency_mode=mode)
except ValueError as e:
    if "latency_mode" in str(e):
        mode = "auto"  # fall back to default and re-run
        run_analysis(data_path, latency_mode=mode)
    else:
        raise

Prevention

When it happens

Trigger: Passing latency_mode='balanced', 'HIGH' (ok after normalization... actually 'high' still not allowed), 'turbo', None (AttributeError on .strip instead), or a typo like 'fasr' to the analysis run API; only 'auto', 'quality', 'fast' (case-insensitive) pass.

Common situations: Callers copying a mode name from a different tool's docs, config files edited by hand with typos, or client code sending the field when it was never set (None → .strip() crashes before validation).

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/14182b68854f2dab. Report an issue: GitHub.