A support bot that makes up account balances is not just useless in a digital bank. It is dangerous. Financial conversations demand exact numbers, verified payees, and an audit trail for every claim. Large language models excel at conversation, but they hallucinate. When a user asks, “How much remain for my account?” the model must reach for a database, not imagination. That is exactly what function calling enforces, and it is the core of this build.
Google’s Gemma 4 gives developers a capable 31-billion parameter model that can follow complex instructions and carry on natural dialogue, including in regional dialects. Paired with Google AI Studio, it becomes a rapid prototyping environment where you can define tools, test edge cases, and export working JavaScript before you touch a server. The goal here is a fintech support agent that checks account balances, tracks transaction status, and pays bills. Crucially, it responds in Nigerian Pidgin when the user does, matching tone without ever improvising financial facts.
Why Function Calling Matters for Financial Bots
Without function calling, a language model treats every question as a creative writing exercise. Ask it for a balance and it might invent a plausible-sounding figure drawn from patterns in its training data. That failure mode is unacceptable when real money is involved.
Function calling reverses the flow. The model’s job is not to know the balance. Its job is to recognize intent, choose the correct tool, and extract parameters. When a user writes “Check my balance,” Gemma 4 emits a structured JSON request—something like a call to get_balance with an account_id. Your backend executes that call against the core banking system, gets the real figure, and feeds it back into the conversation. Only then does the model generate the human-facing sentence. Every answer comes from a tool call to a backend. Because the model is gated by external logic, hallucinations stop at the API boundary.
This pattern also creates clear audit trails. Each tool request and its corresponding result are logged in the message history. Regulators and risk teams can inspect exactly when a balance was checked and what number the user received.
Designing the Agent in Google AI Studio
The workflow starts inside Google AI Studio. Select gemma-4-31b-it, the instruct-tuned variant optimized for dialogue and instruction following.
Next, write system instructions that set hard boundaries. For a digital bank, the tone should be professional, direct, and calm. But the instructions must go further. Tell the model explicitly that it never estimates account data, never assumes a transaction status, and never completes a bill payment without confirming the tool result. If the user writes in Nigerian Pidgin, the model should reply in Nigerian Pidgin. If the user switches to English, the model follows. The system prompt is where you encode trust and safety policy in plain language.
Then define the tool schemas. Think of these as contracts between the model and your backend. You need at least three:
get_balance
Parameters:account_id(string, required)
Returns: current balance and currency.get_transaction_status
Parameters:transaction_reference(string, required)
Returns: status such as pending, completed, or failed, plus a timestamp.pay_bill
Parameters:biller_code(string, required),amount(number, required),account_pin(string, optional depending on your flow)
Returns: confirmation reference or error message.
Each schema uses a standard JSON format describing the function name, description, and parameter properties. The description fields matter immensely. Write them so the model understands when to invoke each tool. Ambiguous descriptions lead to wrong tool selection, so be specific: “Use get_balance when the user wants to know their current account balance. Do not use it for transaction history.”
Prototyping in the Browser
Before you write a single Express route, test the entire conversation flow inside AI Studio’s chat panel. This saves days of backend rework. Type a query in Nigerian Pidgin: “Wetin remain inside my account?” Watch whether Gemma 4 correctly emits a get_balance call or whether it tries to answer from training data. If it gets the parameters wrong—perhaps using account_number instead of account_id—you fix the schema description right there.
Przetestuj również scenariusze błędów. Poproś o status transakcji bez podawania numeru referencyjnego. Dobrze zainstruowany model powinien albo poprosić użytkownika o brakujący parametr, albo wywołać narzędzie z tym, co posiada, i pozwolić backendowi zwrócić błąd walidacji. Chcesz zobaczyć te zachowania w piaskownicy (sandbox), a nie na produkcji.
Gdy prompty i schematy będą działać poprawnie, wyeksportuj kod JavaScript. AI Studio generuje czysty fragment kodu, który strukturyzuje żądanie API wraz z Twoim system promptem, wiadomością użytkownika i definicjami narzędzi. Stanie się to fundamentem Twojej logiki backendowej.
Podłączanie backendu Express
Weź wyeksportowany kod i umieść go w aplikacji Express. Architektura jest prosta, ale kluczowym elementem jest pętla wykonawcza.
Skonfiguruj punkt końcowy POST — na przykład /chat — który przyjmuje wiadomość użytkownika oraz historię sesji. Przekaż je do punktu końcowego Gemma 4, do którego możesz dotrzeć za pomocą API kompatybilnego z OpenAI lub własnego punktu końcowego wnioskowania Google, w zależności od wybranego sposobu hostowania.
Odpowiedź modelu można podzielić na dwie kategorie. Albo jest to końcowa wiadomość tekstowa, albo zawiera tool_call żądający danych. Gdy otrzymasz wywołanie narzędzia, wykonaj odpowiadającą mu funkcję w swoim backendzie. Zapytaj bazę danych o saldo. Połącz się z procesorem płatności, aby sprawdzić status rachunku. Do historii konwersacji dodaj wynik działania narzędzia jako nową wiadomość z rolą tool, a następnie odeślij cały zaktualizowany tablicę z powrotem do Gemma 4.
Powtarzaj tę pętlę, aż model zwróci końcową odpowiedź tekstową. Ta odpowiedź będzie oparta na rzeczywistych danych, które dostarczyłeś. Express ułatwia tę koordynację, ponieważ każde przejście przez pętlę to po prostu kolejne żądanie HTTP, a możesz czysto obsługiwać wykonanie narzędzi za pomocą async/await.
Na wczesnym etapie rozwoju zastąp wywołania tych narzędzi danymi typu mock. Prosty obiekt JavaScript mapujący przykładowe identyfikatory kont na salda wystarczy, aby udowodnić, że pętla działa. Celem jest zweryfikowanie wzorca interakcji przed integracją z niestabilnymi zewnętrznymi API bankowymi.
Od prototypu do produkcji
Działający prototyp to nie jest produkcyjna infrastruktura bankowa, ale droga od jednego do drugiego jest jasna.
Zastąp dane typu mock rzeczywistymi API bankowości rdzennej (core banking). Podłącz swoje narzędzie get_balance do systemu księgowego za pomocą REST lub gRPC. Podepnij pay_bill pod swój rzeczywisty switch płatniczy. Robiąc to, nie musisz zmieniać modelu ani logiki konwersacji; wymieniasz jedynie implementację obsługi narzędzi.
Dodaj Redis do zarządzania sesjami. Stan konwersacji w bankowości jest wrażliwy i regulowany. Musisz bezpiecznie przechowywać historię wiadomości, ustawiać dla nich czas wygaśnięcia i zapewniać, że sesja użytkownika nie wycieknie między żądaniami. Redis obsługuje to za pomocą polityk TTL i szybkiego wyszukiwania kluczy.
Gdy ruch wzrośnie, przenieś wnioskowanie (inference) do vLLM. AI Studio jest doskonałe do prototypowania, ale hostowane samodzielnie wnioskowanie za pomocą vLLM na klastrach GPU daje kontrolę nad opóźnieniami, grupowaniem (batching) i kosztami w skali. Gemma 4 działa wydajnie pod vLLM, a zachowanie wywoływania narzędzi pozostaje identyczne.
Kluczowe wnioski
Budowanie godnego zaufania agenta fintech polega mniej na rozmiarze modelu, a bardziej na ograniczeniach architektonicznych. Gemma 4 zapewnia wystarczającą moc rozumowania, aby analizować mieszany kod językowy nigeryjskiego pidginu i kierować złożone intencje, ale bezpieczeństwo wynika z pętli narzędziowej. Każde saldo jest pobierane na żywo. Każda płatność rachunku jest potwierdzana przez zewnętrzny system. Nic nie jest zmyślone.
Zacznij w przeglądarce z AI Studio, utwardź logikę w pętli Express i podmień ją na rzeczywistą infrastrukturę bankową, gdy przepływy konwersacji będą już niezawodne. W ten sposób dostarczasz bota, któremu ludzie mogą naprawdę powierzyć swoje pieniądze.
Źródło: Building a Full Gemma 4 Google AI Studio Project: A Fintech Support Agent
Opcjonalna społeczność edukacyjna: GyaanSetu AI na Telegramie
