Tutorial: Building AI Agents with Tools & Function Calling
Learn step by step how to build AI agents with tools and function calling in 2026. A complete guide from basic concepts to real-world implementation.

The global AI agent market is projected to surpass US$ 51 billion in 2026, growing more than 40% compared to the previous year, according to various recent industry research reports. In Indonesia itself, AI agent adoption in banking, e-commerce, and customer service sectors has surged — more than 60% of mid-to-large enterprises are now piloting at least one AI agent in their operational workflows. These figures are not just a passing trend: AI agents have shifted from being merely reactive chatbots to autonomous systems capable of making decisions, invoking external functions, and completing complex tasks without human intervention at every step. If you are a developer, product manager, or startup founder who wants to remain relevant in the era of intelligent automation, understanding how to build AI agents — especially with tools and function calling — is no longer an optional skill, but a core competency that must be mastered right now. Function calling is the technical bridge that transforms large language models from text-generating machines into executors of real actions in the digital world.
What Are AI Agents with Tools and Function Calling? Systems That Can "Act", Not Just "Speak"
Imagine a human personal assistant. When you say, "Please book a flight ticket to Surabaya for tomorrow morning, find the cheapest one, and put it in my calendar," the assistant does not just reply, "Okay, I will look for it." They open the flight booking application, compare prices, choose the cheapest option, then open the calendar app and create an event. An AI agent with function calling works exactly like that: the large language model (LLM) acts as the "brain" that understands instructions, while tools are the "hands" that execute real actions — calling APIs, sending emails, updating databases, or running code.
Technically, function calling is a mechanism where the LLM receives function definitions (name, parameters, description) and then produces structured output — usually in JSON format — containing the name of the function to be called along with its arguments. Your application then executes that function, returns the result to the model, and the model continues the conversation or completes the task. This cycle — understand, select tool, execute, return result, continue — is the heart of every modern AI agent.
There are several types of tools commonly used in AI agent development:
API Caller Tools — tools that call external REST API or GraphQL endpoints, for example to fetch weather data, stock prices, or shipping status.
Database Query Tools — tools that run SQL queries or database operations to read and write structured data.
Code Execution Tools — tools that run code snippets safely in a sandbox, useful for complex calculations or data transformation.
Browser Automation Tools — tools that control a browser to retrieve information from the web, fill out forms, or perform scraping.
Internal Business Logic Tools — business-specific functions such as "createinvoice", "checkproductstock", or "schedulemeeting" that connect to a company's internal systems.
Multi-Agent Communication Tools — tools that allow one agent to communicate with another agent to delegate sub-tasks.
Why Function Calling Matters: From Passive LLM to Autonomous System
1. Turning Conversations into Real Transactions
Without function calling, an LLM can only generate text. With function calling, the text produced by the model becomes a trigger for concrete actions: fetching real-time data, sending commands to external systems, or updating status in a database. This is the fundamental difference between a "chatbot that answers questions" and an "AI agent that gets work done". In 2026, users are no longer impressed by lengthy answers — they want systems that actually do something: order, pay, schedule, analyze, and report. Function calling is the key to meeting those expectations.
Case Study – Logistics Company: A large logistics company in Southeast Asia implemented an AI agent with function calling to handle 70% of customer inquiries related to shipping status. Instead of answering with static text, the agent calls a track_package function connected to the internal tracking system, retrieves real-time data, and then summarizes it in natural language. As a result, response time dropped from an average of 4 minutes to 12 seconds, and customer satisfaction increased significantly without adding service staff.
2. Overcoming Model Knowledge Limitations
LLMs have a knowledge cutoff and do not know what happened after their last training. The model does not know the latest stock prices, tomorrow's weather, or the product stock in your warehouse. Function calling solves this problem by allowing the model to access external data in real-time through tools. The model does not need to "know" the answer — it only needs to know which tool to call to get that answer. This pattern is called Retrieval-Augmented Generation (RAG) with action, and it has become the de facto standard for business AI applications in 2026.
3. Reliability and Structured Output
One of the biggest problems in AI production is inconsistent output. Function calling forces the model to produce output in a structured schema (JSON schema) that can be validated programmatically. This allows applications to handle errors gracefully, perform retries, and ensure that data entering downstream systems is always valid. For companies integrating AI into financial, logistics, or healthcare systems where format errors can be fatal, function calling is a non-negotiable feature.
4. Cost and Token Efficiency
Instead of asking the model to generate long answers that are then processed with fragile regex or text parsing, function calling allows the model to directly produce concise function calls. This reduces the number of tokens generated and processed, which at production scale means significant cost savings. In 2026, with rising compute costs and demand for efficiency, architectures that prioritize function calling have proven to be 30-50% more economical than free-text-based architectures for structured tasks.
AI Agent and Function Calling Adoption in Indonesia
Key Players: The AI agent ecosystem in Indonesia in 2026 is dominated by a combination of global and local players. On the model and platform side, OpenAI (with GPT-5 and Assistant API), Anthropic (Claude 4 with advanced tool use features), Google (Gemini 2.5 with native function calling capabilities), and Meta (open-source Llama 4) are the primary choices. On the local side, platforms such as Kata.ai, Botika, and Prosa.ai have integrated function calling into their enterprise offerings. Meanwhile, open-source frameworks like LangGraph, CrewAI, and Microsoft's AutoGen are increasingly popular among Indonesian developers for building complex multi-tool agents.
Local Success Stories:
GoTo (Gojek-Tokopedia) implemented AI agents with function calling for integrated customer service, reducing ticket handling time by 45% and improving first-contact resolution by 30%.
Bank Mandiri launched a banking AI assistant that can call internal functions for balance checks, inter-account transfers, and bill payments directly from conversations, recording more than 2 million monthly interactions.
Telkom Indonesia built an AI agent for internal IT service automation, where the agent can reset passwords, open tickets, and run network diagnostics through function calling, saving thousands of technician work hours per month.
Halodoc uses AI agents with tools for initial symptom triage and automatic consultation scheduling, connecting patients to the right doctor in an average of 8 seconds.
Blibli implemented an AI shopping assistant that can call product search, price comparison, and personalized recommendation functions, increasing shopping cart conversion by 22%.
Challenges & How to Overcome Them
1. Managing Tool Definition Complexity
The more tools you provide to the model, the greater the risk of the model choosing incorrectly or filling parameters incorrectly. In production applications with dozens of functions, this can become a nightmare. How to overcome it: implement tool routing — group tools by domain and use a supervisor agent that selects the relevant group of tools before calling a specific function. Additionally, write very clear tool descriptions, include usage examples, and limit parameters to only those truly necessary. Best practice in 2026 is to start with 3-5 core tools and expand gradually while monitoring error rates.
2. Security and Malicious Execution Risks
When an AI agent has the ability to call functions that affect the real world — sending money, deleting data, sending emails — the risk of misuse increases dramatically. Prompt injection, where malicious users insert hidden instructions to manipulate the agent, is a real threat that must be anticipated. How to overcome it: implement human-in-the-loop for high-risk actions (for example, transfers above a certain value require manual confirmation), use a strict allowlist for callable functions, and implement comprehensive logging for auditing. In 2026, the "least privilege" principle — giving the agent only the minimum access necessary — has become a mandatory security standard.
3. Managing Context and Conversation History
AI agents that make multiple function calls in one session can quickly fill the model's context window, causing performance degradation or soaring costs. How to overcome it: use context summarization — periodically summarize conversation history and tool call results into a compact summary before continuing. Also implement tool result caching for repeated calls with the same parameters, and consider a stateless architecture where each request carries the minimal required context.
4. Handling Errors and Edge Cases in Tool Execution
Tools will fail: API down, wrong parameters, timeout, or unexpected return format. AI agents must be able to handle failures gracefully. How to overcome it: design every tool with clear error handling — return informative error messages to the model so it can try an alternative approach. Implement retry mechanisms with exponential backoff, and prepare fallback tools for critical scenarios. The 2026 best practice is to build "self-healing" agents that can diagnose their own failures and take corrective action without human intervention.
The Future of AI Agents with Tools and Function Calling
Agent-to-Agent Economy (A2A) — by 2027-2028, AI agents from different companies will communicate directly through standard protocols, calling each other's tools to complete cross-organizational transactions without human intervention.
Autonomous Multi-Agent Swarms — instead of one agent with many tools, the trend is shifting toward swarms of specialist agents collaborating, each with specialized tools, coordinated by an intelligent orchestrator agent.
Natural Language Tool Creation — models will be able to dynamically create new tools based on needs, write their own function code, and register them for use in the same session — without developers writing a single line of code.
Persistent Agent with Memory — agents will no longer be stateless; they will have long-term memory of user preferences, interaction history, and previous tool call results, enabling far higher personalization and efficiency.
Conclusion: Building Intelligence That Acts, Not Just Thinks
This tutorial has mapped out the technical and strategic foundations for building AI agents with tools and function calling — from basic concepts and tangible business benefits to implementation challenges and future directions. The essence is simple yet profound: in 2026, the value of AI no longer lies in its ability to generate fluent text, but in its ability to act — calling functions, manipulating systems, and completing real work. Function calling is the technical mechanism that bridges language intelligence with real-world execution, and anyone who masters it will be at the forefront of the ongoing intelligent automation revolution. For developers, product managers, and business leaders in Indonesia, this is not a question of "whether" but "how quickly" you start building. The future does not belong to those who talk the most about AI, but to those who build agents that actually work.