langchain-ai/deepagents · error · ValueError

Goal criteria request requires a request_id.

Error message

Goal criteria request requires a request_id.

What it means

The goal-criteria middleware validates every incoming goal-criteria request dict before acting on it. The `request_id` field is required and must be a non-blank string, because it is used to correlate the proposal with the caller's turn. `_goal_criteria_request` raises this `ValueError` when the key is absent, not a string, or only whitespace.

Source

Thrown at libs/code/deepagents_code/goal_rubric.py:1220

    Returns:
        A normalized typed request: a `GoalAmendRequest` when `kind` is amend
        (with `criteria` and `feedback` guaranteed present), otherwise a
        `GoalCreateRequest`. Fields not valid for the resolved kind are dropped.

    Raises:
        TypeError: If the request or one of its fields has the wrong type.
        ValueError: If a required request value is missing or invalid.
    """
    if not isinstance(value, dict):
        msg = "Goal criteria request must be an object."
        raise TypeError(msg)
    request_id = value.get("request_id")
    kind = value.get("kind")
    objective = value.get("objective")
    if not isinstance(request_id, str) or not request_id.strip():
        msg = "Goal criteria request requires a request_id."
        raise ValueError(msg)
    if kind not in {"create", "amend"}:
        msg = "Goal criteria request kind must be create or amend."
        raise ValueError(msg)
    if not isinstance(objective, str) or not objective.strip():
        msg = "Goal criteria request requires an objective."
        raise ValueError(msg)

    # Values are validated for non-blankness but stored verbatim (not stripped):
    # this feature deliberately preserves the user's exact goal/criteria wording,
    # and the prompt builders wrap each value in explicit XML boundaries.
    optional: dict[str, str] = {}
    for key in ("criteria", "feedback", "previous_criteria"):
        item = value.get(key)
        if item is None:
            continue
        if not isinstance(item, str):
            msg = f"Goal criteria request field {key} must be text."
            raise TypeError(msg)

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Add a `request_id` key with a non-empty string value (e.g. a uuid4 string) to the request dict.
  2. Coerce non-string ids with `str(value)` before dispatching the request.
  3. Check the state for a stale goal-criteria request written by an older version and clear it or upgrade its shape.

Example fix

// before
request = {"kind": "create", "objective": "Ship feature"}
// after
import uuid
request = {"request_id": str(uuid.uuid4()), "kind": "create", "objective": "Ship feature"}
Defensive patterns

Strategy: validation

Validate before calling

request_id = value.get("request_id")
if not isinstance(request_id, str) or not request_id.strip():
    raise ValueError("goal criteria request needs a non-blank string request_id")

Type guard

def has_valid_request_id(value: dict) -> bool:
    rid = value.get("request_id")
    return isinstance(rid, str) and bool(rid.strip())

Try / catch

try:
    run_middleware(state)
except ValueError as e:
    if "requires a request_id" in str(e):
        state["goal_request"]["request_id"] = str(uuid.uuid4())
        run_middleware(state)

Prevention

When it happens

Trigger: Calling the middleware hook path (`before_agent`/`abefore_agent`) with a state payload whose goal-criteria request dict lacks `request_id`, sets it to `None`/`""`/`" "`, or sets it to a non-string like an int or dict.

Common situations: Hand-crafted or older persisted state that predates the `request_id` field; a client building the request dict manually and forgetting the key; deserialized JSON where the id was serialized as a number.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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