AI Model Wiki

    Skip to main content
    Back to Glossary

    Function Calling

    Function calling (also called tool use) is a capability that lets a language model signal, in a structured way, that it wants to invoke an external function — passing typed arguments — rather than generating a plain-text answer. The model does not execute the function itself; it emits a structured request (typically as JSON), the host application calls the real function, and the result is fed back into the conversation so the model can compose a final response. This pattern turns a static text predictor into an agent that can read databases, call APIs, run calculations, or trigger side-effects.

    Think of it like a surgeon who dictates instructions to a scrub nurse rather than reaching across the sterile field themselves. The surgeon (model) says precisely what they need — "hand me a 10-blade scalpel" — and the nurse (runtime) fetches and returns it. The surgeon never touches the instrument tray directly.

    A typical OpenAI-style function-calling exchange looks like this:

    // Model output (structured request)
    { "name": "get_weather", "arguments": { "city": "Bangkok", "units": "celsius" } }
    
    // Application calls the real function, returns:
    { "temperature": 34, "condition": "partly cloudy" }
    
    // Model then generates: "It is currently 34 °C and partly cloudy in Bangkok."
    

    Function calling is foundational to RAG (retrieving documents on demand), Prompt Engineering (crafting tool schemas the model interprets correctly), and Inference pipelines that chain multiple tool calls. It also underpins LLM-based agent frameworks like LangChain and AutoGen, and connects to Context Window management since tool results are inserted back into the prompt.

    You will encounter function calling in any production AI application that needs live data, user-specific records, or side-effects — chatbots that book appointments, coding assistants that run tests, or data analysts that query SQL databases on behalf of a user.

    Related Courses

    AI Terminology
    Glossary