huggingface/smolagents · error · AgentToolExecutionError

You returned multiple final answers. Please return only one

Error message

You returned multiple final answers. Please return only one single final answer!

What it means

ToolCallingAgent._step_stream tracks whether a final answer was already produced in the current step via got_final_answer. If a second ToolOutput with is_final_answer appears (e.g. the model called final_answer twice in one message), AgentToolExecutionError is raised because the run would have conflicting results.

Source

Thrown at src/smolagents/agents.py:1346

            try:
                chat_message = self.model.parse_tool_calls(chat_message)
            except Exception as e:
                raise AgentParsingError(f"Error while parsing tool call from model output: {e}", self.logger)
        else:
            for tool_call in chat_message.tool_calls:
                tool_call.function.arguments = parse_json_if_needed(tool_call.function.arguments)
        final_answer, got_final_answer = None, False
        for output in self.process_tool_calls(chat_message, memory_step):
            yield output
            if isinstance(output, ToolOutput):
                if output.is_final_answer:
                    if len(chat_message.tool_calls) > 1:
                        raise AgentExecutionError(
                            "If you want to return an answer, please do not perform any other tool calls than the final answer tool call!",
                            self.logger,
                        )
                    if got_final_answer:
                        raise AgentToolExecutionError(
                            "You returned multiple final answers. Please return only one single final answer!",
                            self.logger,
                        )
                    final_answer = output.output
                    got_final_answer = True

                    # Manage state variables
                    if isinstance(final_answer, str) and final_answer in self.state.keys():
                        final_answer = self.state[final_answer]
        yield ActionOutput(
            output=final_answer,
            is_final_answer=got_final_answer,
        )

    def process_tool_calls(
        self, chat_message: ChatMessage, memory_step: ActionStep
    ) -> Generator[ToolCall | ToolOutput]:
        """Process tool calls from the model output and update agent memory.

View on GitHub (pinned to 30bb116109)

Solutions

  1. Retry the run — resampling usually yields a single final_answer call.
  2. Tighten the prompt: 'Return exactly one final_answer call and nothing else.'
  3. Use a stronger model or structured outputs that constrain the number of tool calls.
Defensive patterns

Strategy: retry

Try / catch

from smolagents.exceptions import AgentToolExecutionError

try:
    result = agent.run(task)
except AgentToolExecutionError as e:
    if 'multiple final answers' in str(e):
        result = agent.run(task)
    else:
        raise

Prevention

When it happens

Trigger: A single model message containing two or more final_answer tool calls (or multiple managed agents each returning final answers) processed within one step of agent.run.

Common situations: Models that duplicate the final_answer call; multi-tool-call responses where every sub-agent resolves to a final answer; prompt templates not enforcing a single answer.

Related errors


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