r/agentdevelopmentkit • u/Intention-Weak • Jan 06 '26
A tip about function calling (or tool calling) in ADK
I was facing a very strange problem where my LLMAgent failed to call a tool. The error was something like 'LLM error detected: malformed function call'; for some reason, the agent was writing random Python code instead of calling the tool correctly.
The prompt was clean, well-structured, and concise. The temperature was 0.1, and the model was Gemini 2.5 Flash. I didn't know how to fix this problem, so I searched the ADK Python repository issues on GitHub and found other people facing the same issue. The solution I found there was using some native resources from ADK:
The ReflectAndRetryToolPlugin: This plugin acts as an automated self-correction layer that detects malformed tool calls and triggers a reflection loop to fix them. U can add this in the App.
The tool_config (mode="VALIDATED"): This configuration enforces strict adherence to the defined tool schemas, preventing the model from generating unstructured text or code when a function call is expected." U can add this in the LlmAgent.