AI & MLLLMOpenAIPython

Moving from Chat Responses to Function Calling

If I ask a chat model for the weather in Toronto, what exactly does my application get back when the model asks to look it up? I used a function-calling notebook to see where choosing an operation ends and running it begins.

The cookbook example defines a weather function for the Chat Completions API. That let me inspect the operation name and arguments the model was being asked to supply.

Describing the available operation

A tool definition describes an operation and its arguments in a structured form. The model can then return a request that the application interprets.

The application still owns execution. It needs to validate arguments, check whether the operation is appropriate, run the relevant code, and decide how to handle the result.

This separates a proposed action from an executed one. That distinction matters for calendar writes, external requests, database changes, and any operation with consequences beyond the chat window.

The surrounding control loop

A useful loop includes the user's request, the model's tool request, the application's result, and the final response. Errors and missing arguments need to fit into that loop too.

The notebook tries a Toronto weather request under different tool settings. With tools available, the model can choose an operation. Another cell explicitly requires get_n_day_weather_forecast, and a third sets tool_choice to none. A separate database example reads the proposed function name and parses the query argument from JSON, which is the point where application code gets to decide what to do with the request.

The schema makes the boundary visible; it does not replace validation or permission checks.

A precursor to later application patterns

I used the same division of responsibilities in a wearable-data assistant. The model asks for an analytics operation, the application calculates the result, and the answer cites that evidence.

Related project