Usamos cookies para melhorar a tua experiência e medir o tráfego. Política de cookies

    Scalor
    CONVENCE-NOS →
    Glossário/Agentes & Tools

    Function Calling

    tool useuso de ferramentas

    The ability of an AI model to identify that it needs an external tool to perform a task and generate the necessary command to execute it using structured data.

    What it is

    Function Calling is the functionality that allows large language models (LLMs) to stop being just text generators and become action engines. At its core, it is the bridge between AI reasoning and your company's traditional IT systems.

    While a model like GPT-4 or Claude is incredibly capable of writing and analyzing, it lives in a vacuum: it doesn't know what time it is, doesn't have access to your bank balance, and can't check the stock in your warehouse on its own. Function Calling allows the developer to describe available tools (APIs, databases, calculators) to the AI. When the user asks a question that requires external data, the AI evaluates which tool to use and returns a structured data format (usually JSON) with the parameters needed to execute that function.

    How it works

    Despite the name, the AI does not execute the code directly on its servers. The process is a four-step dialogue:

    1. Presentation: When sending a message to the AI, the system attaches a 'list of tools' described in code. For example: 'I have a function called check_stock that accepts the parameter product_reference'.
    2. Decision: The model analyzes the user's request. If the customer asks 'Do we have blue sneakers size 42?', the AI realizes it doesn't know the answer but sees that it has a stock tool available.
    3. Call Request: The AI responds, not with text for the customer, but with a technical request: 'Please execute check_stock for the item blue-snk-42'.
    4. Execution and Response: Your computer system executes the command in the database, gets the result ('Yes, 5 units'), and sends it back to the AI. Only then does the AI write to the user: 'Yes, we have 5 pairs in stock. Would you like to order?'.

    This cycle transforms the AI into an agent that interacts with business reality in real-time.

    When to use it

    You should implement Function Calling whenever you need the AI to interact with dynamic data or third-party systems. For an SME, this is critical to avoid hallucinations. If you ask the AI 'What was yesterday's revenue?', without Function Calling, it might make up a number. With Function Calling, it queries the billing software.

    Ideal use cases include:

    • Real-time data querying: Prices, weather, calendar availability, or inventory levels.
    • Actions in external systems: Creating a support ticket in Zendesk, sending a confirmation email, or scheduling a meeting in Google Calendar.
    • Structured data extraction: Transforming a messy customer email into an order form ready to be entered into the ERP.
    • Complex calculations: Delegating financial math to a precise calculator rather than relying on the model's probabilistic arithmetic.

    Common errors

    The most frequent error is giving generic names or vague descriptions to functions. The AI decides which tool to use based on the description you provide. If the description is ambiguous, it will choose the wrong tool or try to guess the parameters.

    Another critical error is the lack of validation. You should never allow the AI to execute sensitive functions (such as 'Delete User' or 'Make Bank Transfer') without a human verification layer or rigid business rules. The AI generates the command, but your system must validate if that user has permission to execute it.

    Finally, many developers forget to handle network errors. If your provider's API takes too long to respond, the AI will lose context or enter a loop. It is necessary to provide error responses so the AI can inform the user politely.

    Practical example for an SME

    Imagine a Portuguese wine distribution company. They have a chatbot for their professional clients (restaurants and wine shops).

    Without Function Calling, the bot only explains wine varieties. With Function Calling, the bot has access to three tools: check_wholesale_price(client_id, product_id), check_delivery_date(postal_code), and register_order().

    When a restaurant owner in Porto asks: 'How much for a case of Pêra-Manca and when will it arrive?', the flow is this:

    • The AI detects that it needs to check the specific price for that customer and the logistics times for Porto.
    • It calls the functions in milliseconds.
    • It receives the data: €450 + VAT and delivery next Tuesday.
    • It responds: 'For your wholesale profile, the case is €450 + VAT. If you order now, we can deliver to Porto this Tuesday.'.

    Here, the value for the SME is the automation of a sale that previously would have required a phone call or email exchange, while maintaining total data accuracy.

    Frequently Asked Questions

    Q: Is Function Calling safe? R: Yes, as long as the developer controls what the function does. The AI only suggests the call; it is your code that executes it. Never give direct and unrestricted access to the database.

    Q: Do I need to know how to program to use this? R: To set up the technical infrastructure, yes. However, 'no-code' tools for AI agents are starting to integrate these capabilities visually.

    Q: What is the difference between Function Calling and a Plugin? R: Function Calling is the underlying technical mechanism. A Plugin (like those in ChatGPT) is a specific interface implementation that uses this mechanism to connect the chatbot to external services.

    Q: Does it consume many tokens? R: Yes, function definitions take up space in the Context Window. If you have dozens of complex functions, the cost per message will be higher.

    Exemplos práticos

    • 01A real estate chatbot that queries the database to list 2-bedroom apartments in Braga.
    • 02A virtual assistant that schedules meetings by checking real-time availability in the team's Outlook.
    • 03A support tool that automatically cancels subscriptions after validating the customer's request in Stripe.
    • 04A purchasing analysis system that converts PDF invoices into structured entries in Primavera software.

    Termos relacionados

    Agente de IA
    Um sistema autónomo capaz de planear tarefas, utilizar ferramentas externas e tomar decisões para atingir um objetivo específico sem supervisão humana constante.
    Context Window
    Capacidade máxima de informação que um modelo de IA consegue processar de uma só vez antes de começar a esquecer os detalhes iniciais.
    LLM
    Modelos de inteligência artificial treinados em volumes massivos de texto para compreender, gerar e processar linguagem humana com alta fluidez.
    RAG
    Técnica que permite a um modelo de IA consultar documentos externos atualizados e privados antes de gerar uma resposta, garantindo maior precisão e reduzindo alucinações.
    Structured Output
    Garante que o modelo de IA responde num formato técnico rígido e previsível, como JSON, em vez de texto livre narrativo.

    Quer usar Function Calling na sua empresa?

    30 minutos, gratuito, sem compromisso. Dizemos onde encaixa.

    Diagnóstico IA gratuito