In this final chapter of our series dedicated to Autonomous Micro-Agents, we step away from the terminal to understand the bigger picture. We examine why the Function Calling architecture we built complements RAG (Retrieval-Augmented Generation) systems and how to choose the right technology based on the nature of our data.
“In this article, we transformed the Gemini model from a simple chat partner into an agent capable of execution. We gave it the ability to interact with the local MariaDB server through a Python function and taught it to request inventory queries through direct API calls. Today, we take stock: why did we use this Function Calling approach, and in which scenarios should we replace it or complement it with RAG-based search?”
Throughout this series, we have built a complete infrastructure together: we set up virtual machines in Proxmox, secured connections without port forwarding, and wrote the Python script that allows a Cloud-based AI to request queries against our local inventory.
By analyzing the execution logic of our script, we can observe an interesting phenomenon: if the user uses words that do not appear in the database at all (such as “memory sticks” instead of RAM), the local system may return zero results. This rigid behavior leads us to one of the most important debates in AI engineering today: Semantic Search (RAG) vs. Action Execution (Function Calling).
🔹Semantic Flexibility (RAG) vs. Deterministic Execution (Function Calling)
To understand the difference between these two approaches, we need to look at how a large language model (LLM) accesses and uses external information:
- The RAG (Retrieval-Augmented Generation) system: It is primarily used for retrieving information based on meaning and semantic similarity. In a typical implementation, documents (PDFs, guides, manuals, or other text sources) are split into chunks, converted into numerical representations (vectors), and stored in a vector database. When a user asks a question, the system searches for chunks whose meaning is similar to that of the question. This allows it to recognize that “memory stick” and “RAM module” refer to the same concept, even if the exact wording does not appear in the original documents.
- The Function Calling system we built: It allows the model to request that operations be performed through external functions. In our project, Gemini analyzes the question, decides which tool to use, and passes the arguments to the Python function. The model does not query the database directly. The Python script executes the SQL query, and the result is sent back to the model so it can formulate the response. In the current implementation, the search uses the SQL
LIKEoperator. Therefore, if the supplied term does not match the text in the database, the query may return “not found,” even if the product exists under a different name. This is a limitation of the search mechanism we implemented, not an inherent limitation of Function Calling technology.
🔹Comparison Table: How AI Processes Information
To visualize the data flow in these two types of applications, take a look at the table below:
| Architectural Feature | RAG Architecture (Semantic Search) | Function Calling Architecture (SQL Agent) |
|---|---|---|
| Typical Use | Retrieving information from documents, technical manuals, PDFs, and knowledge bases. | Performing operations through external functions, such as querying databases or calling software services. |
| How It Works | Converting information chunks into vectors and identifying those that are semantically closest to the user’s question. | The model selects a function and provides the required arguments. The Python code executes the SQL query and returns the result. |
| Linguistic Behavior | Can identify relevant information even when the question is phrased differently from the documents, depending on the quality of indexing and semantic search. | Depends on how the function is implemented. In our project, SQL search using LIKE requires a text match and may fail to find synonyms. |
| Accuracy of Retrieved Data | Depends on the relevance of the retrieved chunks and the quality of the indexed sources. | Can return exact values from the database, provided the query and the data are correct. |
| Risk of Hallucination | The model may misinterpret or incorrectly rephrase information retrieved from documents. | Tool results can be verified, but the model may still misinterpret the data or produce an incorrect response. |
| System Objective | To retrieve relevant information, answer questions, and synthesize content. | To perform operations through external tools, check stock levels, retrieve data, or modify information. |
🔹Scenario Analysis: System Behavior
Let’s see how these theoretical concepts translate into application execution through two practical scenarios based on the structure of our code:
- Scenario 1: A Flexible Query (“Do we have any memory modules in stock?”)
- In a RAG environment: The system can identify the semantic relationship between the term “memory modules” and the product description
RAM DDR3L, provided that the indexing and search mechanisms support this association. This allows it to retrieve relevant information even when the wording of the question differs from the text in the database. - In our SQL Agent: Gemini extracts the term “memory modules” and passes it to the Python function. The local script executes an SQL query against the MariaDB database using the
LIKEoperator. Since the text stored in the table isRAM DDR3L, while the search term is “memory modules,” the text match does not identify the product. As a result, the agent may report that the product was not found, even though it is in stock. This is a limitation of the search mechanism implemented in our project, not of Function Calling technology itself.
- In a RAG environment: The system can identify the semantic relationship between the term “memory modules” and the product description
- Scenario 2: Questions Outside the Application’s Scope (“What is the capital of France?”)
- In a RAG environment: If the application’s instructions do not sufficiently restrict its scope, the model may answer using its general knowledge, even when the requested information is not part of the company’s data.
- In our SQL Agent: The system instruction includes a Guardrail mechanism that tells the model not to use the database tool for requests outside the application’s business domain. In the tested scenario, the model recognizes that the question is unrelated to its role and declines to use the tool, providing the predefined safety response. This behavior results from the instructions given to the model, not from a restriction automatically imposed by Function Calling technology.
🔹Decision Matrix: How to Choose the Right Architecture
When designing an AI-powered application within your own local infrastructure, the choice of technology should take into account the nature of the data, how it is used, and the outcome you expect:
- Choose RAG when: You need to retrieve relevant information based on the meaning and context of a question. This approach is suitable for technical support ticket histories, network procedures, server documentation, or equipment user manuals, where users may phrase their questions differently from the wording in the original sources.
- Choose Function Calling when: The model needs to request that operations be performed through external functions and use the results. This approach is suitable for checking physical inventory, verifying dynamic prices, managing user lists, or interacting with financial systems, where it is important that operations are performed using up-to-date data.
💡 Behind the Scenes: The Explicit Function Calling Flow
It is essential to understand the logic behind this chapter. While other frameworks abstract away part of the execution process behind the scenes, direct REST communication gives us visibility into the exchange of messages between the local application and the AI model, as well as control over how calls to local functions are validated and executed. The local Python script acts as a bridge between the model and your infrastructure. The model analyzes the function’s structure and issues a “Function Call” request, together with the required arguments. The local script receives the request, validates the parameters, queries the MariaDB database, and sends the result back to the model. This keeps the execution of local operations under the control of the Python code. Using parameterized queries also helps reduce the risk of data received from the model being interpreted as part of the SQL statement.
🏁 Conclusion: From Infrastructure to Autonomous Artificial Intelligence
We started with the local infrastructure and gradually built a system in which an AI model can request that operations be performed through external functions, using real data from a database. We then examined the difference between Function Calling and RAG and looked beyond the code to understand how complex artificial intelligence applications work from the user’s perspective.
Throughout these eight episodes, we moved from concrete technical components to concepts such as autonomy, collaboration between agents, and multi-agent architectures. We saw that behind a simple interface, there can be complex processes, multiple specialized components, and decisions made by AI models.
Our experiment is not a fully autonomous system that starts up and runs without human intervention. The Python script must be launched manually, and this limitation is part of the implementation we built and tested. What matters is that we have understood the technical workflow and laid the foundations for an architecture that can be extended in the future.
This is the bigger picture we set out to build: not just to use artificial intelligence, but to understand what happens behind the scenes.
Stay Free! Stay Hidden! Stay Autonomous!
