Tool Calling and AI Agents: How Function Calling Really Works
How LLM tool calling works, how to write tool descriptions models use correctly, how agent loops run and stop, and the failures to plan for in agents.
Tools & agents
Tool calling lets a model request an action, such as searching, reading a file or calling an API, by returning a structured call that your code executes. An AI agent repeats that loop until the task is done. Prompting here is mostly about clear tool names and descriptions, precise parameters, and rules for when to act, when to ask and when to stop.
Your app parses the model’s JSON, but sometimes the reply starts with “Sure! Here is the JSON:”. What is the most robust fix?
An agent keeps calling the same search tool in a loop. Which change helps most?
B. Describe when the tool is useful, and add a stop rule such as a max number of searches before answering Agents decide from tool descriptions and stop conditions. Without a clear purpose and a limit, repeating the call looks as reasonable to the model as stopping.
Tool calling is when the model returns a structured request to run a function you defined, with arguments. Your code runs it and sends the result back, and the model continues with that result.
A chatbot replies to messages. An agent can call tools in a loop, deciding its next step from each result, until it reaches a goal or a stop condition.
How LLM tool calling works, how to write tool descriptions models use correctly, how agent loops run and stop, and the failures to plan for in agents.
Prompt injection tricks an AI into following attacker instructions hidden in input or documents. Learn direct vs indirect attacks and the mitigations that work.
Getting valid JSON from an LLM takes more than asking nicely. Use schemas, structured output modes, validation and retries, and avoid the usual failure modes.
Short quizzes on real prompting decisions, with an explanation for every answer. Free to start on iPhone and Android.