langchain-ai/deepagents · error · GoalStateSizeError

{label} is {actual} characters; maximum is {limit}. Remove a

Error message

{label} is {actual} characters; maximum is {limit}. Remove at least {excess} characters.

What it means

`validate_goal_objective` enforces `GOAL_OBJECTIVE_CHAR_LIMIT` (8,000 characters) on the persisted goal objective text. If the objective is longer, it raises `GoalStateSizeError` (a `ValueError` subclass) with the actual count, the limit, and the minimum number of characters to remove. The limit exists because the objective is embedded verbatim in model-visible goal-state notices.

Source

Thrown at libs/code/deepagents_code/goal_state_limits.py:144


def validate_goal_objective(objective: str) -> None:
    """Reject a goal objective that cannot fit its persistent context budget.

    This checks raw length only. HTML escaping can still expand the text
    fivefold, so a caller about to run criteria generation should also call
    `validate_goal_objective_rendered`: an objective that passes here can still
    leave no room for any criteria in the rendered notice.

    Args:
        objective: Goal objective proposed by the user or criteria model.

    Raises:
        GoalStateSizeError: If `objective` exceeds `GOAL_OBJECTIVE_CHAR_LIMIT`.
    """
    if len(objective) > GOAL_OBJECTIVE_CHAR_LIMIT:
        label = "Goal objective"
        raise GoalStateSizeError(
            label=label,
            actual=len(objective),
            limit=GOAL_OBJECTIVE_CHAR_LIMIT,
        )


def validate_rubric(criteria: str) -> None:
    """Reject criteria that cannot fit their persistent context budget.

    Args:
        criteria: Standalone rubric or goal acceptance criteria.

    Raises:
        GoalStateSizeError: If `criteria` exceeds `RUBRIC_CHAR_LIMIT`.
    """
    if len(criteria) > RUBRIC_CHAR_LIMIT:
        label = "Rubric"
        raise GoalStateSizeError(

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Shorten the objective to at most 8,000 characters (remove at least `excess` characters, reported in the message).
  2. Move long detail into the rubric/criteria fields or an external document and reference it briefly.
  3. Pre-validate with `len(objective) <= GOAL_OBJECTIVE_CHAR_LIMIT` before applying the goal.
  4. Catch `GoalStateSizeError` and surface the truncation guidance to the user instead of failing the flow.

Example fix

// before
apply_goal(objective=long_spec_text)
// after
from deepagents_code.goal_state_limits import GOAL_OBJECTIVE_CHAR_LIMIT, validate_goal_objective
try:
    validate_goal_objective(long_spec_text)
except GoalStateSizeError as e:
    long_spec_text = long_spec_text[: GOAL_OBJECTIVE_CHAR_LIMIT - 200] + "\n... (truncated)"
apply_goal(objective=long_spec_text)
Defensive patterns

Strategy: validation

Validate before calling

from deepagents_code.goal_state_limits import GOAL_OBJECTIVE_CHAR_LIMIT
def objective_fits(text: str) -> bool:
    return len(text) <= GOAL_OBJECTIVE_CHAR_LIMIT

Type guard

def is_valid_objective(text: object) -> bool:
    return isinstance(text, str) and len(text) <= GOAL_OBJECTIVE_CHAR_LIMIT

Try / catch

from deepagents_code.goal_state_limits import GoalStateSizeError
try:
    validate_goal_objective(objective)
except GoalStateSizeError as e:
    surface(f"Objective is {e.actual} chars; trim {e.excess} chars (limit {e.limit}).")

Prevention

When it happens

Trigger: Accepting a goal (`/goal` command, `_propose_goal_rubric`, `validate_goal_application`) whose objective exceeds 8,000 characters; pasting a long document as the objective; reading objective text from a file without size-checking it.

Common situations: Users pasting an entire spec/README as a goal; generated objectives that accumulate across amend cycles; scripted goal application from CI that reads unconstrained config text.

Related errors


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