{"record":{"id":"388dfbaf8e97a556","repo":"huggingface/smolagents","slug":"if-you-want-to-return-an-answer-please-do-not-per","errorCode":null,"errorMessage":"If you want to return an answer, please do not perform any other tool calls than the final answer tool call!","messagePattern":"If you want to return an answer, please do not perform any other tool calls than the final answer tool call!","errorType":"exception","errorClass":"AgentExecutionError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":1341,"sourceCode":"            memory_step.token_usage = chat_message.token_usage\n        except Exception as e:\n            raise AgentGenerationError(f\"Error while generating output:\\n{e}\", self.logger) from e\n\n        if chat_message.tool_calls is None or len(chat_message.tool_calls) == 0:\n            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        )","sourceCodeStart":1323,"sourceCodeEnd":1359,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L1323-L1359","documentation":"In ToolCallingAgent._step_stream, once a tool output flagged is_final_answer appears, the model must have issued exactly one tool call — the final_answer call. If the message contains additional tool calls alongside final_answer, the agent raises AgentExecutionError because mixing final answers with other calls makes the run's result ambiguous.","triggerScenarios":"The model returns multiple tool_calls in one message where at least one is final_answer (e.g. final_answer(...) plus a search(...) call in the same response), during agent.run with a ToolCallingAgent.","commonSituations":"Smaller models that 'hedge' by calling a tool and answering at once; prompts encouraging parallel tool use; structured-output configs that force multiple tool call slots.","solutions":["Retry the run or step — models usually emit a single final_answer call on resampling.","Use a stronger/tool-calling-native model that respects the single-final-answer contract.","Clarify the system prompt/prompt template to forbid combining final_answer with other tool calls."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from smolagents.exceptions import AgentExecutionError\n\ntry:\n    result = agent.run(task)\nexcept AgentExecutionError as e:\n    if 'final answer tool call' in str(e):\n        result = agent.run(task + '\\nReturn the answer using only the final_answer tool.')\n    else:\n        raise","preventionTips":["Instruct the model to call final_answer alone, never alongside other tools.","Use models with strong instruction following for tool-calling agents.","Treat single occurrences as resampling noise; only fix prompts if recurrent."],"tags":["smolagents","tool-calling","final-answer","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"}