{"record":{"id":"a23b526c854d73c9","repo":"huggingface/smolagents","slug":"you-returned-multiple-final-answers-please-return","errorCode":null,"errorMessage":"You returned multiple final answers. Please return only one single final answer!","messagePattern":"You returned multiple final answers\\. Please return only one single final answer!","errorType":"exception","errorClass":"AgentToolExecutionError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":1346,"sourceCode":"            try:\n                chat_message = self.model.parse_tool_calls(chat_message)\n            except Exception as e:\n                raise AgentParsingError(f\"Error while parsing tool call from model output: {e}\", self.logger)\n        else:\n            for tool_call in chat_message.tool_calls:\n                tool_call.function.arguments = parse_json_if_needed(tool_call.function.arguments)\n        final_answer, got_final_answer = None, False\n        for output in self.process_tool_calls(chat_message, memory_step):\n            yield output\n            if isinstance(output, ToolOutput):\n                if output.is_final_answer:\n                    if len(chat_message.tool_calls) > 1:\n                        raise AgentExecutionError(\n                            \"If you want to return an answer, please do not perform any other tool calls than the final answer tool call!\",\n                            self.logger,\n                        )\n                    if got_final_answer:\n                        raise AgentToolExecutionError(\n                            \"You returned multiple final answers. Please return only one single final answer!\",\n                            self.logger,\n                        )\n                    final_answer = output.output\n                    got_final_answer = True\n\n                    # Manage state variables\n                    if isinstance(final_answer, str) and final_answer in self.state.keys():\n                        final_answer = self.state[final_answer]\n        yield ActionOutput(\n            output=final_answer,\n            is_final_answer=got_final_answer,\n        )\n\n    def process_tool_calls(\n        self, chat_message: ChatMessage, memory_step: ActionStep\n    ) -> Generator[ToolCall | ToolOutput]:\n        \"\"\"Process tool calls from the model output and update agent memory.","sourceCodeStart":1328,"sourceCodeEnd":1364,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L1328-L1364","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the run — resampling usually yields a single final_answer call.","Tighten the prompt: 'Return exactly one final_answer call and nothing else.'","Use a stronger model or structured outputs that constrain the number of tool calls."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from smolagents.exceptions import AgentToolExecutionError\n\ntry:\n    result = agent.run(task)\nexcept AgentToolExecutionError as e:\n    if 'multiple final answers' in str(e):\n        result = agent.run(task)\n    else:\n        raise","preventionTips":["Prompt: 'Return exactly one final_answer call.'","Avoid configurations that force multiple parallel tool calls per message.","Retry on occurrence; persistent duplication indicates a model/prompt mismatch."],"tags":["smolagents","final-answer","tool-calling","agent-execution"],"backgroundTag":"llm-invalid-tool-call-sequence","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}