ML//agent//function calling

Function calling is a structured model output containing a tool identifier and arguments, commonly represented as JSON. The application validates the call, executes ordinary code, returns an observation, and may invoke the model again.


Function calling is a structured model output containing a tool identifier and arguments, commonly represented as JSON. The application validates the call, executes ordinary code, returns an observation, and may invoke the model again.

It is a protocol for requesting execution, not execution itself. The model has no direct function pointer into the host process.

Schemas constrain syntax and communicate intent (with names and descriptions they form the tool interface, which decides which calls the model can represent and select reliably), but valid JSON can still request a semantically wrong or unsafe operation. A well-formed call still crosses into implementation code, part of the attack surface, which must check its authority and treat its arguments as untrusted.

The returned observation becomes new context. Its selection, formatting, truncation, and error detail influence the model's next decision.

A call can be as small as {"tool": "get_weather", "arguments": {"city": "Madrid"}}; writing it executes nothing until the application parses it and decides to run it. Where the tools come from is a separate matter: they can be coded into the application or discovered at run time from an MCP server, which publishes each tool's name, description and argument schema in the same shape.

Function calling supplies the plumbing for tool use. The harness supplies the control loop and enforcement around it.