0
Phase 6

Function Calling

~2 min read

Concept & How It Works

    Why Does It Exist?

    Function calling was the first widely adopted standard for LLM-tool integration. Most frameworks and providers now use compatible schemas.

    Real-World Analogy

    Function calling is placing an order at a deli counter — you specify the item (function) and modifications (arguments); the kitchen (runtime) prepares it.
    Loading diagram...

    Visual Workflows

    What is Function Calling?

    Loading diagram...

    Example

    Scenario

    GPT-4o receives a weather tool definition and responds with tool_calls: [{function: {name: 'get_weather', arguments: '{"city": "Berlin"}'}}].

    Solution

    In Tool Calling & Function Calling, apply Function Calling to this scenario: GPT-4o receives a weather tool definition and responds with tool_calls: [{function: {name: 'get_weather', arguments: '{"city": "Berlin"}'}}]. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to Function Calling (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where Function Calling happens in the code.

    Function Calling
    1response = client.chat.completions.create(  # call the API2    model="gpt-4o-mini",3    messages=[{"role": "user", "content": "Weather in Berlin?"}],4    tools=[{"type": "function", "function": WEATHER_FN}],  # pass tool schemas so the LLM can call functions5    tool_choice="auto",6)

    Commands to Remember

    Commands to Remember

    • tools=[{"type":"function","function":{"name":"get_weather","parameters":{...}}}] # define schema
    • response.choices[0].message.tool_calls # read model tool selection
    • json.loads(tool_call.function.arguments) # parse arguments

    Common Mistakes

    • Treating Function Calling as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for function calling

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • Function Calling
    • JSON Schema
    • tool_choice
    • Tool Message