huggingface/smolagents · error · ValueError

Cannot specify both 'messages' and 'steps' parameters. Use '

Error message

Cannot specify both 'messages' and 'steps' parameters. Use 'steps' instead.

What it means

RunResult (and similar result/output objects) accept a deprecated 'messages' parameter that was renamed to 'steps'. Passing both at once is ambiguous, so the constructor raises a ValueError and asks you to use 'steps' only.

Source

Thrown at src/smolagents/agents.py:221

        token_usage (TokenUsage | None): Count of tokens used during the run.
        timing (Timing): Timing details of the agent run: start time, end time, duration.
        messages (list[dict]): The agent's memory, as a list of messages.
            <Deprecated version="1.22.0">
            Parameter 'messages' is deprecated and will be removed in version 1.25. Please use 'steps' instead.
            </Deprecated>
    """

    output: Any | None
    state: Literal["success", "max_steps_error"]
    steps: list[dict]
    token_usage: TokenUsage | None
    timing: Timing

    def __init__(self, output=None, state=None, steps=None, token_usage=None, timing=None, messages=None):
        # Handle deprecated 'messages' parameter
        if messages is not None:
            if steps is not None:
                raise ValueError("Cannot specify both 'messages' and 'steps' parameters. Use 'steps' instead.")
            warnings.warn(
                "Parameter 'messages' is deprecated and will be removed in version 1.25. Please use 'steps' instead.",
                FutureWarning,
                stacklevel=2,
            )
            steps = messages

        # Initialize with dataclass fields
        self.output = output
        self.state = state
        self.steps = steps
        self.token_usage = token_usage
        self.timing = timing

    @property
    def messages(self):
        """Backward compatibility property that returns steps."""
        warnings.warn(

View on GitHub (pinned to 30bb116109)

Solutions

  1. Remove the messages=... argument and pass only steps=...
  2. If building kwargs dynamically, ensure the key is 'steps' and that 'messages' is not also set
  3. Silence the FutureWarning path entirely by never using 'messages' once migrated

Example fix

# before
result = RunOutput(output=ans, messages=steps_list, steps=steps_list)

# after
result = RunOutput(output=ans, steps=steps_list)
Defensive patterns

Strategy: validation

Validate before calling

def build_result(output, steps, **legacy):
    if legacy.get("messages") and steps:
        raise ValueError("pass only 'steps'")
    steps = steps or legacy.get("messages")
    return RunOutput(output=output, steps=steps)

Try / catch

try:
    result = RunOutput(output=o, steps=s)
except ValueError as e:
    if 'messages' in str(e):
        # drop the messages= kwarg and rebuild with steps only
        ...

Prevention

When it happens

Trigger: Constructing a result object with both keyword arguments, e.g. RunResult(messages=old_messages, steps=new_steps), typically while migrating pre-1.25 code that passed 'messages' and partially updated to the new API.

Common situations: Upgrading smolagents to >=1.25 where 'messages' was deprecated (removal slated for 1.25); copy-pasting new example code into old code that still passes messages=...; library wrappers that forward **kwargs and end up setting both.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/87c9294b0012d74d. Report an issue: GitHub.