lubu labs

Function Calling

Simon Budziak
Simon BudziakCTO
Function Calling (also known as "Tool Use" or "Tool Calling") is a critical capability that enables large language models to interact with external systems, APIs, and databases by generating structured requests to invoke predefined functions. This transforms LLMs from pure text generators into action-oriented agents that can read sensors, query databases, send emails, or control software.

Here's how function calling works in practice:
  • 1. Function Definition: The developer provides the model with a schema describing available functions (name, description, parameters). For example: get_weather(location: string, units: string).
  • 2. User Query: The user asks a question that requires external data: "What's the weather in Warsaw?"
  • 3. Function Selection: The model recognizes it needs external information and generates a structured function call: get_weather(location="Warsaw", units="celsius").
  • 4. External Execution: Your application intercepts this call, executes the actual API request, and returns the result to the model.
  • 5. Final Response: The model incorporates the function result into a natural language answer: "It's currently 15°C and partly cloudy in Warsaw."
Function calling is foundational for building AI agents because it bridges the gap between language understanding and real-world actions. Modern applications use it to:
  • Access Real-Time Data: Pull stock prices, flight information, or inventory levels.
  • Modify Systems: Create calendar events, update CRM records, or trigger workflows.
  • Perform Calculations: Offload complex math, simulations, or specialized computations to deterministic code.
  • Multi-Step Reasoning: Chain multiple function calls together to solve complex tasks autonomously.
All major LLM providers (OpenAI, Anthropic, Google) support function calling with structured schemas (typically JSON-based). The quality of function descriptions and parameter schemas directly impacts how reliably the model invokes the right tools at the right time, making thoughtful API design crucial for agentic applications.

Ready to Build with AI?

Lubu Labs specializes in building advanced AI solutions for businesses. Let's discuss how we can help you leverage AI technology to drive growth and efficiency.