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:

  1. get_balance
    Parameters: account_id (string, required)
    Returns: current balance and currency.

  2. get_transaction_status
    Parameters: transaction_reference (string, required)
    Returns: status such as pending, completed, or failed, plus a timestamp.

  3. 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.

Jaribu pia mifumo ya hitilafu (failure modes). Omba hali ya muamala bila kutoa namba ya kumbukumbu (reference number). Modeli iliyoelekezwa vizuri inapaswa ama kumwomba mtumiaji kiparameta kilichokosekana au kuita zana (tool) kwa kile kilichopo na kuruhusu backend kurudisha kosa la uhakiki (validation error). Unataka kuona tabia hizi kwenye sandbox, siyo kwenye uzalishaji (production).

Mara tu prompts na schema zinapofanya kazi kwa usahihi, toa (export) kodi ya JavaScript. AI Studio inazalisha kipande safi (clean snippet) kinachopanga ombi la API pamoja na system prompt yako, ujumbe wa mtumiaji, na tafsiri za zana (tool definitions). Hii inakuwa msingi wa mantiki yako ya backend.

Kuunganisha Express Backend

Chukua kodi iliyotolewa na uingize kwenye programu ya Express. Muundo (architecture) ni rahisi, lakini mzunguko wa utekelezaji (execution loop) ndio sehemu muhimu zaidi.

Sanidi endpoint ya POST—labda /chat—ambayo inakubali ujumbe wa mtumiaji na historia yoyote ya kikao (session history). Zipeleke hizi kwenye endpoint ya Gemma 4, ambayo unaweza kuipata kupitia API inayofanana na OpenAI au endpoint ya inference ya Google kulingana na chaguo lako la uhosting.

Jibu kutoka kwa modeli lingekuwa katika moja ya makundi mawili. Ama ni ujumbe wa mwisho wa maandishi, au una tool_call inayoomba data. Unapopokea tool call, tekelesa kazi inayohusika dhidi ya backend yako. Uliza kwenye hifadhidata (database) kuhusu salio. Omba kwa mchakato wa malipo (payment processor) kuhusu hali ya bili. Ambatanisha matokeo ya zana kwenye historia ya mazungumzo kama ujumbe mpya wenye nafasi (role) ya tool, na utume array nzima iliyosasishwa kwa Gemma 4.

Rudia mzunguko huu hadi modeli irudishe jibu la mwisho la maandishi. Jibu hilo litakuwa limethibitishwa na data halisi uliyotoa. Express inafanya uratibu huu kuwa rahisi kwa sababu kila hatua katika mzunguko ni ombi lingine la HTTP, na unaweza kutumia async/await kutekeleza zana kwa urahisi.

Wakati wa maendeleo ya awali, tumia data za mfano (mock data) kwa ajili ya tool calls hizi. Object rahisi ya JavaScript inayounganisha ID za akaunti za sampuri na salio inatosha kuthibitisha kuwa mzunguko unafanya kazi. Lengo ni kuhakiki mfumo wa mwingiliano kabla ya kuunganishwa na API za benki za watu wa tatu ambazo zinaweza kuwa tete.

Kutoka kwenye Prototype hadi Uzalishaji (Production)

Prototype inayofanya kazi si miundombinu ya kibenki ya uzalishaji, lakini njia kutoka moja hadi nyingine iko wazi.

Badilisha mock data na API halisi za kibenki (core banking APIs). Unganisha zana yako ya get_balance na mfumo wa leja (ledger system) kupitia REST au gRPC. Unganisha pay_bill kwenye switch yako halisi ya malipo. Unapofanya hivi, huhitaji kubadilisha modeli au mantiki ya mazungumzo; unabadilisha tu utekelezaji wa tool handlers.

Ongeza Redis kwa ajili ya usimamizi wa kikao (session management). Hali ya mazungumzo katika benki ni nyeti na ina kanuni. Unahitaji kuhifadhi historia za ujumbe kwa usalama, kuzimaliza baada ya muda fulani uliowekwa, na kuhakikisha kuwa kikao cha mtumiaji hakiwezi kuvuja kwenye maombi mengine. Redis inashughulikia hili kwa sera za TTL na utafutaji wa haraka wa funguo (key lookups).

Wakati trafiki inapoongezeka, hamishia inference kwenye vLLM. AI Studio ni nzuri kwa kutengeneza prototype, lakini inference inayojiendesha (self-hosted inference) kwa kutumia vLLM kwenye GPU clusters inakupa udhibiti wa latency, batching, na gharama kwa kiwango kikubwa. Gemma 4 inafanya kazi kwa ufanisi chini ya vLLM, na tabia ya tool-calling inabaki vilevile.

Funzo la Kweli

Kujenga wakala wa fintech anayeaminika si kuhusu ukubwa wa modeli bali zaidi kuhusu vizuizi vya usanifu (architectural constraints). Gemma 4 inatoa nguvu ya kutosha ya kufikiri ili kuchanganua Nigerian Pidgin iliyochanganywa na lugha nyingine na kuelekeza nia tata, lakini usalama unatokana na mzunguko wa zana (tool loop). Kila salio linatafutwa mubashara. Kila malipo ya bili unathibitishwa na mfumo wa nje. Hakuna kitu kinachobuniwa.

Anza kwenye kivinjari (browser) ukitumia AI Studio, imarisha mantiki kwenye mzunguko wa Express, na ubadilishe na miundombinu halisi ya kibenki mara tu mtiririko wa mazungumzo unapokuwa imara kabisa. Hivyo ndivyo unavyotengeneza bot ambayo watu wanaweza kuiamini kweli kwa pesa zao.

Chanzo: Building a Full Gemma 4 Google AI Studio Project: A Fintech Support Agent

Jumuiya ya kujifunza ya hiari: GyaanSetu AI kwenye Telegram