AI & LLMs
How an LLM decides to call your code
A language model can write you a beautiful function to fetch the weather. What it can't do — on its own — is run it. So how do assistants end up checking your calendar, searching a codebase, or placing an order? They use tools. And the model's only job is to decide which one.
The model can't actually run anything
A language model produces one thing: text. A "tool" is just a function you describe to it — a name, a sentence about what it does, and the inputs it expects. The model can't execute it. What it can do is emit a structured request that says "call get_weather with city = Pune." Your application sees that request, runs the real function, and hands the answer back.
The loop
Step by step, for "what's the weather in Pune?":
- You send the question plus a list of the tools available.
- The model replies with either a normal answer or a tool call — structured data naming the function and its arguments.
- Your application runs the real function and gets "31°C, humid."
- You feed that result back into the model.
- The model turns it into a sentence — or decides it needs another tool and goes around again.
The model decides which tool and what arguments. Your code does the doing. The model never touches your systems directly — it only ever asks.
Why this matters
- It turns a text predictor into something that can act — search, calculate, book, query a database.
- You control the menu. The model can only reach the tools you expose — which is exactly how MCP servers package those tools up in a standard way.
- Never trust the arguments blindly. The model can pick the wrong tool or bad inputs. Validate before you run anything that matters.
That's the whole trick behind "AI agents": a plain request-and-reply loop, where one side happens to be very good at choosing the next move.