Agent can exit on tool call when max_agent_steps is reached, not guaranteeing a final text answer
Is your feature request related to a problem? Please describe.
When an Agent reaches max_agent_steps, it stops immediately - even if the last message is from a tool invocation. This results in no final text response from the LLM, which could be problematic if you expect that the agent answers with natural language
Describe the solution you'd like
When max_agent_steps is reached, there could be a setting that the agent:
- Detect if the last message is from a tool call
- Make ONE final call to the chat generator (without tools)
- Return a proper text response
Describe alternatives you've considered Locally I built a AlwaysAnswerAgent (AAA). My max_agent_steps are low to prevent minute long runs. I want that my agent tells if he has problems with the provided input instead digging for minutes to the wrong result. However when I set max_agent_steps e.g to 10, I receive a tool call output, that I cant display to the user. So I built my AAA that when the threshold is hit, summarizes what he tried so far. So the main goal is to end always with a ChatGenerator/Generator that dont call again tools.
Implemented an optional extra LLM call via a new final_answer_on_max_steps parameter.
- Preserves full reasoning:
max_agent_steps = 3still yields 3 full iterations, not 2 + forced conclusion - Matches issue intent: explicitly requests an additional call
- Better edge case behavior:
max_agent_steps = 1⇒ one step + answer, not zero work + answer - Clear semantics: “extra call only when needed” avoids redefining what a “step” means
- Optional: users can disable for strict cost control
- Robust: wrapped in
try/exceptto gracefully fall back to the last tool result if needed
:param final_answer_on_max_steps:
If True, the agent performs one additional LLM call when `max_agent_steps`
is reached and the last message is a tool result. This guarantees a final
natural-language answer instead of raw tool output. The extra call does not
count toward `max_agent_steps`. Default: True.
Default = True because:
- Better UX for all users (no confusing tool results)
- Issue author explicitly wanted this behavior
- Current behavior (returning raw tool output) is objectively worse
- Cost increase is minimal (at most +1 call, only when limit is hit)
- Can be disabled for strict cost control or exact parity with current behavior