huggingface/smolagents · error · AgentExecutionError
If you want to return an answer, please do not perform any…
Error message
If you want to return an answer, please do not perform any other tool calls than the final answer tool call!
What it means
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.
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.
Defensive patterns
Strategy: retry
Try / catch
from smolagents.exceptions import AgentExecutionError
try:
result = agent.run(task)
except AgentExecutionError as e:
if 'final answer tool call' in str(e):
result = agent.run(task + '\nReturn the answer using only the final_answer tool.')
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- You returned multiple final answers. Please return only one…
- Argument has type ' ' but should be
- Argument has type ' ' but should be
- Argument is required
- Error while parsing tool call from model output
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/388dfbaf8e97a556.
Report an issue: GitHub.
Appendix: source
Thrown at src/smolagents/agents.py:1341
memory_step.token_usage = chat_message.token_usage
except Exception as e:
raise AgentGenerationError(f"Error while generating output:\n{e}", self.logger) from e
if chat_message.tool_calls is None or len(chat_message.tool_calls) == 0:
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,
)View on GitHub (pinned to 30bb116109)