Function Calling
AI EngineerFunction calling is the mechanism that connects a model’s intent to your code’s execution. You send the model a list of available functions along with the user’s message; instead of replying with prose, the model can respond with a structured request — a function name plus JSON arguments — that your application executes. You then feed the result back, and the model continues, either calling another function or producing a final answer. The model decides what to call; you control whether and how it actually runs.
This matters because it solves the two hardest problems of wiring LLMs into real software: getting structured, parseable output instead of free text, and giving the model access to live data and real actions. Function calling is the foundation under agents, RAG pipelines that fetch on demand, structured data extraction, and every “AI feature” that touches your database or a third-party API. Understand this loop and most agent frameworks stop looking like magic.
In practice, you’ll define functions with JSON Schema parameters, pass them via a tools parameter in the SDK, and write a loop: check the response for tool calls, dispatch each one to a real function (get_weather(city="Tokyo")), append the result to the message history, and call the model again until it returns plain text. You’ll also handle multiple calls in one turn, invalid arguments, and errors. OpenAI, Google, and Anthropic each implement this with different API shapes — covered in the next topics — but the loop is identical.
Resources
0/6 completed- What are Tools? - Hugging FaceOfficial docs