Tool Use and Function Calling: How AI Agents Access Real Business Systems
Understand how AI agents interact with real business software through tool use and function calling: JSON schemas, API round-trips, access control, and a Pamulang cafe stock scenario.
Key takeaways
- Function calling is a mechanism where a large language model outputs valid JSON data structures to request external function execution rather than running arbitrary code unsupervised.
- The function calling round-trip involves four stages: sending tool schema definitions to the model, generating JSON arguments by the model, executing safe code on the backend server, and returning the system payload to the model.
- Tool integration security must enforce least-privilege access, server-side schema validation, immutable audit logs, and human confirmation for actions that alter critical records.
Have you ever wondered how a WhatsApp booking assistant knows that a second-floor boarding room is already occupied and immediately offers the next available unit? Naturally, an artificial language model does not have physical eyes to inspect a receptionist ledger.
The answer lies in a core engineering mechanism known as tool use or function calling. As introduced in our pillar guide on how agentic AI works for beginners, this capability bridges flexible natural language reasoning with the strict data types required by company databases.
For business owners and software developers alike, understanding function calling is the key to turning a passive chat responder into an operational system that completes real transactions. Let us examine its architecture step by step.
Why language models need hands and eyes: limits of pure text
Large language models are technically isolated from the live world because they are trained on historical datasets and cannot observe real-time state or modify external software records without dedicated programming interfaces.
Three fundamental limitations appear when you force a language model to operate without tool integration. First is knowledge cutoff blindness. The model does not know whether today is a public holiday, what the current exchange rate is this afternoon, or whether a doctor at your clinic called in sick ten minutes ago.
Second is unreliable arithmetic calculation. Language models are trained to predict word patterns rather than compute exact math. When asked to total ten order items with tiered coupon discounts and an 11% tax rate, a raw model can make subtle rounding errors that hurt margins.
Third is the absence of operational agency. A text-only model can write the sentence "Your order #1045 has been canceled and refunded," while zero changes actually occurred in your point-of-sale system or bank ledger. Without a tool call, that confirmation is pure hallucination.
What tool use and function calling are: simple technical definition
Function calling is a standard protocol in language model APIs where developers declare a catalog of available functions along with parameter rules, allowing the model to decide when a function is needed and output structured JSON arguments.
It is critical to emphasize that the language model does not execute the function itself. It never opens a direct network connection to your database server. Instead, the model pauses normal conversational output and emits a structured JSON block telling your server: "Please execute this function name with these exact parameter values."
Your application server retains full control. It inspects the JSON request from the model, verifies user permissions, executes local backend code (such as a parameterized SELECT query against a relational database), and feeds the resulting data payload back to the model.
Anatomy of a function call: JSON schema, parameters, system response
The anatomy of a function call consists of three primary parts: a JSON Schema declaration describing the function purpose and parameter types, the argument payload generated by the model, and the structured response returned by the external system.
Let us inspect these components using an inventory lookup function for a coffee shop application:
Four anatomical components of a function call declaration
- Function Name: A unique programmatic identifier such as
check_ingredient_stock. Names must be concise and follow strict naming conventions. - Semantic Description: Plain-language instructions read by the model to know when calling this function is appropriate, such as "Use this function when a barista or manager asks for remaining stock of milk, syrup, or coffee beans."
- Parameters Object: A standard JSON Schema definition specifying variable names (for example
ingredient_name), data types (string or integer), required flags, and allowed enum values. - Tool Output Payload: A concise JSON response from the backend server confirming live state, such as
{"status": "ok", "remaining_units": 4, "unit": "liters"}.
| User Chat Message | Selected Function Name | Generated JSON Arguments | Actual Backend Action |
|---|---|---|---|
| "Check how much caramel syrup is left at the main bar" | check_ingredient_stock | {"ingredient": "caramel_syrup", "location": "main_bar"} | Queries branch inventory database table |
| "Please create a draft order for 5 palm sugar iced coffees" | create_order_draft | {"item_id": "palm_sugar_coffee", "qty": 5} | Inserts a draft order into the POS system |
| "What was our total cafe revenue last night?" | get_sales_summary | {"date": "2026-10-28", "shift": "evening"} | Aggregates settled transaction totals from server |
| "Send the PDF summary to the manager WhatsApp" | send_report_document | {"format": "pdf", "recipient": "+62812xxxx"} | Generates PDF report and triggers WhatsApp API |
Precision in writing parameter descriptions directly determines accuracy. Ambiguous descriptions cause the model to pick the wrong tool or pass improperly formatted dates.
The round-trip flow: from user message to executed result
A function calling round-trip operates in a closed orchestration loop involving the user, your intermediate application server, the large language model API, and your operational business database.
Here is the chronological sequence that completes within a few hundred milliseconds when a message arrives:
Chronological sequence of a function calling orchestration loop
- The user sends a text message through an interface (such as a WhatsApp webhook or in-house staff app).
- Your application server bundles the message with the list of declared tool schemas and forwards the request to the language model API.
- The language model analyzes the text, concludes a tool is required, and returns a
tool_callsresponse containing the function name and JSON arguments. - Your application server intercepts that response, validates the arguments, and executes the backend function code (such as a SQL query to a relational database).
- Your server receives the database rows, wraps them inside a
toolrole message, and sends them back to the language model. - The language model reads the verified data and writes a natural, helpful final reply delivered to the user phone.
Example scenario: cafe inventory check in Pamulang
As an example scenario, imagine an independent coffee shop in Pamulang, South Tangerang using function calling to let baristas and store managers check ingredient stock directly through their operational WhatsApp group.
Suppose during busy afternoon shifts, baristas rarely have time to open a back-office laptop just to check whether UHT milk cartons in the secondary storage room are sufficient for the weekend. Instead, they send a quick text to the cafe assistant number.
When a barista messages: "Admin, how many crates of fresh milk are left in the storage room?", the system can execute a structured sequence:
Example inventory execution steps at a Pamulang coffee shop
- The model maps the phrase "fresh milk" to item code
SKU-MILK-FRESH-1Lvia thecheck_inventoryfunction parameter. - The backend server queries the inventory database and retrieves the result: 4 crates remaining (48 liters), with the nearest expiration date in 5 days.
- The model reads the payload and replies on WhatsApp: "Fresh milk stock in secondary storage is 4 crates (48 liters). Note: 1 crate expires in 5 days."
- If the barista follows up with: "Please draft a purchase order for 5 crates to our usual supplier," the model calls
create_po_draft, which sends an approval button to the cafe manager.
This implementation aligns with the architecture documented in our cafe operations dashboard case study and our custom software development work for businesses around Pamulang.
Tool security: authority limits, human confirmation, audit logs
Connecting an AI model to live production databases requires layered security governance to prevent malicious prompt injection, unauthorized record deletion, and unapproved financial transactions.
The first mandatory principle is Read-Write Separation. Tools that only read non-sensitive information (such as checking table availability, reading doctor schedules, or looking up menu prices) can run automatically. However, tools that mutate permanent state or move money (such as canceling bookings, changing catalog prices, or issuing refunds) must require explicit human-in-the-loop confirmation.
The second principle is maintaining an immutable audit trail. Every time a function is invoked by the language model, record a log entry containing the session ID, timestamp, tool name, input arguments, and server response. This log provides full accountability during stock or billing audits.
The third principle is strict server-side parameter validation. Never trust JSON arguments generated by a language model blindly. Validate every field using strict JSON Schema validators on the server to guarantee phone numbers match valid formats and order quantities are never negative numbers.
For a deeper look at open cross-platform tool standards, read our guide on the Model Context Protocol (MCP) for business integration and our security analysis on prompt injection mitigation.
Official reference sources
The following engineering documentation and security standards provide official specifications for implementing tool use and function calling; check the official documentation for current figures and terms regarding payload limits and schema rules:
- OpenAI Official Function Calling Guide explains tool declaration payloads and structured JSON parameter handling; check the official documentation for current figures and terms.
- Google Gemini API Structured Outputs & Function Calling details function declaration schemas and execution modes in Gemini models; check the official documentation for current figures and terms.
- Official JSON Schema Specification defines the validation vocabulary for object structures and programming data types; check the official documentation for current figures and terms.
- OWASP Application Security Verification Standard (ASVS) provides verification benchmarks for input validation and backend access control; check the official documentation for current figures and terms.
- Indonesia Personal Data Protection Law No. 27 of 2022 at JDIH BPK RI governs confidentiality requirements when logging user interaction payloads; check the official documentation for current figures and terms.
Conclusion
Function calling and tool use form the engineering bridge that turns a conversational language model into an operational assistant capable of supporting real daily business tasks.
Reliable execution depends on precise JSON schema declarations, strict backend parameter validation, human confirmation for write actions, and transparent audit logging.