How Does an LLM Call a Function When It Just Generates Text?
The magic trick is mostly JSON, schemas, a runtime loop, and a developer who remembers to validate inputs.
An LLM does not reach into your server and press a function button. It generates text or structured output that says, roughly, "call this tool with these arguments." Your runtime reads that request, validates it, runs real code, and sends the result back to the model.
That is the trick.
The loop
- You give the model a list of tools with names, descriptions, and argument schemas.
- The model decides a tool is needed.
- The model outputs a tool call in the expected structured format.
- Your application validates the arguments.
- Your application runs the real function.
- The tool result is added back to the conversation.
- The model uses that result to answer or choose another action.
Function calling vs agents
A single model call can use a tool. That does not automatically make it an agent.
An agent usually has a loop: inspect, choose action, run tool, observe result, continue. Function calling is the mechanism. The agent loop is the workflow around it.
The part developers own
The model suggests. Your code executes. That means your code needs schemas, permissions, rate limits, input validation, error handling, and audit logs for anything that matters.