🐛Debugging Mission·intermediate·⏱️ 25–40m·⭐ 175 XP
M-043Debug the Broken Tool-Calling Loop
Description
Nebula Corp's AI agent is stuck in an infinite loop. The agent is supposed to call a weather tool, parse the response, and return a final answer to the user — but it never stops looping. The tool gets called over and over, and the agent never produces a result. Find the bug in the tool-response parsing logic and fix the loop so the agent terminates correctly.
Symptoms
wrong-outputThe agent loops until MAX_ITERATIONS is reached and returns an error instead of a final answer
wrong-outputThe get_weather tool is called correctly on the first iteration, but the agent never checks the LLM response for a final answer on subsequent iterations
wrong-outputrunAgent('What is the weather in San Francisco?') returns 'Error: Agent exceeded maximum iterations' instead of the weather summary
Expected Behavior (3)
Returns final answer for weather query
The agent should call the tool, parse the result, and return the final answer
Input:runAgent('What is the weather in San Francisco?')
Expected:FINAL_ANSWER: The weather in San Francisco is 72°F and sunny.
Does not exceed iteration limit
A working agent should finish well before hitting MAX_ITERATIONS
Input:runAgent('What is the weather in San Francisco?')
Expected:NOT_CONTAINS:exceeded maximum iterations
Tool is called exactly once
The weather tool should be invoked once, not repeatedly
Input:runAgent('What is the weather in San Francisco?')
Expected:NOT_CONTAINS:exceeded maximum iterations
Related Lessons
Click Run / Check to validate your solution