<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Agbo, Daniel Onuoha </title>
    <description>The latest articles on DEV Community by Agbo, Daniel Onuoha  (@shieldstring).</description>
    <link>https://dev.to/shieldstring</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F261529%2F89766ddd-e5eb-4837-9d17-eacb12a93b0c.jpg</url>
      <title>DEV Community: Agbo, Daniel Onuoha </title>
      <link>https://dev.to/shieldstring</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shieldstring"/>
    <language>en</language>
    <item>
      <title>A Practical Trust Architecture for AI Systems in Africa</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Thu, 19 Nov 2026 23:00:00 +0000</pubDate>
      <link>https://dev.to/shieldstring/a-practical-trust-architecture-for-ai-systems-in-africa-371e</link>
      <guid>https://dev.to/shieldstring/a-practical-trust-architecture-for-ai-systems-in-africa-371e</guid>
      <description>&lt;p&gt;&lt;em&gt;Building an AI model is an engineering achievement. Building a system people can safely depend on is an entirely different challenge.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In my previous article, [Trust Is the Deployment Obstacle: Why African AI Projects Stall After the Demo], I explored a recurring problem in Africa's AI ecosystem: promising projects often demonstrate impressive capabilities but struggle to make the transition into production.&lt;/p&gt;

&lt;p&gt;The underlying issue is not always model performance.&lt;/p&gt;

&lt;p&gt;It is the difficulty of establishing trust among the people and institutions expected to use, manage, regulate, and depend on these systems.&lt;/p&gt;

&lt;p&gt;But identifying trust as a problem is only the beginning.&lt;/p&gt;

&lt;p&gt;The more important question is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do we actually engineer trust into an AI system?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How do we move from an experimental notebook or an impressive demonstration to an AI-powered product that can operate reliably in a financial institution, hospital, agricultural platform, logistics company, or government service?&lt;/p&gt;

&lt;p&gt;The answer requires a different approach to AI architecture.&lt;/p&gt;

&lt;p&gt;Instead of treating trust as a policy document or a collection of security features, we should treat it as an architectural property of the entire system.&lt;/p&gt;

&lt;p&gt;In this article, we will explore a practical trust architecture for production AI systems, including data validation, model evaluation, confidence thresholds, human oversight, observability, auditability, security, and continuous monitoring.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Start With the Architecture, Not the Model
&lt;/h2&gt;

&lt;p&gt;A common approach to building AI products looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Collect data.&lt;/li&gt;
&lt;li&gt;Train a model.&lt;/li&gt;
&lt;li&gt;Evaluate accuracy.&lt;/li&gt;
&lt;li&gt;Expose the model through an API.&lt;/li&gt;
&lt;li&gt;Connect the API to an application.&lt;/li&gt;
&lt;li&gt;Deploy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a reasonable starting point for experimentation.&lt;/p&gt;

&lt;p&gt;However, it leaves several important questions unanswered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How do we know the incoming data is reliable?&lt;/li&gt;
&lt;li&gt;How do we detect when the model begins producing unreliable predictions?&lt;/li&gt;
&lt;li&gt;What happens when the model is uncertain?&lt;/li&gt;
&lt;li&gt;Can we reconstruct how a particular decision was generated?&lt;/li&gt;
&lt;li&gt;Who reviews potentially harmful outputs?&lt;/li&gt;
&lt;li&gt;What happens when the AI service becomes unavailable?&lt;/li&gt;
&lt;li&gt;How do we roll back a problematic model version?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions suggest that a production AI system needs several interconnected layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  A practical trust architecture
&lt;/h3&gt;

&lt;p&gt;The following architecture illustrates how these components can work together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 USERS / APPLICATIONS
                         |
                         v
                API GATEWAY / AUTH
                         |
                         v
                REQUEST VALIDATION
                         |
                         v
                 DATA GOVERNANCE
              /                  \
             v                    v
       Data Validation       Privacy Controls
             |                    |
             +---------+----------+
                       |
                       v
                 AI INFERENCE
                       |
                       v
                OUTPUT VALIDATION
                       |
                       v
              CONFIDENCE EVALUATION
                       |
             +---------+----------+
             |                    |
             v                    v
       Auto-eligible         Human Review
             |                    |
             +---------+----------+
                       |
                       v
                DECISION LAYER
                       |
             +---------+----------+
             |                    |
             v                    v
       Application/API       Audit Logging
             |
             v
          END USER

       MONITORING ACROSS ALL LAYERS
       MODEL PERFORMANCE / DRIFT
       SECURITY / LATENCY / ERRORS
       INCIDENTS / SYSTEM HEALTH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important idea is that the model is only one component.&lt;/p&gt;

&lt;p&gt;A trustworthy system needs mechanisms around the model that validate its inputs, evaluate its outputs, control how decisions are executed, and preserve enough evidence to investigate problems.&lt;/p&gt;

&lt;p&gt;Let's examine these components individually.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Build a Reliable Data Validation Layer
&lt;/h2&gt;

&lt;p&gt;Before an AI model can produce a meaningful result, it must receive meaningful input.&lt;/p&gt;

&lt;p&gt;This sounds obvious, but data quality is one of the most underestimated challenges in production AI.&lt;/p&gt;

&lt;p&gt;Consider an AI-powered credit assessment platform operating in Nigeria.&lt;/p&gt;

&lt;p&gt;The platform receives financial information from multiple sources. Some records may be incomplete, some transactions may be duplicated, and some customers may have inconsistent financial histories.&lt;/p&gt;

&lt;p&gt;If these records enter the model without validation, the system can produce misleading predictions.&lt;/p&gt;

&lt;p&gt;The solution is to introduce a data validation layer before inference.&lt;/p&gt;

&lt;p&gt;This layer should check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Required fields.&lt;/li&gt;
&lt;li&gt;Data types and formats.&lt;/li&gt;
&lt;li&gt;Missing values.&lt;/li&gt;
&lt;li&gt;Duplicate records.&lt;/li&gt;
&lt;li&gt;Invalid ranges.&lt;/li&gt;
&lt;li&gt;Unexpected distributions.&lt;/li&gt;
&lt;li&gt;Data freshness.&lt;/li&gt;
&lt;li&gt;Schema changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Python-based AI services, Pydantic provides a practical way to validate incoming data.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field_validator&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreditAssessmentRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;monthly_income&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;monthly_expenses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;transaction_count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;employment_status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;transaction_date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;

    &lt;span class="nd"&gt;@field_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"employment_status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nd"&gt;@classmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_employment_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cls&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"employed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"self_employed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"unemployed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"business_owner"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Invalid employment status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does not guarantee that the information is truthful or complete.&lt;/p&gt;

&lt;p&gt;It establishes that the data meets the expected structural requirements before further processing.&lt;/p&gt;

&lt;p&gt;For more advanced systems, validation should also include statistical checks, anomaly detection, data provenance, and consistency checks across connected data sources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An important distinction:&lt;/strong&gt; Valid data is not necessarily representative data.&lt;/p&gt;

&lt;p&gt;A dataset can pass every schema validation test and still systematically exclude important segments of the population.&lt;/p&gt;

&lt;p&gt;That is why data validation must be accompanied by data quality evaluation and fairness testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Introduce Confidence-Aware AI Decisions
&lt;/h2&gt;

&lt;p&gt;One of the most important principles in trustworthy AI is that a system should not behave as though every prediction is equally reliable.&lt;/p&gt;

&lt;p&gt;Consider a medical image classification system.&lt;/p&gt;

&lt;p&gt;It receives an image and predicts whether a particular condition is present.&lt;/p&gt;

&lt;p&gt;The model might produce:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"condition_detected"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.96&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On another image, it might return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"condition_detected"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.54&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These outputs should not necessarily trigger the same operational response.&lt;/p&gt;

&lt;p&gt;A production system can introduce confidence-based routing.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Confidence&lt;/th&gt;
&lt;th&gt;System behaviour&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Eligible for the approved automated workflow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;Additional verification&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Human review or abstention&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The thresholds must be established through validation against the specific use case, rather than chosen arbitrarily.&lt;/p&gt;

&lt;p&gt;A simple implementation might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evaluate_prediction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;confidence&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.90&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"high_confidence"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"requires_review"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;confidence&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.70&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"needs_verification"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"requires_review"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"low_confidence"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"requires_review"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example illustrates a routing mechanism, not a clinically validated decision policy.&lt;/p&gt;

&lt;p&gt;There is also an important technical consideration: a model's confidence score is not necessarily its probability of being correct.&lt;/p&gt;

&lt;p&gt;A model can be highly confident and still be wrong.&lt;/p&gt;

&lt;p&gt;This is why production systems should evaluate calibration, class-specific performance, out-of-distribution inputs, and the consequences of false positives and false negatives.&lt;/p&gt;

&lt;p&gt;For high-impact applications, abstaining from making a prediction can be a valuable capability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A trustworthy AI system should be able to say, "I don't have enough reliable information to answer this."&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Design Human-in-the-Loop Workflows
&lt;/h2&gt;

&lt;p&gt;Automation should not mean removing humans from every decision.&lt;/p&gt;

&lt;p&gt;In many applications, human oversight is an essential component of the architecture.&lt;/p&gt;

&lt;p&gt;Consider a fraud detection system used by a fintech company.&lt;/p&gt;

&lt;p&gt;The model identifies suspicious transactions and assigns risk scores.&lt;/p&gt;

&lt;p&gt;Instead of automatically blocking every flagged transaction, the system can route selected cases to a fraud analyst.&lt;/p&gt;

&lt;p&gt;A simplified workflow could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Incoming Transaction
        |
        v
   AI Risk Model
        |
        v
   Risk Evaluation
        |
   +----+----+
   |         |
 Low Risk  High Risk
   |         |
   v         v
Continue   Review Queue
              |
              v
         Human Analyst
              |
       +------+------+
       |             |
       v             v
    Approve        Escalate
       |             |
       +------+------+
              |
              v
       Record Outcome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The human reviewer should receive enough context to make an informed decision:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Relevant transaction information.&lt;/li&gt;
&lt;li&gt;Model-generated risk indicators.&lt;/li&gt;
&lt;li&gt;Supporting evidence.&lt;/li&gt;
&lt;li&gt;Previous relevant events.&lt;/li&gt;
&lt;li&gt;Reason for escalation.&lt;/li&gt;
&lt;li&gt;Available actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The workflow should also record the reviewer’s decision.&lt;/p&gt;

&lt;p&gt;This creates a feedback mechanism that can help improve future evaluations and operational policies.&lt;/p&gt;

&lt;p&gt;However, human oversight must be meaningful.&lt;/p&gt;

&lt;p&gt;A human reviewer who simply clicks "Approve" without understanding the recommendation does not provide effective oversight.&lt;/p&gt;

&lt;p&gt;For high-impact systems, reviewers need adequate information, appropriate authority, sufficient time, and clear escalation procedures.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Make AI Systems Observable
&lt;/h2&gt;

&lt;p&gt;Traditional application monitoring focuses on metrics such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU utilization.&lt;/li&gt;
&lt;li&gt;Memory consumption.&lt;/li&gt;
&lt;li&gt;Request latency.&lt;/li&gt;
&lt;li&gt;HTTP error rates.&lt;/li&gt;
&lt;li&gt;Database performance.&lt;/li&gt;
&lt;li&gt;Service availability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These metrics remain important for AI applications.&lt;/p&gt;

&lt;p&gt;However, an AI system can be technically healthy while producing increasingly unreliable predictions.&lt;/p&gt;

&lt;p&gt;Imagine a model deployed for agricultural disease detection.&lt;/p&gt;

&lt;p&gt;The API responds successfully. Inference takes 200 milliseconds. Server utilization is normal.&lt;/p&gt;

&lt;p&gt;But a change in weather conditions, crop varieties, or image capture devices causes the model's predictions to become less reliable.&lt;/p&gt;

&lt;p&gt;From the perspective of conventional infrastructure monitoring, everything looks fine.&lt;/p&gt;

&lt;p&gt;From the perspective of the farmer relying on the system, something is wrong.&lt;/p&gt;

&lt;p&gt;This is why AI observability needs additional dimensions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Monitoring area&lt;/th&gt;
&lt;th&gt;What to monitor&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Infrastructure&lt;/td&gt;
&lt;td&gt;CPU, memory, availability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API&lt;/td&gt;
&lt;td&gt;Latency, throughput, error rates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data&lt;/td&gt;
&lt;td&gt;Missing values, schema changes, distribution shifts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model&lt;/td&gt;
&lt;td&gt;Accuracy, precision, recall, calibration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Predictions&lt;/td&gt;
&lt;td&gt;Confidence distributions, unusual outputs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fairness&lt;/td&gt;
&lt;td&gt;Performance across relevant user groups&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Human review&lt;/td&gt;
&lt;td&gt;Escalation rates, overrides, review outcomes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security&lt;/td&gt;
&lt;td&gt;Unauthorised access, suspicious activity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Tools such as Prometheus, Grafana, OpenTelemetry, and Evidently AI can support different parts of this monitoring architecture.&lt;/p&gt;

&lt;p&gt;The important point is to monitor both the infrastructure and the behaviour of the AI system.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Detect Model Drift Before It Becomes a Business Problem
&lt;/h2&gt;

&lt;p&gt;Models are trained using historical data.&lt;/p&gt;

&lt;p&gt;But the world changes.&lt;/p&gt;

&lt;p&gt;Customer behaviour changes. Economic conditions change. User populations evolve. Agricultural environments shift. Fraud patterns become more sophisticated.&lt;/p&gt;

&lt;p&gt;A model that performed well during evaluation may gradually become less effective after deployment.&lt;/p&gt;

&lt;p&gt;This is commonly discussed under two related concepts:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data drift:&lt;/strong&gt; The distribution of incoming data changes compared with the data used during training.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concept drift:&lt;/strong&gt; The relationship between input features and the target outcome changes over time.&lt;/p&gt;

&lt;p&gt;For example, a credit assessment model trained on historical income patterns may become less reliable when economic conditions change significantly.&lt;/p&gt;

&lt;p&gt;A fraud detection model may struggle when attackers develop new transaction patterns.&lt;/p&gt;

&lt;p&gt;To address this, production systems should:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Establish baseline data distributions.&lt;/li&gt;
&lt;li&gt;Continuously monitor incoming data.&lt;/li&gt;
&lt;li&gt;Compare current distributions against historical baselines.&lt;/li&gt;
&lt;li&gt;Evaluate model performance when reliable ground-truth labels become available.&lt;/li&gt;
&lt;li&gt;Trigger alerts when defined thresholds are exceeded.&lt;/li&gt;
&lt;li&gt;Initiate investigation and controlled retraining when necessary.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A monitoring system should not automatically retrain and deploy a new model simply because drift is detected.&lt;/p&gt;

&lt;p&gt;Drift is a signal that investigation is required, not proof that a new model will be better.&lt;/p&gt;

&lt;p&gt;Every updated model should undergo evaluation, testing, approval, and controlled deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Make Every Important AI Decision Auditable
&lt;/h2&gt;

&lt;p&gt;Imagine a customer challenging an AI-generated decision made three months ago.&lt;/p&gt;

&lt;p&gt;The organisation needs to answer several questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which model generated the prediction?&lt;/li&gt;
&lt;li&gt;What relevant data was provided?&lt;/li&gt;
&lt;li&gt;What output did the model produce?&lt;/li&gt;
&lt;li&gt;Was the output modified or reviewed?&lt;/li&gt;
&lt;li&gt;Which human approved the final action?&lt;/li&gt;
&lt;li&gt;What version of the system was running?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the organisation cannot reconstruct the decision, it has a serious accountability problem.&lt;/p&gt;

&lt;p&gt;This is where audit logging becomes essential.&lt;/p&gt;

&lt;p&gt;A simplified audit record might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"request_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"req_00123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"model_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"credit-risk-model"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"model_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"v2.4.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"timestamp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-19T10:30:00Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"medium_risk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"review_required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"review_status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"approved"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"reviewer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"analyst_042"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a real implementation, records should include the relevant provenance and decision metadata required by the application.&lt;/p&gt;

&lt;p&gt;However, auditability does not mean storing every piece of personal information indefinitely.&lt;/p&gt;

&lt;p&gt;Sensitive information should be minimised, protected, access-controlled, and retained according to applicable legal and operational requirements.&lt;/p&gt;

&lt;p&gt;Useful audit infrastructure should support:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Immutable or tamper-evident records.&lt;/li&gt;
&lt;li&gt;Access control.&lt;/li&gt;
&lt;li&gt;Model version tracking.&lt;/li&gt;
&lt;li&gt;Timestamped events.&lt;/li&gt;
&lt;li&gt;Human intervention history.&lt;/li&gt;
&lt;li&gt;Incident investigation.&lt;/li&gt;
&lt;li&gt;Retention policies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is to make consequential system behaviour traceable without creating unnecessary privacy risks.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Security and Privacy Must Be Built Into the AI Lifecycle
&lt;/h2&gt;

&lt;p&gt;AI introduces additional security and privacy concerns.&lt;/p&gt;

&lt;p&gt;An AI application may process personal information, financial records, medical information, business documents, or proprietary datasets.&lt;/p&gt;

&lt;p&gt;It may also interact with external model providers, vector databases, third-party APIs, and cloud infrastructure.&lt;/p&gt;

&lt;p&gt;Every integration creates potential risks.&lt;/p&gt;

&lt;p&gt;Some important considerations include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data minimisation:&lt;/strong&gt; Collect and process only the information required for the intended purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encryption:&lt;/strong&gt; Protect sensitive data during transmission and storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access control:&lt;/strong&gt; Ensure that users and services can only access authorised resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secrets management:&lt;/strong&gt; Avoid hardcoding API keys, credentials, or database passwords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt injection protection:&lt;/strong&gt; Treat external documents and user-provided content as untrusted inputs, particularly in systems using retrieval-augmented generation (RAG).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output validation:&lt;/strong&gt; Validate model-generated content before passing it to downstream services or executing actions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API protection:&lt;/strong&gt; Apply authentication, authorisation, rate limiting, and request validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third-party risk management:&lt;/strong&gt; Understand how external AI providers process, retain, and potentially use submitted data.&lt;/p&gt;

&lt;p&gt;For applications operating in Nigeria, the Nigeria Data Protection Act 2023 and applicable guidance from the Nigeria Data Protection Commission should be considered when designing data collection, processing, storage, and sharing workflows.&lt;/p&gt;

&lt;p&gt;For systems operating across multiple African countries, teams must also assess the applicable laws and regulatory requirements in each jurisdiction.&lt;/p&gt;

&lt;p&gt;Security is not a final deployment checklist.&lt;/p&gt;

&lt;p&gt;It is a continuous engineering responsibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Build a Responsible Model Deployment Pipeline
&lt;/h2&gt;

&lt;p&gt;Trustworthy AI requires controlled model releases.&lt;/p&gt;

&lt;p&gt;A model should not move directly from an experiment into production simply because it performs well on a test dataset.&lt;/p&gt;

&lt;p&gt;A practical deployment pipeline could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        DATA COLLECTION
               |
               v
        DATA VALIDATION
               |
               v
          MODEL TRAINING
               |
               v
        MODEL EVALUATION
               |
               v
       SECURITY / FAIRNESS
          EVALUATION
               |
               v
        MODEL REGISTRY
               |
               v
        STAGING DEPLOYMENT
               |
               v
        CONTROLLED TESTING
               |
               v
         APPROVAL GATE
               |
               v
       PRODUCTION DEPLOYMENT
               |
               v
       CONTINUOUS MONITORING
               |
               v
         MODEL REVIEW
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A production implementation can combine tools such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MLflow:&lt;/strong&gt; Experiment tracking and model lifecycle management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DVC:&lt;/strong&gt; Dataset and pipeline versioning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Actions:&lt;/strong&gt; Automated testing and deployment workflows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker:&lt;/strong&gt; Reproducible application environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prometheus and Grafana:&lt;/strong&gt; Infrastructure and application monitoring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evidently AI:&lt;/strong&gt; Data and model evaluation and monitoring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes:&lt;/strong&gt; Container orchestration for systems that need it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not every AI project needs this entire stack.&lt;/p&gt;

&lt;p&gt;A small startup building a low-risk recommendation engine may need a much simpler infrastructure than a financial institution deploying AI-assisted credit decisions.&lt;/p&gt;

&lt;p&gt;The architecture should match the application's risk, scale, complexity, and operational requirements.&lt;/p&gt;

&lt;p&gt;The underlying principle remains the same: every production model should have a traceable development and deployment lifecycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. An African AI Trust Architecture in Practice
&lt;/h2&gt;

&lt;p&gt;Let's bring these concepts together with a practical scenario.&lt;/p&gt;

&lt;p&gt;Imagine a fintech company developing an AI-powered transaction monitoring system for Nigerian customers.&lt;/p&gt;

&lt;p&gt;The goal is to identify potentially fraudulent transactions while reducing unnecessary interruptions to legitimate customers.&lt;/p&gt;

&lt;p&gt;A possible architecture would look like this:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Transaction ingestion
&lt;/h3&gt;

&lt;p&gt;Transactions enter through the payment processing infrastructure.&lt;/p&gt;

&lt;p&gt;The system validates the request, checks required fields, verifies data provenance, and ensures that the transaction is properly authenticated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Feature processing
&lt;/h3&gt;

&lt;p&gt;Relevant transaction characteristics are extracted.&lt;/p&gt;

&lt;p&gt;These may include transaction frequency, amount patterns, device information, historical behaviour, and other legitimately available indicators.&lt;/p&gt;

&lt;p&gt;Sensitive data is minimised and protected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: AI inference
&lt;/h3&gt;

&lt;p&gt;The feature set is passed to the fraud detection model.&lt;/p&gt;

&lt;p&gt;The model produces a risk score and relevant supporting indicators.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Decision orchestration
&lt;/h3&gt;

&lt;p&gt;A separate decision layer evaluates the model output against the organisation's approved policies.&lt;/p&gt;

&lt;p&gt;Depending on the risk category, the transaction may proceed, undergo additional verification, or be escalated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Human review
&lt;/h3&gt;

&lt;p&gt;Selected cases enter a review queue where authorised fraud analysts can investigate and record their decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Audit logging
&lt;/h3&gt;

&lt;p&gt;Relevant model versions, decision metadata, and review outcomes are recorded securely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Continuous monitoring
&lt;/h3&gt;

&lt;p&gt;The system monitors transaction patterns, model behaviour, false positives, false negatives, latency, and operational incidents.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 8: Controlled improvement
&lt;/h3&gt;

&lt;p&gt;New data and verified outcomes are used to evaluate whether the model requires updates.&lt;/p&gt;

&lt;p&gt;Every new version passes through the appropriate testing and approval process before deployment.&lt;/p&gt;

&lt;p&gt;This architecture creates something more valuable than an isolated prediction endpoint.&lt;/p&gt;

&lt;p&gt;It creates a system with defined responsibilities, observable behaviour, and mechanisms for managing uncertainty.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Trust Should Be Measurable
&lt;/h2&gt;

&lt;p&gt;One final principle deserves attention.&lt;/p&gt;

&lt;p&gt;If trust is an engineering requirement, we should be able to measure the mechanisms that support it.&lt;/p&gt;

&lt;p&gt;Rather than relying on vague statements such as "our AI is reliable" or "our model is responsible," teams should define measurable operational indicators.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Example measurement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reliability&lt;/td&gt;
&lt;td&gt;Service availability and failure rate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Precision, recall, and task-specific metrics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Calibration&lt;/td&gt;
&lt;td&gt;Alignment between confidence and observed correctness&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data quality&lt;/td&gt;
&lt;td&gt;Missing-value and validation failure rates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fairness&lt;/td&gt;
&lt;td&gt;Performance differences across relevant groups&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Accountability&lt;/td&gt;
&lt;td&gt;Percentage of consequential decisions with traceable records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Human oversight&lt;/td&gt;
&lt;td&gt;Review completion and escalation rates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security&lt;/td&gt;
&lt;td&gt;Unresolved vulnerabilities and access violations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Operational resilience&lt;/td&gt;
&lt;td&gt;Recovery time and successful rollback capability&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These indicators should be defined according to the actual application.&lt;/p&gt;

&lt;p&gt;For example, an AI-powered educational recommendation engine and an AI-assisted medical diagnostic system should not be evaluated using identical acceptance criteria.&lt;/p&gt;

&lt;p&gt;Risk determines the level of assurance required.&lt;/p&gt;

&lt;p&gt;A useful way to think about this is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The higher the potential impact of an AI decision, the stronger the evidence, oversight, and controls required before deployment.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: We Need to Engineer Confidence, Not Just Intelligence
&lt;/h2&gt;

&lt;p&gt;The future of AI in Africa will not be determined solely by the sophistication of the models we build.&lt;/p&gt;

&lt;p&gt;It will also depend on our ability to turn those models into dependable systems.&lt;/p&gt;

&lt;p&gt;We need AI products that can operate in environments with imperfect data, changing conditions, diverse users, and varying infrastructure capabilities.&lt;/p&gt;

&lt;p&gt;We need systems that acknowledge uncertainty, protect user information, support human intervention, provide traceable decisions, and remain observable throughout their lifecycle.&lt;/p&gt;

&lt;p&gt;Most importantly, we need engineering teams that understand that deployment is not the final stage of AI development.&lt;/p&gt;

&lt;p&gt;It is where the real responsibility begins.&lt;/p&gt;

&lt;p&gt;The transition from prototype to production requires more than a successful inference endpoint. It requires an architecture that makes reliability demonstrable, accountability enforceable, and trust continuously measurable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We should stop asking only whether an AI model works. We should start asking whether the entire system is worthy of being trusted.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because the next generation of successful African AI products will not simply be the products with the most impressive demonstrations.&lt;/p&gt;

&lt;p&gt;They will be the ones people can confidently depend on.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>machinelearning</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Trust Is the Deployment Obstacle: Why African AI Projects Stall After the Demo</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Thu, 19 Nov 2026 00:38:03 +0000</pubDate>
      <link>https://dev.to/shieldstring/trust-is-the-deployment-obstacle-why-african-ai-projects-stall-after-the-demo-5hh</link>
      <guid>https://dev.to/shieldstring/trust-is-the-deployment-obstacle-why-african-ai-projects-stall-after-the-demo-5hh</guid>
      <description>&lt;p&gt;&lt;em&gt;The demo went well. The room was impressed. Then nothing shipped.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There is a familiar story playing out across Africa's technology ecosystem.&lt;/p&gt;

&lt;p&gt;A team builds an AI-powered solution. The prototype works. The model produces impressive results. Stakeholders gather for a demonstration, and everyone is excited about what the technology could accomplish.&lt;/p&gt;

&lt;p&gt;There are smiles, applause, questions about scalability, and conversations about the possibilities.&lt;/p&gt;

&lt;p&gt;Then the project goes quiet.&lt;/p&gt;

&lt;p&gt;Weeks become months. The promised pilot never happens. The product remains in a presentation deck, a GitHub repository, or a demonstration environment.&lt;/p&gt;

&lt;p&gt;What happened?&lt;/p&gt;

&lt;p&gt;The immediate assumption is often that the model needs improvement. Perhaps it requires more training data, a better architecture, additional fine-tuning, or a more sophisticated machine learning pipeline.&lt;/p&gt;

&lt;p&gt;Sometimes that is true.&lt;/p&gt;

&lt;p&gt;But increasingly, the problem is not the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem is trust.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Across African markets, many AI initiatives face a difficult transition from proof of concept to production. The technology may be functional, but the people expected to depend on it are not yet convinced that it is reliable, safe, explainable, and accountable enough to operate in real-world environments.&lt;/p&gt;

&lt;p&gt;And until that confidence exists, even an impressive AI system can remain permanently stuck at the demo stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Demo Is Not the Product
&lt;/h2&gt;

&lt;p&gt;A successful demonstration proves that something can work under controlled conditions.&lt;/p&gt;

&lt;p&gt;Production proves that it can continue working when conditions are unpredictable.&lt;/p&gt;

&lt;p&gt;These are two very different engineering challenges.&lt;/p&gt;

&lt;p&gt;During a demonstration, developers control the environment. They know the expected inputs, understand the dataset, anticipate potential failures, and can intervene when something goes wrong.&lt;/p&gt;

&lt;p&gt;Production environments are less forgiving.&lt;/p&gt;

&lt;p&gt;Consider an AI-powered credit assessment system designed for a Nigerian fintech company.&lt;/p&gt;

&lt;p&gt;During development, the model might achieve impressive performance using historical transaction records. It may identify patterns, estimate creditworthiness, and generate recommendations within milliseconds.&lt;/p&gt;

&lt;p&gt;But before a financial institution allows that system to influence actual lending decisions, several questions emerge:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What happens when the model incorrectly rejects a qualified applicant?&lt;/li&gt;
&lt;li&gt;Can the institution explain why a customer received a particular decision?&lt;/li&gt;
&lt;li&gt;Does the training data adequately represent people with irregular income?&lt;/li&gt;
&lt;li&gt;How does the system handle incomplete or inconsistent financial records?&lt;/li&gt;
&lt;li&gt;Who takes responsibility when an automated recommendation causes financial harm?&lt;/li&gt;
&lt;li&gt;Can the institution demonstrate that the system does not systematically disadvantage certain customer groups?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions cannot be answered by model accuracy alone.&lt;/p&gt;

&lt;p&gt;A model achieving 95% accuracy does not automatically become a trustworthy financial product.&lt;/p&gt;

&lt;p&gt;The remaining 5% represents real people, real money, and potentially serious consequences.&lt;/p&gt;

&lt;p&gt;The difference between a successful AI demonstration and a production-ready AI system is the ability to answer these questions convincingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Trust Is a Technical Requirement, Not Just a Business Requirement
&lt;/h2&gt;

&lt;p&gt;One mistake technology teams make is treating trust as something to address after development.&lt;/p&gt;

&lt;p&gt;The engineering team builds the model, integrates the APIs, develops the interface, and prepares the deployment pipeline. Only when stakeholders raise concerns do conversations about security, privacy, accountability, and explainability begin.&lt;/p&gt;

&lt;p&gt;By then, addressing those concerns can require significant architectural changes.&lt;/p&gt;

&lt;p&gt;Trust should be part of the system's design from the beginning.&lt;/p&gt;

&lt;p&gt;A production-ready AI system needs more than an inference endpoint. It needs mechanisms that allow people to understand, monitor, challenge, and control its behaviour.&lt;/p&gt;

&lt;p&gt;Some of these mechanisms include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explainability:&lt;/strong&gt; Can stakeholders understand the factors influencing an AI-generated recommendation?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; Does the system produce consistent results across different conditions, datasets, and user populations?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Observability:&lt;/strong&gt; Can engineers identify model drift, unexpected outputs, latency issues, and failures?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security and privacy:&lt;/strong&gt; Are sensitive datasets protected throughout collection, processing, storage, and transmission?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Accountability:&lt;/strong&gt; Is there a clearly defined process for reviewing decisions and handling incidents?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Human oversight:&lt;/strong&gt; Can a qualified person intervene when the system encounters uncertain or high-impact situations?&lt;/p&gt;

&lt;p&gt;These are not optional enterprise features.&lt;/p&gt;

&lt;p&gt;They are engineering requirements for systems that interact with real people and real institutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Africa's Data Reality Makes Trust More Difficult
&lt;/h2&gt;

&lt;p&gt;AI systems are only as dependable as the data and environments in which they operate.&lt;/p&gt;

&lt;p&gt;However, building AI products for African markets introduces data challenges that are not always adequately represented in standard development environments.&lt;/p&gt;

&lt;p&gt;Consider some practical realities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Financial records may be fragmented across multiple institutions and platforms.&lt;/li&gt;
&lt;li&gt;Many small businesses operate with limited formal documentation.&lt;/li&gt;
&lt;li&gt;Speech recognition systems may struggle with local accents, code-switching, and multilingual conversations.&lt;/li&gt;
&lt;li&gt;Agricultural datasets may be inconsistent across geographical regions and growing seasons.&lt;/li&gt;
&lt;li&gt;Healthcare records may exist in disconnected digital and physical systems.&lt;/li&gt;
&lt;li&gt;Internet connectivity, device capabilities, and infrastructure quality can vary significantly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An AI model trained primarily on clean, structured datasets from another geographical context may perform impressively in a controlled environment but struggle when exposed to actual users.&lt;/p&gt;

&lt;p&gt;Imagine deploying a voice-based AI assistant in Nigeria.&lt;/p&gt;

&lt;p&gt;A system might perform well when tested with standard English pronunciation but struggle when users communicate using Nigerian English, Pidgin, Igbo, Yoruba, Hausa, or a mixture of languages.&lt;/p&gt;

&lt;p&gt;The issue is not necessarily that the model is fundamentally incapable.&lt;/p&gt;

&lt;p&gt;The issue is that its developers may not have adequately tested the conditions under which people will use it.&lt;/p&gt;

&lt;p&gt;This creates a trust problem.&lt;/p&gt;

&lt;p&gt;When users repeatedly experience inaccurate responses, they stop relying on the system. When businesses notice inconsistent outputs, they hesitate to integrate it into their operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local context is not merely a feature of African AI products. It is part of their reliability requirements.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Stakeholders Need Evidence, Not Just Impressive Outputs
&lt;/h2&gt;

&lt;p&gt;Another reason AI projects stall is the gap between what engineers demonstrate and what decision-makers need to evaluate.&lt;/p&gt;

&lt;p&gt;An engineering team might present:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model accuracy.&lt;/li&gt;
&lt;li&gt;Precision and recall.&lt;/li&gt;
&lt;li&gt;Inference latency.&lt;/li&gt;
&lt;li&gt;Training loss.&lt;/li&gt;
&lt;li&gt;API response times.&lt;/li&gt;
&lt;li&gt;Benchmark comparisons.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These metrics are important, but they do not necessarily answer the questions that determine whether an organisation is willing to deploy the system.&lt;/p&gt;

&lt;p&gt;A bank wants to understand financial and reputational risk.&lt;/p&gt;

&lt;p&gt;A hospital wants to know whether the system can safely support clinical workflows.&lt;/p&gt;

&lt;p&gt;A government institution wants to understand accountability, data protection, and operational consequences.&lt;/p&gt;

&lt;p&gt;A customer wants to know whether their information is safe and whether they can challenge an incorrect outcome.&lt;/p&gt;

&lt;p&gt;Different stakeholders require different forms of evidence.&lt;/p&gt;

&lt;p&gt;This means AI teams must learn to translate technical performance into operational confidence.&lt;/p&gt;

&lt;p&gt;For example, instead of simply reporting:&lt;/p&gt;

&lt;p&gt;"Our model achieves 94% accuracy."&lt;/p&gt;

&lt;p&gt;A more useful production evaluation might explain:&lt;/p&gt;

&lt;p&gt;"Our model achieves 94% accuracy on the evaluated dataset, with performance measured separately across relevant user groups. Predictions below a defined confidence threshold are flagged for human review. Model decisions are logged, and performance is monitored for changes after deployment."&lt;/p&gt;

&lt;p&gt;The second statement communicates more than performance.&lt;/p&gt;

&lt;p&gt;It communicates how the system behaves, where its limitations exist, and what happens when it is uncertain.&lt;/p&gt;

&lt;p&gt;That is the kind of evidence stakeholders need.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Explainability and Human Oversight Cannot Be Afterthoughts
&lt;/h2&gt;

&lt;p&gt;AI systems increasingly influence decisions that affect people's lives.&lt;/p&gt;

&lt;p&gt;Yet, many implementations still treat model outputs as unquestionable answers.&lt;/p&gt;

&lt;p&gt;This is dangerous.&lt;/p&gt;

&lt;p&gt;A model can produce a prediction without understanding the broader consequences of that prediction.&lt;/p&gt;

&lt;p&gt;For example, an AI-powered recruitment platform may rank candidates based on historical hiring data. If that historical data contains bias, the model may reproduce and reinforce it.&lt;/p&gt;

&lt;p&gt;A healthcare assistant may generate a plausible recommendation based on incomplete patient information.&lt;/p&gt;

&lt;p&gt;A fraud detection model may flag legitimate transactions because a customer's behaviour differs from the patterns represented in its training data.&lt;/p&gt;

&lt;p&gt;In each case, the system needs a mechanism for handling uncertainty.&lt;/p&gt;

&lt;p&gt;This is where human-in-the-loop architecture becomes important.&lt;/p&gt;

&lt;p&gt;Rather than allowing every model output to trigger an irreversible action, systems can introduce decision boundaries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High-confidence, low-risk outputs can proceed automatically where appropriate.&lt;/li&gt;
&lt;li&gt;Medium-confidence outputs can trigger additional verification.&lt;/li&gt;
&lt;li&gt;Low-confidence or high-impact decisions can be escalated for human review.&lt;/li&gt;
&lt;li&gt;Users should have appropriate channels to challenge or correct consequential decisions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is not to remove automation.&lt;/p&gt;

&lt;p&gt;It is to design automation that recognises its limitations.&lt;/p&gt;

&lt;p&gt;A trustworthy AI system should know when it needs human intervention.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Production Readiness Requires More Than Deploying a Model
&lt;/h2&gt;

&lt;p&gt;There is a tendency to think of AI deployment as a relatively straightforward process:&lt;/p&gt;

&lt;p&gt;Train model → Export model → Build API → Deploy to cloud → Connect frontend.&lt;/p&gt;

&lt;p&gt;That workflow may be sufficient for a prototype.&lt;/p&gt;

&lt;p&gt;It is not a complete production strategy.&lt;/p&gt;

&lt;p&gt;Production AI requires an operational infrastructure that supports continuous evaluation, monitoring, security, and accountability.&lt;/p&gt;

&lt;p&gt;Some critical components include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data validation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Check incoming data for missing values, unexpected formats, distribution changes, and inconsistencies before it reaches the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model versioning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Track model versions, datasets, training configurations, evaluation results, and deployment history. Teams should be able to identify which model generated a particular prediction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitoring and observability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Monitor latency, error rates, prediction distributions, model drift, and system availability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fallback mechanisms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Define what happens when the model becomes unavailable, produces unreliable outputs, or encounters an unfamiliar input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Audit logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Maintain appropriate records of model outputs, relevant inputs, system versions, and human interventions while respecting data protection requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security controls&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Protect model endpoints, datasets, credentials, infrastructure, and user information against unauthorised access and manipulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Incident response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Establish processes for investigating harmful outputs, disabling problematic functionality, rolling back models, and communicating incidents.&lt;/p&gt;

&lt;p&gt;These practices are often associated with MLOps, but their importance goes beyond operational convenience.&lt;/p&gt;

&lt;p&gt;They create the evidence and control mechanisms required to establish confidence in an AI system.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Trust Must Be Built Across an Entire Ecosystem
&lt;/h2&gt;

&lt;p&gt;AI trust is not something an engineering team can establish independently.&lt;/p&gt;

&lt;p&gt;It involves multiple stakeholders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developers and engineers&lt;/strong&gt; must build systems that are secure, testable, observable, and maintainable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Businesses and product teams&lt;/strong&gt; must communicate the system's purpose, limitations, and expected outcomes honestly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regulators and policymakers&lt;/strong&gt; must establish clear expectations around data protection, accountability, and responsible AI deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customers and end users&lt;/strong&gt; must understand how AI affects their interactions, what information is being collected, and what options are available when something goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Investors and institutional partners&lt;/strong&gt; need evidence that the technology can operate sustainably and manage its risks.&lt;/p&gt;

&lt;p&gt;This is particularly important in African markets, where AI adoption is developing alongside existing challenges involving digital infrastructure, institutional capacity, data governance, and public confidence.&lt;/p&gt;

&lt;p&gt;Trust cannot be established through marketing campaigns or impressive presentations.&lt;/p&gt;

&lt;p&gt;It must emerge from the actual behaviour of the system and the institutions responsible for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. How We Can Move African AI Projects Beyond the Demo
&lt;/h2&gt;

&lt;p&gt;If trust is the obstacle, then the solution is not simply to build larger models or chase better benchmarks.&lt;/p&gt;

&lt;p&gt;We need to change how AI projects are designed, evaluated, and deployed.&lt;/p&gt;

&lt;p&gt;Here are seven practical recommendations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Design for the actual deployment environment.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Test with representative local datasets, real user behaviour, different devices, network conditions, languages, and operational constraints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Establish trust requirements before development begins.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Identify what customers, regulators, business owners, and end users need to see before they will rely on the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Make model limitations visible.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Document what the system can do, what it cannot do, where it performs poorly, and when human intervention is necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Build monitoring into the architecture.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do not wait until customers report problems before discovering that a model's performance has degraded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Introduce controlled pilot deployments.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start with limited use cases, measurable success criteria, and clearly defined human oversight before expanding to broader operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Make accountability part of the product.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Define who owns the system, who reviews consequential decisions, how incidents are handled, and how users can raise concerns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Treat trust as something that must be continuously earned.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A successful launch does not guarantee long-term reliability. Monitor the system, evaluate its performance, collect feedback, and improve it as conditions change.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Competitive Advantage May Not Be the Model
&lt;/h2&gt;

&lt;p&gt;Africa does not lack talented AI engineers, ambitious founders, research initiatives, or promising ideas.&lt;/p&gt;

&lt;p&gt;There is significant potential for AI to improve financial services, healthcare, agriculture, education, logistics, manufacturing, and public infrastructure across the continent.&lt;/p&gt;

&lt;p&gt;But potential is not the same as impact.&lt;/p&gt;

&lt;p&gt;We need to move beyond celebrating the number of AI prototypes we build and start paying closer attention to the number of systems that successfully become part of everyday operations.&lt;/p&gt;

&lt;p&gt;An impressive demo can attract attention.&lt;/p&gt;

&lt;p&gt;A reliable system earns adoption.&lt;/p&gt;

&lt;p&gt;A transparent system earns confidence.&lt;/p&gt;

&lt;p&gt;An accountable system earns long-term institutional trust.&lt;/p&gt;

&lt;p&gt;The next phase of African AI development will not be determined solely by who builds the most sophisticated models. It will also depend on who can engineer systems that people and institutions are willing to trust.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The question is no longer just whether we can build AI that works.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is whether we can build AI that people can confidently depend on.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And perhaps that is the deployment challenge we should be solving next.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What do you think is the biggest obstacle preventing AI projects in Africa from moving beyond the proof-of-concept stage: data quality, infrastructure, regulation, funding, or trust?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experiences in the comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>software</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Next Phase of Vision-Language Navigation</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Fri, 04 Sep 2026 16:43:04 +0000</pubDate>
      <link>https://dev.to/shieldstring/the-next-phase-of-vision-language-navigation-5egk</link>
      <guid>https://dev.to/shieldstring/the-next-phase-of-vision-language-navigation-5egk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; Vision-Language Navigation has moved well past indoor discrete step benchmarks. The next phase is defined by self-evolving agents, long-horizon multi-stage planning, aerial and outdoor deployment, zero-shot generalization, and the convergence of VLN with Vision-Language-Action models. This article maps those shifts in detail — and explains why each of them matters.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Where VLN Started — and Why That Baseline No Longer Holds
&lt;/h2&gt;

&lt;p&gt;Vision-Language Navigation was formalized as a research challenge around 2018 with the R2R benchmark: given a natural language instruction and a panoramic first-person view, navigate to the described destination inside a photorealistic indoor environment.&lt;/p&gt;

&lt;p&gt;The setting was deliberately constrained. Agents moved along discrete graph nodes, environments were static, instruction lengths were manageable, and success was measured by a single clean terminus. Those constraints were valuable — they made the problem tractable enough to study rigorously. They also produced a deceptively narrow definition of what navigation with language really needs to be.&lt;/p&gt;

&lt;p&gt;By 2025 and into 2026, the field has largely exhaused what clean indoor discrete-action benchmarks can teach us. The interesting research is now happening at the edges: longer task horizons, open-world outdoor environments, aerial platforms, agents that learn continuously, and architectures where navigation is no longer a standalone skill but a component of a broader action-capable system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 1 — Self-Evolving Agents
&lt;/h2&gt;

&lt;p&gt;One of the cleanest limitations of previous VLN systems was their static knowledge base. After training, the agent's internal model of the world was fixed. It could not update from deployment experience, and it could not integrate knowledge from successful or failed episodes into future decisions.&lt;/p&gt;

&lt;p&gt;Research presented at ICLR 2026 introduced SE-VLN, a self-evolving vision-language navigation framework that addresses this directly. SE-VLN is built on a multimodal large language model backbone and adds three core modules: a hierarchical memory system that converts successful and failed navigation episodes into reusable structured knowledge, a retrieval-augmented reasoning module that queries that memory during live navigation, and a reflection module that updates the agent's behavior based on post-episode analysis.&lt;/p&gt;

&lt;p&gt;The reported results are significant. SE-VLN achieved navigation success rates of 57% and 35.2% in unseen environments on the R2R and REVERIE benchmarks respectively, representing relative improvements of 23.9% and 15% over prior state-of-the-art. Critically, performance improved as the experience repository grew, demonstrating genuine continual learning behavior rather than just stronger initialization.&lt;/p&gt;

&lt;p&gt;The implication for practitioners is important: the model's usefulness compounds over deployment time. That is a fundamentally different capability profile than a system that decays or plateaus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 2 — Long-Horizon Multi-Stage Navigation
&lt;/h2&gt;

&lt;p&gt;Standard VLN benchmarks were built around single-stage tasks. Navigate from point A to point B. The implicit assumption was that the navigation episode was a single coherent unit of behavior.&lt;/p&gt;

&lt;p&gt;Real-world navigation tasks rarely look like that. A hospital delivery robot may need to collect a sample from one floor, confirm patient identity at another, and deliver to a lab in a third wing — all within a single natural language instruction sequence. A household assistant asked to "clean up and then start a load of laundry" needs to execute multiple sequenced subtasks with state tracking and conditional branching.&lt;/p&gt;

&lt;p&gt;CVPR 2025 addressed this directly with the introduction of Long-Horizon Vision-Language Navigation (LH-VLN), a new task definition accompanied by the NavGen data generation platform and the LHPR-VLN benchmark. LHPR-VLN consists of 3,260 tasks with an average of 150 task steps — an order of magnitude more complex than standard benchmarks. To evaluate these tasks meaningfully, the authors introduced three new metrics: Independent Success Rate, Conditional Success Rate, and CSR weighted by Ground Truth, to capture partial completion performance that binary success/failure metrics cannot express.&lt;/p&gt;

&lt;p&gt;The accompanying method, Multi-Granularity Dynamic Memory (MGDM), integrates short-term memory blurring with long-term memory retrieval to enable flexible navigation in dynamic, multi-stage environments.&lt;/p&gt;

&lt;p&gt;The benchmark framing itself matters as much as the method. By formally defining LH-VLN and providing the evaluation infrastructure, this work established a new standard for what navigation complexity should look like in research.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 3 — Cognitive Maps and Spatial Memory
&lt;/h2&gt;

&lt;p&gt;Most VLN systems process navigation as a reactive sequence: observe, attend to instruction, predict the next action, step, repeat. This works acceptably for short, well-described paths in compact environments. It breaks down badly at scale.&lt;/p&gt;

&lt;p&gt;In large-scale environments — outdoor city blocks, multi-building campuses, sprawling factory floors — the reactive paradigm is insufficient because the agent has no persistent spatial representation to reason over. It cannot connect what it sees now to where it has been, what structure the environment has, or which direction to commit to when landmarks are ambiguous.&lt;/p&gt;

&lt;p&gt;CogVLN, presented at ICLR 2026, addresses this by constructing a &lt;strong&gt;cognitive map&lt;/strong&gt; before and during navigation. Inspired by how humans mentally encode environments, CogVLN prioritizes encoding of key scenes that carry high environmental distinctiveness, while allocating fewer encoding resources to visually redundant areas. Built on a multimodal large language model, the system uses the cognitive map to drive three modules: a localization module that identifies start and goal vertices, a path planning module that generates traversal routes, and a navigation module that executes those routes while handling user feedback interactively.&lt;/p&gt;

&lt;p&gt;Validation in the CARLA Town01 and Town07 environments — large-scale driving simulation — demonstrated strong generalization performance. The outdoor setting is notable: most prior VLN research was validated in indoor room-scale environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 4 — Outdoor and Urban-Scale Deployment
&lt;/h2&gt;

&lt;p&gt;The expansion from indoor to outdoor environments is not just a dataset change. It represents a qualitative shift in the problem structure.&lt;/p&gt;

&lt;p&gt;Indoor VLN benefits from clearly bounded spaces, structured landmark vocabulary, predictable lighting, and a manageable graph of traversable waypoints. Outdoor navigation introduces GPS ambiguity at fine scales, variable occlusion from moving vehicles and pedestrians, weather-dependent visual appearance, landmark impermanence, and action spaces that include continuous speed and heading rather than discrete graph steps.&lt;/p&gt;

&lt;p&gt;Recent research in 2025 and 2026 has pushed into this territory explicitly. Vision-language models applied to mobile robot navigation in unstructured manufacturing environments demonstrated a VLM-based architecture integrating 3D scene reconstruction, semantic segmentation via LSeg, and LLM-driven spatial goal navigation — achieving a 92.5% average success rate across different navigation subgoal configurations in simulation, with real-world deployment on a TIAGo++ platform.&lt;/p&gt;

&lt;p&gt;The larger research direction involves grounding natural language not in 3D room graphs but in semantic maps built from real sensor data, with online updates as the environment changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 5 — Aerial Vision-Language Navigation
&lt;/h2&gt;

&lt;p&gt;Ground-based navigation has dominated VLN research since the field's inception. UAV-based VLN presents a distinctly harder problem and has remained underexplored until recently.&lt;/p&gt;

&lt;p&gt;The core challenges are not simply a rescaling of the ground problem. Aerial agents operate in a continuous 6-DOF action space rather than ground-plane discrete steps. The visual perspective is fundamentally different — top-down, oblique, and shifting with altitude. The dynamic range of environments navigable by a UAV is vastly larger than any indoor graph. And the safety implications of navigation failure are different: a UAV that misidentifies a waypoint does not just stop at the wrong room — it may exit controlled airspace or lose signal.&lt;/p&gt;

&lt;p&gt;Research published in 2025 and 2026 has begun building the infrastructure needed to study this problem properly. The OpenUAV platform provides diverse environments, realistic flight control physics, and algorithm support specifically designed for VLN tasks. The UAV-Need-Help benchmark introduces approximately 12,000 trajectories with varying levels of assistant guidance, providing a tiered evaluation framework that distinguishes between agents that can navigate with full instruction sets and those that require interactive clarification.&lt;/p&gt;

&lt;p&gt;OpenVLN extended this further with an open-world aerial VLN framework targeting general outdoor environments. The research consistently identifies a significant gap between current model performance and human operator performance — marking UAV-VLN as one of the most open and tractable research frontiers in the field.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 6 — Zero-Shot Generalization with Multimodal LLMs
&lt;/h2&gt;

&lt;p&gt;A persistent frustration in VLN has been the brittleness of trained agents to distribution shift. A model trained on R2R instructions performs well on R2R-style paths but degrades sharply when instruction phrasing, environment style, or object vocabulary shifts. Supervised models overfit to benchmark conventions rather than developing genuine spatial and linguistic reasoning.&lt;/p&gt;

&lt;p&gt;The emergence of strong multimodal large language models has reframed this challenge. Rather than training a navigation-specific policy from scratch, the new paradigm leverages the broad visual and linguistic knowledge already encoded in a foundation model.&lt;/p&gt;

&lt;p&gt;UniGoal, presented at CVPR 2025, proposed a universal zero-shot goal-oriented navigation framework that unifies object category, instance image, and text description goals into a single graph representation. An online scene graph tracks the agent's environmental observations, and an LLM performs explicit graph-based reasoning to match scene state against goal state. UniGoal achieved state-of-the-art zero-shot performance across three navigation tasks with a single model, outperforming task-specific zero-shot methods.&lt;/p&gt;

&lt;p&gt;NavBench, published in mid-2025, evaluated this zero-shot navigation paradigm more systematically. Across 3,200 question-answer pairs and 432 full episodes in 72 indoor scenes, the benchmark tested comprehension across global instruction alignment, temporal progress estimation, and local observation-action reasoning. GPT-4o performed strongest, while lighter open-source models succeeded in simpler scenarios. The consistent finding was that models with higher navigation comprehension scores achieved better execution outcomes — confirming that language understanding quality and navigation quality are coupled, not independent.&lt;/p&gt;

&lt;p&gt;The persistent weak point across models was temporal understanding: estimating progress through a navigation episode. This is a significant gap because long-horizon tasks require the agent to know not just where it is but how far into the instruction sequence it has advanced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift 7 — The Convergence of VLN and VLA
&lt;/h2&gt;

&lt;p&gt;The most structurally significant shift in the field is arguably the convergence of Vision-Language Navigation with Vision-Language-Action models.&lt;/p&gt;

&lt;p&gt;Classic VLN treated navigation as an isolated capability: perceive, ground instruction, move. The output was a trajectory — a sequence of waypoints or steps. The gap between that output and genuine embodied task completion was never addressed in the VLN framing.&lt;/p&gt;

&lt;p&gt;VLA models dissolve that separation. Architectures in the RT-2, OpenVLA, and ChatVLA-2 lineage extend the VLM paradigm all the way to physical action tokens, mapping visual observations and natural language instructions directly to motor commands. Navigation becomes one component of a unified perception-language-action loop rather than a separate planning problem that upstream some physical controller.&lt;/p&gt;

&lt;p&gt;ChatVLA-2, presented at NeurIPS 2025, introduced a mixture-of-expert VLA architecture with a three-stage training pipeline designed to preserve the VLM's core reasoning capabilities during robotic fine-tuning. The system demonstrated that mathematical reasoning and spatial intelligence acquired during VLM pretraining transferred into navigation and manipulation tasks without explicit retraining — a result with significant implications for generalization.&lt;/p&gt;

&lt;p&gt;Figure AI's Helix VLA model extended this to full humanoid upper-body control: arms, hands, torso, and fingers controlled through the same VLA framework that processes natural language task descriptions. The gap between "navigate to the kitchen" and "navigate to the kitchen and put the cup in the dishwasher" is shrinking.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Open Problems
&lt;/h2&gt;

&lt;p&gt;Despite the pace of progress, several fundamental challenges remain unsolved and are worth naming clearly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporal understanding.&lt;/strong&gt; As NavBench demonstrated, current multimodal LLMs struggle to estimate navigation progress through a long instruction sequence. This is a prerequisite for reliable long-horizon task execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Efficient edge deployment.&lt;/strong&gt; VLA models powerful enough to handle open-world navigation carry large memory and compute footprints. Deploying them on embedded hardware — the compute available on a mobile robot or UAV — requires architectural innovations in model compression, token efficiency, and real-time inference optimization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continual learning without forgetting.&lt;/strong&gt; SE-VLN showed that experience-based evolution is possible, but the broader challenge of learning new environments and tasks without catastrophic forgetting of previously learned capabilities remains open.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sim-to-real for diverse embodiments.&lt;/strong&gt; Domain randomization improves transfer, but the visual and physical gap between simulation and the real world remains significant for outdoor environments, aerial platforms, and novel object categories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Safety and failure semantics.&lt;/strong&gt; As VLN agents move from indoor benchmarks to real deployments — hospitals, warehouses, public spaces — the definition of safe failure behavior needs to be formalized. An agent that is uncertain should know what to ask, when to stop, and how to communicate its state.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the Next Phase Looks Like
&lt;/h2&gt;

&lt;p&gt;The research trajectory is now reasonably clear. VLN in its next phase will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Operate continuously in open-world environments, updating spatial and semantic memory from live experience&lt;/li&gt;
&lt;li&gt;Handle multi-stage, multi-subtask instruction sequences with hundreds of steps&lt;/li&gt;
&lt;li&gt;Extend across aerial, ground, and mobile manipulation platforms within unified model architectures&lt;/li&gt;
&lt;li&gt;Generalize zero-shot to novel environments, object classes, and instruction styles using foundation model priors&lt;/li&gt;
&lt;li&gt;Converge with the broader VLA paradigm, where navigation is not a separate module but an integrated capability within an action-capable embodied agent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benchmark infrastructure is being built now. The architectural foundations — multimodal LLMs, cognitive maps, self-evolving memory, long-horizon planning — are either available or within reach. The primary constraint shifting from research to deployment is the same one it always is: the gap between what works in simulation and what works in the real world, at scale, reliably, across the full distribution of environments an agent will encounter.&lt;/p&gt;

&lt;p&gt;That gap is the next three years of work in this field.&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>ai</category>
      <category>machinelearning</category>
      <category>robotics</category>
    </item>
    <item>
      <title>New post: Programmable Wallets for the Agentic Internet 💳🤖

Covers how x402 revives HTTP 402 for machine-to-machine stablecoin payments, the three-actor model (Client/Resource Server/Facilitator), what makes a wallet "agentic" vs. just a crypto wallet wi</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Wed, 02 Sep 2026 13:19:11 +0000</pubDate>
      <link>https://dev.to/shieldstring/new-post-programmable-wallets-for-the-agentic-internet-covers-how-x402-revives-http-402-for-35m</link>
      <guid>https://dev.to/shieldstring/new-post-programmable-wallets-for-the-agentic-internet-covers-how-x402-revives-http-402-for-35m</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5" class="crayons-story__hidden-navigation-link"&gt;Programmable Wallets for the Agentic Internet&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/shieldstring" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F261529%2F89766ddd-e5eb-4837-9d17-eacb12a93b0c.jpg" alt="shieldstring profile" class="crayons-avatar__image" width="800" height="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/shieldstring" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Agbo, Daniel Onuoha 
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Agbo, Daniel Onuoha 
                
                
              
              &lt;div id="story-author-preview-content-4501790" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/shieldstring" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F261529%2F89766ddd-e5eb-4837-9d17-eacb12a93b0c.jpg" class="crayons-avatar__image" alt="" width="800" height="800"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Agbo, Daniel Onuoha &lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 30&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5" id="article-link-4501790"&gt;
          Programmable Wallets for the Agentic Internet
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/blockchain"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;blockchain&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/automation"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;automation&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt;&amp;nbsp;reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
          
          &lt;div class="only-sidebar-menu-item trusted-visible-block print-hidden align-center"&gt;
                
                    
                
          &lt;/div&gt;

        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;/div&gt;


</description>
      <category>agents</category>
      <category>ai</category>
      <category>crypto</category>
      <category>web3</category>
    </item>
    <item>
      <title>Programmable Wallets for the Agentic Internet</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Sun, 30 Aug 2026 05:00:00 +0000</pubDate>
      <link>https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5</link>
      <guid>https://dev.to/shieldstring/programmable-wallets-for-the-agentic-internet-4h5</guid>
      <description>&lt;p&gt;Agents are coming online at a scale that makes human-in-the-loop payments impractical, and the industry's answer has converged on an unlikely source: a dormant HTTP status code from the 1990s. The x402 protocol revives HTTP 402 "Payment Required" to let AI agents pay for APIs, data, and services directly in stablecoins, with no accounts, API keys, or checkout pages — and as of July 2026, agent-driven traffic is already overtaking human traffic on some of its earliest adopting platforms. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Agents Need Wallets, Not Accounts
&lt;/h2&gt;

&lt;p&gt;Every payment system built for the human web assumes a person is present to log in, enter card details, or approve an OAuth prompt. An autonomous agent completing a task — sourcing a freight quote, pulling a paid dataset, calling a monetized API a hundred times in sequence — can't pause for a human to approve each of those actions without defeating the purpose of automation. What agents need instead is a wallet: a programmable store of funds governed by rules set in advance, so the agent can spend within defined limits without asking permission for every transaction. &lt;/p&gt;

&lt;p&gt;This is the shift x402 was built to enable — machine-to-machine payments that happen inline, within the same HTTP request cycle that fetches the resource, rather than through a separate billing relationship set up by a human beforehand. &lt;/p&gt;

&lt;h2&gt;
  
  
  How x402 Actually Works
&lt;/h2&gt;

&lt;p&gt;x402 uses a three-actor model: the &lt;strong&gt;Client&lt;/strong&gt; (the buyer — an AI agent, app, or script), the &lt;strong&gt;Resource Server&lt;/strong&gt; (the seller — an API or paid service), and the &lt;strong&gt;Facilitator&lt;/strong&gt; (a settlement service that verifies and broadcasts payments on-chain). The flow runs in a single retried request cycle, with no redirects, webhooks, or manual checkout involved: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Client makes a request.&lt;/strong&gt; A normal &lt;code&gt;GET&lt;/code&gt; or &lt;code&gt;POST&lt;/code&gt; to a paid endpoint — no auth headers, no API key. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server responds &lt;code&gt;402 Payment Required&lt;/code&gt;.&lt;/strong&gt; The response includes structured payment metadata: the price, accepted stablecoin (usually USDC), the destination address, and which blockchain network to use. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client signs a payment authorization.&lt;/strong&gt; The agent's wallet signs an off-chain authorization for the exact amount using EIP-3009 transfer authorizations on EVM chains — this step requires no gas fee from the client. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client retries the request&lt;/strong&gt; with the signed payment attached in a header (historically &lt;code&gt;X-PAYMENT&lt;/code&gt;, now standardizing toward &lt;code&gt;PAYMENT-SIGNATURE&lt;/code&gt; in x402 v2). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server verifies and settles.&lt;/strong&gt; The server checks the signature — either locally or by calling the facilitator's &lt;code&gt;/verify&lt;/code&gt; endpoint — then settles the payment on-chain directly or via the facilitator's &lt;code&gt;/settle&lt;/code&gt; endpoint. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server returns &lt;code&gt;200 OK&lt;/code&gt;&lt;/strong&gt; with the resource and a settlement confirmation header proving the transaction went through. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The elegance of this design is that it needed almost no new infrastructure — HTTP already reserved status code 402 for exactly this purpose decades ago; it simply never had a standard payment mechanism to pair with it until now. &lt;/p&gt;

&lt;h2&gt;
  
  
  What Makes a Wallet "Agentic"
&lt;/h2&gt;

&lt;p&gt;A programmable wallet built for this world looks structurally different from a personal crypto wallet. Rather than a human approving each transaction, the wallet enforces policy automatically: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Spending caps&lt;/strong&gt; — hard limits on how much the agent can spend per transaction, per hour, or per day&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allowed actions&lt;/strong&gt; — a whitelist of what the wallet can be used for (e.g., only data purchases, not arbitrary transfers)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Approved counterparties&lt;/strong&gt; — restricting payments to a known set of vetted services or domains&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Policy checks before execution&lt;/strong&gt; — every time the agent decides it needs to spend funds, the wallet checks the action against policy before signing anything, and only executes if it passes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the piece that makes autonomous spending safe enough to deploy: the agent has genuine spending authority, but only within boundaries a human or organization defined ahead of time — closer to a corporate purchasing card with programmable limits than a blank check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real Implementations Already Live
&lt;/h2&gt;

&lt;p&gt;This isn't theoretical. Coinbase's Agent Kit gives agents a skills library for wallet operations — sending, trading, earning — and integrates natively with x402 for agent-to-service payments, including gasless transactions on Base. Cloudflare has shipped x402 support directly into its Agents SDK, letting any Cloudflare Worker accept or make agent payments with a few lines of middleware. Coinbase opened x402 USDC payments to all Business customers on July 23, 2026, explicitly citing that agent traffic was already overtaking human traffic on its developer documentation. &lt;/p&gt;

&lt;p&gt;The protocol also works across multiple chains — Base, Ethereum, Arbitrum, Optimism, Polygon, and Solana are all supported, which matters because it means an agent's wallet isn't locked into one ecosystem's liquidity or fee structure. &lt;/p&gt;

&lt;h2&gt;
  
  
  x402 vs. the Other Agent Payment Standards
&lt;/h2&gt;

&lt;p&gt;x402 sits in a specific niche within the broader agent payment landscape, distinct from protocols like AP2 or MPP that focus more on authorization mandates and card-network integration.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;x402&lt;/th&gt;
&lt;th&gt;AP2 / Card-Network Protocols&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Settlement rail&lt;/td&gt;
&lt;td&gt;On-chain stablecoins (USDC)&lt;/td&gt;
&lt;td&gt;Traditional card/bank rails with cryptographic mandates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best fit&lt;/td&gt;
&lt;td&gt;Pay-per-call APIs, micropayments, data access&lt;/td&gt;
&lt;td&gt;Larger consumer purchases, subscriptions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Setup&lt;/td&gt;
&lt;td&gt;No account, no API key needed&lt;/td&gt;
&lt;td&gt;Requires to be registered merchant/payment relationships&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Speed&lt;/td&gt;
&lt;td&gt;Settles within the same HTTP request&lt;/td&gt;
&lt;td&gt;May involve separate authorization and settlement steps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fee structure&lt;/td&gt;
&lt;td&gt;Near-zero for stablecoin transfers&lt;/td&gt;
&lt;td&gt;Standard card-network interchange fees apply&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;x402 is best understood as a settlement layer built specifically for agents and services, not a consumer checkout replacement — it's optimized for high-frequency, low-value machine payments where card-network fees would make the transaction uneconomical. &lt;/p&gt;

&lt;h2&gt;
  
  
  Monetizing Your Own APIs with x402
&lt;/h2&gt;

&lt;p&gt;For a backend developer, adding x402 support to an existing API is a middleware-level change, not an architectural rewrite. Server-side, you add a payment-checking middleware (Express and other frameworks already have &lt;code&gt;@x402/express&lt;/code&gt;-style packages) that intercepts unpaid requests and returns the 402 challenge with your pricing and wallet address, then verifies incoming payment signatures before letting the request through. &lt;/p&gt;

&lt;p&gt;A minimal server-side pricing structure typically involves defining a discovery document — an OpenAPI-style manifest describing which endpoints are paid, the price per call, and accepted payment methods — so agents (or the MCP servers they use) can find and price your service programmatically before ever making a request. This is the same discoverability principle from MCP tool discovery, applied to payments: an agent shouldn't need to guess pricing through trial and error.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to Watch as the Standard Matures
&lt;/h2&gt;

&lt;p&gt;x402 is actively evolving — a v2 revision is standardizing header naming (&lt;code&gt;PAYMENT-REQUIRED&lt;/code&gt;, &lt;code&gt;PAYMENT-SIGNATURE&lt;/code&gt;, &lt;code&gt;PAYMENT-RESPONSE&lt;/code&gt;) and network identifiers using CAIP-2 chain formats, and developers building against it now should track which version their facilitator and client libraries actually support, since v1 and v2 agents can silently filter each other out if &lt;code&gt;accepts&lt;/code&gt; fields aren't handled correctly. Identity is also an open frontier — projects are already layering verified identity on top of x402's base payment flow, since the protocol itself proves a payment happened but says little about who or what authorized it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Where This Is Heading
&lt;/h2&gt;

&lt;p&gt;The practical shift for anyone building fintech or API-monetized products is this: pricing your service per-request, in stablecoins, discoverable by agents without a sales conversation, is quickly becoming a viable revenue model rather than a novelty. An agent buying a freight quote, a weather data point, or a single inference call from your API, paying in the same request that fetches it, is the kind of transaction volume that never made sense under card-network fees — and it's exactly the volume x402 was built to unlock. &lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>blockchain</category>
      <category>automation</category>
    </item>
    <item>
      <title>How Autonomous Agents Operates</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Fri, 28 Aug 2026 05:00:00 +0000</pubDate>
      <link>https://dev.to/shieldstring/how-autonomous-agents-operates-5614</link>
      <guid>https://dev.to/shieldstring/how-autonomous-agents-operates-5614</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Inside an Autonomous Agent: Discover via MCP, Coordinate via A2A, Transact via MPP&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An autonomous agent completing a real task rarely uses one protocol — it typically discovers a tool through MCP, hands off part of the work to another agent through A2A. It pays for a service through MPP, all within a single request chain. Tracing that flow end-to-end shows how these three protocols function together as layers of one stack rather than competing standards.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Tool Discovery via MCP
&lt;/h2&gt;

&lt;p&gt;Before an agent can act, it needs to know what tools exist and what they do — this is MCP's job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The handshake.&lt;/strong&gt; Discovery doesn't start with a plain "list tools" call. The client sends a JSON-RPC 2.0 &lt;code&gt;initialize&lt;/code&gt; request describing its own capabilities (like &lt;code&gt;supportsToolDiscovery&lt;/code&gt; and &lt;code&gt;maxToolCount&lt;/code&gt;), and the server responds with its own capability set. Only after this mutual negotiation does actual tool enumeration begin. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Static vs. dynamic discovery.&lt;/strong&gt; Once connected, an agent can pull tools three ways: statically defining them in code ahead of time, dynamically fetching the current list at runtime, or using a search function that performs semantic matching over available tools based on the user's actual request. Dynamic discovery matters increasingly in production because it lets a platform update its available tools without repackaging or republishing the agent — the client diffs the current tool list against what it last knew and applies changes automatically. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovery at scale.&lt;/strong&gt; In enterprise deployments, an MCP Gateway sits between the agent and multiple MCP servers, filtering which tools an agent can even see based on its identity, workspace, and permission policies — discovery answers "what exists," while a separate authorization step governs "how it can be called". Some gateways go further with a two-step catalog pattern: the agent first calls a lightweight &lt;code&gt;discover_tools&lt;/code&gt; meta-tool to browse categories and names without full schemas, then calls &lt;code&gt;select_tools&lt;/code&gt; to scope its session to a specific subset before receiving the full parameter schemas — this keeps context windows small and improves tool-selection accuracy. &lt;/p&gt;

&lt;p&gt;For a fintech backend, this means your existing REST endpoints — balance checks, transaction lookups — become MCP tools with structured schemas, and any agent (yours or a third party's) can discover and call them without a bespoke integration per client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Coordination via A2A
&lt;/h2&gt;

&lt;p&gt;Once an agent has tools, complex tasks often require delegating part of the work to another, independently built agent — this is what A2A standardizes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agent Cards.&lt;/strong&gt; Every A2A-compliant agent publishes a JSON capability descriptor called an Agent Card at a well-known path: &lt;code&gt;/.well-known/agent.json&lt;/code&gt;. This card gives a complete picture of what the agent can do, how to reach it, and what parameters it expects — the equivalent of a service's OpenAPI spec, but designed for another agent to read. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovery and delegation flow.&lt;/strong&gt; A client agent first fetches the target agent's card from that well-known URL and uses it to build a connection. When it needs that agent's help, it sends a message containing the task along with session metadata like a session ID and historical context. The receiving A2A server evaluates the incoming message as a &lt;strong&gt;Task&lt;/strong&gt; to complete, rather than treating it as a simple stateless API call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this differs from a plain API call.&lt;/strong&gt; A2A tasks carry state — the receiving agent can report back partial progress, ask clarifying questions, or return a task in an intermediate status, not just a final response. This matters for genuinely long-running or multi-step delegation, like one agent asking a separate logistics agent to "find the fastest delivery route" while a parent workflow waits on updates rather than blocking on one synchronous request.&lt;/p&gt;

&lt;p&gt;In a fintech scenario, this looks like a customer-facing support agent discovering a specialized fraud-review agent via its Agent Card, delegating a suspicious transaction for deeper analysis, and continuing the conversation once that sub-agent reports back — all without the two systems having been built by the same team or sharing a private API contract.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Transacting via MPP
&lt;/h2&gt;

&lt;p&gt;Once the right tool is found and any needed coordination is done, the agent may need to pay for the resource itself — this is where MPP (Machine Payments Protocol) takes over.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The core handshake is HTTP-native.&lt;/strong&gt; MPP, co-authored by Stripe and Tempo and launched in March 2026, layers payment directly onto standard HTTP requests using the existing &lt;code&gt;402 Payment Required&lt;/code&gt; status code. The full flow runs in a single request cycle with no redirects or webhooks required: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The agent sends a standard HTTP request (a &lt;code&gt;GET&lt;/code&gt;, for instance) to a paid endpoint&lt;/li&gt;
&lt;li&gt;The server responds with &lt;code&gt;402 Payment Required&lt;/code&gt; and a &lt;code&gt;WWW-Authenticate: Payment&lt;/code&gt; header specifying price, accepted currencies, recipient details, and supported payment methods &lt;/li&gt;
&lt;li&gt;The agent selects a payment method and authorizes payment — via stablecoin transfer, card payment, or another supported rail &lt;/li&gt;
&lt;li&gt;The agent resends the original request, this time including payment credentials in an &lt;code&gt;Authorization: Payment&lt;/code&gt; header &lt;/li&gt;
&lt;li&gt;The server verifies the payment and returns the resource along with a &lt;code&gt;Payment-Receipt&lt;/code&gt; header as proof &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Beyond one-shot payments.&lt;/strong&gt; MPP layers four additional primitives on top of that base handshake: recurring subscriptions, streaming (metered, continuous) payments, cancellation events, and balance reconciliation — all addressed over the same HTTP surface rather than requiring separate billing infrastructure. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MCP tools can be monetized directly.&lt;/strong&gt; MPP explicitly supports paying per MCP tool call — an agent can call a monetized MCP server and pay per invocation without any OAuth flow or account setup, closing the loop between the discovery layer and the payment layer. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovery of paid services.&lt;/strong&gt; Just as MCP has tool discovery, MPP has service discovery: providers can advertise their API's payment terms through an OpenAPI-style discovery document, and agents can find paid APIs through directories like the mpp.dev catalog or via MCP servers built specifically for that purpose. &lt;/p&gt;

&lt;h2&gt;
  
  
  Putting the Full Chain Together
&lt;/h2&gt;

&lt;p&gt;Consider an autonomous procurement agent tasked with sourcing the cheapest available freight quote for a logistics shipment:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;MCP discovery&lt;/strong&gt; — the agent queries its MCP Gateway, which filters and returns only the freight and logistics tools it's permitted to use, based on its identity and workspace policy &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A2A delegation&lt;/strong&gt; — instead of calling every carrier directly, it fetches the Agent Card of a specialized freight-broker agent and delegates the task of gathering quotes, passing along shipment details and a session ID &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MPP settlement&lt;/strong&gt; — once a quote is selected, the broker agent's booking endpoint returns a &lt;code&gt;402&lt;/code&gt; with the price and accepted payment methods; the procurement agent authorizes payment via its available credential, resends the request, and receives a confirmed booking with a payment receipt &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;No human clicked a button anywhere in that sequence, and no single vendor owns the whole chain — MCP handled what tools existed, A2A handled who could help, and MPP handled how the final transaction settled.&lt;/p&gt;

&lt;h2&gt;
  
  
  What This Means for Your Systems
&lt;/h2&gt;

&lt;p&gt;If you're exposing backend services for agents to consume, the practical build order mirrors this chain: wrap your APIs in an MCP server with clear tool schemas first, since that's the layer with the broadest existing tooling support. If your workflows genuinely require delegating tasks to other independently built agents rather than just calling your own tools, add an A2A-compliant Agent Card. Only add MPP support once you actually need agents to pay for access — it plugs directly into existing payment processors like Stripe's PaymentIntents API with a few lines of code, so it's a late addition rather than a prerequisite. &lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>machinelearning</category>
      <category>mcp</category>
    </item>
    <item>
      <title>Leading with Curiosity in the Era of AI</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Wed, 26 Aug 2026 18:31:13 +0000</pubDate>
      <link>https://dev.to/shieldstring/leading-with-curiosity-in-the-era-of-ai-5h80</link>
      <guid>https://dev.to/shieldstring/leading-with-curiosity-in-the-era-of-ai-5h80</guid>
      <description>&lt;p&gt;The technical skills to deploy AI are increasingly commoditized — what's scarce is the judgment to know when to question its output, the resilience to keep experimenting after it fails, and the leadership habits that let teams take those risks safely. As AI absorbs more of the execution work, the human skills that separate good outcomes from mediocre ones are shifting toward curiosity, judgment, and the courage to rethink assumptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Curiosity Is Becoming a Named Leadership Skill
&lt;/h2&gt;

&lt;p&gt;Curiosity used to read as a personality trait — some people ask more questions, others don't. It's now being treated as a trainable leadership competency with measurable consequences. Research on workplace curiosity shows it directly boosts both incremental and radical innovation performance in high-tech industries, and a growing body of leadership studies links it to higher engagement, better problem-solving, and more effective collaboration across teams. &lt;/p&gt;

&lt;p&gt;The AI-specific version of this gap has a name: &lt;strong&gt;data curiosity&lt;/strong&gt;, and it's emerging as one of the biggest blockers to organizations actually realizing AI's value. Leaders who lack data curiosity don't know how to question inputs, probe why a model produced a given output, or push back when something looks off — they either accept AI outputs uncritically or reject them reflexively, and both failure modes are expensive. &lt;/p&gt;

&lt;p&gt;This matters especially for technical leads working directly with AI systems: a curious engineer treats a hallucinated function call or a wrong SQL join not as a dead end but as a question — why did the model reason this way, what context was missing, what would make it more reliable next time. That habit of interrogation is what actually improves system quality over time, more than any single prompt tweak.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fuller Skill Set: Curiosity, Resilience, and Judgment
&lt;/h2&gt;

&lt;p&gt;The World Economic Forum's future-of-work research names analytical thinking, resilience, flexibility, agility, leadership, social influence, curiosity, and lifelong learning as the core skills for the AI-shaped economy — not as a checklist of soft skills, but as the operating capabilities that let people work productively alongside systems that keep changing under them. &lt;/p&gt;

&lt;p&gt;These skills reinforce each other in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Curiosity&lt;/strong&gt; drives the willingness to ask "what assumption are we taking for granted here?" instead of accepting the first plausible answer an AI system gives &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resilience&lt;/strong&gt; is what lets someone run five failed experiments with a new model or workflow and treat the fifth attempt with the same energy as the first, rather than giving up after the second&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Good judgment&lt;/strong&gt; is what separates a leader who knows when an AI recommendation is trustworthy from one who defers to it by default or dismisses it by default — both are judgment failures, just in opposite directions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rethinking assumptions&lt;/strong&gt; is the practice of periodically asking whether the workflow, org structure, or product decision made two years ago still holds now that the tools have changed underneath it&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these compound automatically. They depend on leaders actively creating the conditions where curiosity and risk-taking are survivable, which is a separate and harder problem than simply telling people to "be more curious."&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Conditions for Growth: The Psychological Safety Layer
&lt;/h2&gt;

&lt;p&gt;The connecting mechanism behind all of this is psychological safety — the shared belief that it's safe to take interpersonal risks at work: to speak up with ideas, admit mistakes, or challenge an approach without fear of punishment or embarrassment. Curiosity doesn't survive in a team where the first person to say "I don't think this AI-generated approach is actually right" gets quietly penalized for slowing things down. &lt;/p&gt;

&lt;p&gt;A few concrete practices leaders can act on directly:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model vulnerability first.&lt;/strong&gt; Leaders who openly say "I got this wrong" or "I don't know, let's find out" give everyone else permission to do the same — psychological safety research consistently finds this is the single mechanism that makes the rest possible, not a nice-to-have addition to it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separate the person from the idea.&lt;/strong&gt; Use language like "let's stress-test this approach" rather than "you didn't think this through" — this keeps disagreement about the work, not the person, which is what lets teams challenge each other's (and the AI's) output without it feeling personal. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Respond to mistakes as data, not verdicts.&lt;/strong&gt; When an experiment with a new AI workflow fails, the response that matters is "what did we learn and what do we try next," not silent disappointment or blame — teams that get punished for reasonable risks stop taking them, and curiosity dies quietly. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make the question as celebrated as the answer.&lt;/strong&gt; When someone on the team challenges an AI output and turns out to be right, make that visible — the goal is to reward the instinct to question, not just the correct final result. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Give explicit room to experiment without guaranteed payoff.&lt;/strong&gt; Curious people need space to run experiments that don't work out — if every AI-related initiative needs to show ROI immediately, people stop proposing the exploratory ones that eventually produce the biggest gains. &lt;/p&gt;

&lt;h2&gt;
  
  
  From Delivery Squads to Curiosity Crews
&lt;/h2&gt;

&lt;p&gt;One practical structural shift some organizations are making is running dedicated small, cross-functional teams whose explicit job is structured experimentation with AI — testing new workflows, prompts, and integrations, then reporting back what they learned, separate from the delivery teams focused on shipping. This solves a real tension: delivery teams are (rightly) measured on throughput and reliability, which makes them poor environments for open-ended exploration. A dedicated exploration function gives curiosity a home without asking delivery teams to sacrifice velocity for uncertain experiments. &lt;/p&gt;

&lt;p&gt;For a technical lead, this could be as small as blocking two hours a week when a rotating pair on the team investigates one open question about your AI tooling — not shipping a feature, just generating a clearer answer to something the team has been assuming rather than testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making Curiosity Measurable
&lt;/h2&gt;

&lt;p&gt;Leadership skills that stay abstract tend not to get invested in. Curiosity and exploration can be tracked with concrete, unglamorous metrics: how often teams test new prompts or workflows, how many ideas from AI-assisted brainstorming actually make it into the top tier of concepts considered, and whether retrospectives regularly surface a genuinely new "why" question rather than the same recurring ones. One HBS field study found AI-enabled workers generated a measurably higher share of top-tier ideas when they were structurally encouraged to explore more options before committing — evidence that the exploration itself, not just access to the tool, produces the gain. &lt;/p&gt;

&lt;h2&gt;
  
  
  A 90-Day Starting Point
&lt;/h2&gt;

&lt;p&gt;For a leader looking to act on this rather than just agree with it, three questions are enough to start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where are we currently discouraging curiosity, even unintentionally — through how mistakes get discussed, how fast decisions get locked in, or who gets heard in a meeting?&lt;/li&gt;
&lt;li&gt;Which recent decision would have benefited from exploring three or four more options with AI's help before committing?&lt;/li&gt;
&lt;li&gt;What's one curiosity ritual — a retro question, a rotating investigation slot, a "celebrate the challenge" habit — that could be added to the team's existing rhythm without requiring a new process on top of everything else?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The organizations that get real value from AI won't be the ones with the most sophisticated models — they'll be the ones whose people ask better questions of those models, and whose leaders built the conditions that made asking those questions safe in the first place. &lt;/p&gt;

</description>
      <category>ai</category>
      <category>leadership</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Building for the Agentic Internet: The New Protocol Stack</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Wed, 26 Aug 2026 17:39:42 +0000</pubDate>
      <link>https://dev.to/shieldstring/building-for-the-agentic-internet-the-new-protocol-stack-f0m</link>
      <guid>https://dev.to/shieldstring/building-for-the-agentic-internet-the-new-protocol-stack-f0m</guid>
      <description>&lt;p&gt;The internet is quietly growing a second interface layer — one built for AI agents instead of human clicks. By August 2026, at least ten commerce protocols and four coordination standards are live, and understanding where each fits is now a practical requirement for any backend developer shipping fintech, logistics, or e-commerce systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is the Agentic Internet?
&lt;/h2&gt;

&lt;p&gt;The agentic internet refers to a web where autonomous AI agents — not humans clicking through pages — discover services, negotiate terms, and complete transactions on a user's behalf. Instead of a person browsing a checkout page, an agent reads structured data, calls an API, verifies payment authorization, and completes the purchase, often across several other agents it doesn't control.&lt;/p&gt;

&lt;p&gt;This shift is happening at the protocol level: rather than every AI vendor building bespoke integrations with every merchant or tool, the industry has begun converging on a shared stack, similar to how HTTP standardized the human web.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Four-Layer Protocol Stack
&lt;/h2&gt;

&lt;p&gt;As of mid-2026, the agent protocol landscape has settled into distinct, complementary layers rather than one winning standard.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Protocol&lt;/th&gt;
&lt;th&gt;Owner&lt;/th&gt;
&lt;th&gt;What It Does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Tool access&lt;/td&gt;
&lt;td&gt;MCP (Model Context Protocol)&lt;/td&gt;
&lt;td&gt;Anthropic → Linux Foundation&lt;/td&gt;
&lt;td&gt;Connects an agent to data, APIs, and tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Agent coordination&lt;/td&gt;
&lt;td&gt;A2A (Agent2Agent)&lt;/td&gt;
&lt;td&gt;Google → Linux Foundation&lt;/td&gt;
&lt;td&gt;Lets independently built agents discover and delegate tasks to each other&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Commerce/checkout&lt;/td&gt;
&lt;td&gt;UCP, ACP, Shopify Agents, Amazon Buy for Me&lt;/td&gt;
&lt;td&gt;Google+Shopify; OpenAI+Stripe; others&lt;/td&gt;
&lt;td&gt;Standardizes product discovery, cart, and checkout flows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Payments/authorization&lt;/td&gt;
&lt;td&gt;AP2, Stripe MPP, Mastercard Verifiable Intent, Visa Ready&lt;/td&gt;
&lt;td&gt;Google+Coinbase; Stripe+Tempo; card networks&lt;/td&gt;
&lt;td&gt;Cryptographic proof of who authorized a spend and how much&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A useful mental model: &lt;strong&gt;MCP&lt;/strong&gt; is how an agent reads your systems, &lt;strong&gt;A2A&lt;/strong&gt; is how it talks to other agents, and &lt;strong&gt;UCP/ACP plus AP2&lt;/strong&gt; are how it actually buys something and proves it was allowed to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters for Fintech and Payments
&lt;/h2&gt;

&lt;p&gt;This is the layer where payments expertise becomes directly relevant. AP2, the Agent Payments Protocol, centers on cryptographic mandates — verifiable, user-signed authorizations that scope exactly what an agent may spend, on what, and within what bounds, giving every party in a transaction a proof trail.&lt;/p&gt;

&lt;p&gt;Stripe and Tempo's Machine Payments Protocol (MPP), launched in March 2026, provides a specification for agents and services to coordinate payments programmatically, enabling AI agents to autonomously make payments without a human in the loop.&lt;/p&gt;

&lt;p&gt;Google's Universal Commerce Protocol (UCP), announced at NRF in January 2026, establishes a common language for agents, businesses, and payment providers so a single integration works across the entire shopping journey instead of requiring a custom connection per agent vendor. As of April 2026, UCP formally added A2A as a transport option alongside REST, MCP, and embedded APIs — meaning it now plugs directly into the coordination layer rather than living as an isolated commerce spec.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fragmentation Problem
&lt;/h2&gt;

&lt;p&gt;The honest reality: none of the ten active commerce protocols currently interoperate with each other. A merchant supporting ChatGPT's shopping agents needs ACP (Stripe/OpenAI, Apache 2.0), a merchant optimizing for Google's AI Mode needs UCP, and one targeting Amazon's in-app agent needs a completely separate integration.&lt;/p&gt;

&lt;p&gt;This mirrors the early API-sprawl era of fintech integrations — every payment gateway having its own auth and callback conventions — except now it's happening industry-wide, across dozens of AI platforms simultaneously.&lt;/p&gt;

&lt;p&gt;The pragmatic response most engineering teams are taking is layered adoption: implement MCP first since it has the broadest tooling support (over 10,000 MCP servers already exist), add A2A if you need multi-agent coordination, and pick commerce protocols based on where your actual customers' agents originate — Google ecosystem, OpenAI ecosystem, or a specific card network's program.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Start Building for the Agentic Internet
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Expose your existing APIs through MCP.&lt;/strong&gt;&lt;br&gt;
If you already have REST endpoints for account data, order status, or inventory, wrapping them in an MCP server is the fastest way to make your system agent-readable without redesigning your backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Add structured, machine-readable discovery.&lt;/strong&gt;&lt;br&gt;
Agents rely on structured product feeds and "Agent Cards" (JSON capability descriptors) rather than scraping HTML — publishing this metadata is now as important as your public API docs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Decide your commerce protocol based on channel, not preference.&lt;/strong&gt;&lt;br&gt;
If your app processes payments that ChatGPT-based agents might initiate, ACP with Stripe is the direct path; if Google Search/AI Mode visibility matters more, UCP is the better fit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Build authorization mandates, not blanket API keys.&lt;/strong&gt;&lt;br&gt;
Whatever payment protocol you choose, model your authorization layer around scoped, auditable permissions (what, how much, until when) — this is the core idea behind AP2 and Visa's Verifiable Intent, and it's good practice even before full protocol adoption.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Treat agent traffic as a first-class client, not an edge case.&lt;/strong&gt;&lt;br&gt;
Add logging and rate-limiting specifically for agent-originated requests early, since agent traffic patterns (bursty, programmatic, unattended) differ from human browsing sessions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Still Unsettled
&lt;/h2&gt;

&lt;p&gt;The Agentic Commerce Protocol reached its v1.0 stable release in April 2026 with over 165 supporting organizations and joined the Linux Foundation's Agentic AI Foundation as a hosted project in August 2026 — a sign of real convergence, but the payments and checkout layer is still consolidating faster than the underlying trust and identity layer.&lt;/p&gt;

&lt;p&gt;For a backend team today, the safest bet is building on &lt;strong&gt;MCP&lt;/strong&gt; and &lt;strong&gt;A2A&lt;/strong&gt; now, since both have Linux Foundation backing and broad multi-vendor support, while treating the commerce-specific protocols (UCP, ACP, MPP) as pluggable adapters you can swap or run in parallel as the market picks winners.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>api</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Mental Health Support and First Aid Chatbots with Gemma 4 + Google AI Studio</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Wed, 08 Jul 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/shieldstring/building-full-gemma-4-google-ai-studio-projects-mental-health-support-and-first-aid-chatbots-17ma</link>
      <guid>https://dev.to/shieldstring/building-full-gemma-4-google-ai-studio-projects-mental-health-support-and-first-aid-chatbots-17ma</guid>
      <description>&lt;p&gt;We walk through two complete, working projects built with Gemma 4 via Google AI Studio's Gemini API: a mental health support companion and a first-aid guidance chatbot. Both use real function-calling, both prototype safely inside AI Studio before shipping code, and both are built with a strong safety-first design since they touch sensitive, high-stakes conversations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project 1: Mental Health Support Chatbot
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What We're Building
&lt;/h3&gt;

&lt;p&gt;A supportive conversational companion that can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Offer active-listening style responses and coping suggestions for stress, anxiety, or low mood&lt;/li&gt;
&lt;li&gt;Detect crisis language and immediately surface hotline/emergency contact information&lt;/li&gt;
&lt;li&gt;Log mood check-ins over time for the user to track patterns&lt;/li&gt;
&lt;li&gt;Never diagnose, prescribe, or replace a licensed therapist&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model must never attempt clinical diagnosis or minimize distress — every crisis-flagged message routes through a dedicated safety tool rather than free-text generation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Prototype the Agent in Google AI Studio
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Opened the model picker and selected &lt;code&gt;gemma-4-31b-it&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Added this system instruction in the chat panel:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a warm, non-judgmental mental health support companion. You are NOT
a therapist and must never diagnose conditions or suggest medication. Use
active listening: reflect feelings back, ask gentle open questions, and
suggest simple coping strategies (breathing, grounding, journaling). If the
user expresses thoughts of self-harm, suicide, or being in danger, ALWAYS
call the crisis_escalation tool immediately before responding — do not try
to handle it with conversation alone. Keep responses warm but concise.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Defined two tools — &lt;code&gt;crisis_escalation&lt;/code&gt; and &lt;code&gt;log_mood_checkin&lt;/code&gt; — in the Tools panel&lt;/li&gt;
&lt;li&gt;Deliberately tested edge-case phrases like "I don't see the point anymore" and "I've been feeling really low lately" side by side in the AI Studio chat, to confirm the model correctly distinguished a crisis signal from general low mood before calling different tools&lt;/li&gt;
&lt;li&gt;Iterated on the &lt;code&gt;crisis_escalation&lt;/code&gt; tool description until the model stopped hesitating on ambiguous phrasing — erring toward escalation when in doubt&lt;/li&gt;
&lt;li&gt;Clicked &lt;strong&gt;Get Code&lt;/strong&gt; to export a starting JavaScript snippet&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Testing crisis-detection boundaries directly in AI Studio's chat — before any code existed — was the most important step here. Getting this wrong in production isn't just a bug, so it needed to be validated conversationally first, with many rephrased inputs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Define the Tools and Backend
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tools.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;functionDeclarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"crisis_escalation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Call IMMEDIATELY if the user expresses any thoughts of self-harm, suicide, hopelessness framed as 'no point', or being in immediate danger. When in doubt, call this tool rather than continuing casual conversation."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;riskSignal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"The phrase or context that triggered escalation"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"userId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"riskSignal"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"log_mood_checkin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use when the user shares how they're feeling generally, to record a non-crisis mood entry for tracking over time."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;mood&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. anxious, low, okay, good"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"userId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"mood"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;moodLog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;CRISIS_HOTLINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Nigeria Suicide Prevention Helpline: 0800-800-2000 (24/7)"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;crisis_escalation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;riskSignal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// In production: alert a human moderator/counselor queue immediately&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`CRISIS ESCALATION for ${userId}: ${riskSignal}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;escalated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hotline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;CRISIS_HOTLINE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"A real person can help right now. Please reach out to the number provided."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log_mood_checkin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mood&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mood&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-07-07"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;moodLog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;logged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;crisis_escalation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;log_mood_checkin&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: The Agent Loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// server.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@google/genai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./tools.js"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GEMINI_API_KEY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MODEL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MAX_STEPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SYSTEM_INSTRUCTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`You are a warm, non-judgmental mental health support companion...`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/api/chat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sessionId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;MODEL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;systemInstruction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;SYSTEM_INSTRUCTION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;escalated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;MAX_STEPS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"crisis_escalation"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;escalated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;functionResponse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;escalated&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolStepsUsed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Mental health support agent running on port 3000"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Run It — Actual Results
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Request — general low mood:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"user1","message":"I have been feeling really low and tired lately"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"That sounds really heavy to carry. Feeling low and tired for a while can wear you down. Would it help to talk about what's been going on, or would you rather try a quick grounding exercise together?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"escalated"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request — crisis language:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"user1","message":"Honestly I dont see the point in anything anymore"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"I'm really glad you told me that, and I want you to know you don't have to go through this alone. Please reach out right now to the Nigeria Suicide Prevention Helpline: 0800-800-2000, available 24/7. A real person there can support you immediately. I'm still here with you too."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"escalated"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;escalated: true&lt;/code&gt; flag lets your frontend immediately surface a prominent hotline banner or trigger a human review queue, rather than relying on the chat text alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Safety Notes for This Project
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Set &lt;code&gt;temperature&lt;/code&gt; low (0.3-0.5) to reduce unpredictable phrasing in sensitive responses&lt;/li&gt;
&lt;li&gt;Log every &lt;code&gt;crisis_escalation&lt;/code&gt; call to a monitored channel (Slack, PagerDuty, email) — never let it be silent&lt;/li&gt;
&lt;li&gt;Add a persistent, always-visible hotline number in the UI regardless of what the model says&lt;/li&gt;
&lt;li&gt;Never present this chatbot as a replacement for professional care — state that clearly in onboarding, not just in the system prompt&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Project 2: First Aid AI Chatbot
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What We're Building
&lt;/h3&gt;

&lt;p&gt;An emergency-guidance assistant that can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give step-by-step first aid instructions for common injuries (burns, cuts, choking, fainting)&lt;/li&gt;
&lt;li&gt;Diagnose severity from a description or photo and recommend whether to call emergency services&lt;/li&gt;
&lt;li&gt;Look up the nearest hospital or emergency contact&lt;/li&gt;
&lt;li&gt;Always default to "seek professional help" when a situation sounds serious&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Prototype in Google AI Studio
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Selected &lt;code&gt;gemma-4-31b-it&lt;/code&gt; for multimodal support (injury photos)&lt;/li&gt;
&lt;li&gt;System instruction:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a first aid guidance assistant. Give clear, step-by-step instructions
for common injuries using the assess_severity tool to determine urgency
BEFORE giving detailed steps. If severity is high or symptoms suggest a
medical emergency (heavy bleeding, unconsciousness, difficulty breathing,
chest pain), immediately advise calling emergency services and use the
find_emergency_contact tool. Never claim to replace professional medical care.
Use short numbered steps, no long paragraphs.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Defined &lt;code&gt;assess_severity&lt;/code&gt; and &lt;code&gt;find_emergency_contact&lt;/code&gt; tools&lt;/li&gt;
&lt;li&gt;Tested with deliberately varied injury descriptions ("small paper cut" vs. "can't stop the bleeding") to confirm severity tiers routed correctly&lt;/li&gt;
&lt;li&gt;Uploaded a sample photo of a minor burn to validate multimodal severity assessment in-browser&lt;/li&gt;
&lt;li&gt;Exported code via &lt;strong&gt;Get Code&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Tools and Backend
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tools.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;functionDeclarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"assess_severity"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ALWAYS call this first for any injury or symptom description to determine urgency level before giving instructions."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;injuryType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. burn, cut, choking, fainting, chest pain"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Details or visual symptoms described"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"injuryType"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"find_emergency_contact"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use when severity is high or the situation is a medical emergency, to provide local emergency numbers."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. Port Harcourt"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"location"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;emergencyNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"port harcourt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ambulance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"112"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hospital&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"UPTH Emergency: 084-234-XXX"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;assess_severity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;injuryType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;highRiskTerms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"can't stop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"unconscious"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"difficulty breathing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"chest pain"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"severe"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;isHigh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;highRiskTerms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;term&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;injuryType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;isHigh&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"high"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"low-moderate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;recommendation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;isHigh&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Call emergency services immediately"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Can likely be managed with first aid steps"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;find_emergency_contact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;contact&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;emergencyNumbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;contact&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contact&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"No local emergency data available — call national emergency line 112"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;assess_severity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;find_emergency_contact&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Run It — Actual Results
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Request — minor injury:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"u1","message":"I got a small burn on my finger from a hot pan"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"This sounds manageable at home. Here's what to do:\n1. Run cool (not ice-cold) water over the burn for 10-15 minutes\n2. Remove any rings near the area before it swells\n3. Cover loosely with a clean, non-stick bandage\n4. Do not apply butter or toothpaste\n5. If blistering worsens or it doesn't improve in a day, see a doctor."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request — emergency situation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"u1","message":"My dad is holding his chest and having difficulty breathing, we are in Port Harcourt"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"This could be a medical emergency. Call 112 right now, or the UPTH Emergency line: 084-234-XXX. While waiting: help him sit upright and stay calm, loosen tight clothing, and do not leave him alone. Do not drive him yourself if an ambulance can come faster."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;toolStepsUsed: 2&lt;/code&gt; shows the model correctly chained &lt;code&gt;assess_severity&lt;/code&gt; (flagging high risk) into &lt;code&gt;find_emergency_contact&lt;/code&gt;, without being told explicitly to do both — the tool descriptions alone drove that sequencing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Safety Notes for This Project
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This chatbot should carry a persistent disclaimer that it does not replace calling emergency services directly&lt;/li&gt;
&lt;li&gt;Consider hardcoding a "Call Emergency Now" button in the UI independent of the chat, so users in real emergencies aren't relying on network latency to a chat API&lt;/li&gt;
&lt;li&gt;For rural or low-connectivity areas, a self-hosted E2B/E4B model on a phone (Android AICore) matters even more here than for other use cases — first aid guidance needs to work when a signal doesn't&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Shared Lessons Across Both Projects
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI Studio's browser chat is a safety-testing tool, not just a coding shortcut&lt;/strong&gt; — for sensitive domains, spend real time trying to break your tool-routing logic with edge-case phrasing before writing a line of backend code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tool descriptions carry the actual judgment calls&lt;/strong&gt; — "when in doubt, escalate" belongs in the tool description, not buried in a general system prompt&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;toolStepsUsed&lt;/code&gt; and explicit flags like &lt;code&gt;escalated&lt;/code&gt;&lt;/strong&gt; give your frontend and monitoring systems a way to react to model behavior without parsing free text&lt;/li&gt;
&lt;li&gt;Both projects are stronger candidates for on-device Gemma deployment (E2B/E4B) than for cloud-only APIs, since low-connectivity access to first aid or mental health support can matter most in the exact moments when a network isn't available&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>gemma</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Agentic farm advisory assistant built with Gemma 4 + Google AI Studio</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Wed, 08 Jul 2026 01:00:00 +0000</pubDate>
      <link>https://dev.to/shieldstring/agentic-farm-advisory-assistant-built-with-gemma-4-google-ai-studio-14ca</link>
      <guid>https://dev.to/shieldstring/agentic-farm-advisory-assistant-built-with-gemma-4-google-ai-studio-14ca</guid>
      <description>&lt;p&gt;We will walk through a complete, working project: an agentic farm advisory assistant built with Gemma 4 through Google AI Studio's Gemini API. It diagnoses crop issues from photos, checks weather-based planting windows, and logs farm activity through real function-calling — prototyped in the browser, then shipped as an Express backend with a chat UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We're Building
&lt;/h2&gt;

&lt;p&gt;An advisory chatbot for smallholder farmers and agro-logistics platforms that can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Diagnose a crop disease or pest issue from an uploaded photo&lt;/li&gt;
&lt;li&gt;Check whether current weather conditions are safe for planting or spraying&lt;/li&gt;
&lt;li&gt;Look up market prices for a given crop&lt;/li&gt;
&lt;li&gt;Log a farm activity (planting, spraying, harvest) to a farmer's record&lt;/li&gt;
&lt;li&gt;Reply naturally, including in Nigerian Pidgin or local phrasing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model never guesses market prices or weather data — every factual answer comes from an actual function call against a backend, not the model's own assumptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Prototype the Agent in Google AI Studio
&lt;/h2&gt;

&lt;p&gt;Before writing any code, the entire agent was designed inside aistudio.google.com:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Opened the model picker and selected &lt;code&gt;gemma-4-31b-it&lt;/code&gt; for its multimodal (image) support&lt;/li&gt;
&lt;li&gt;Added this system instruction in the chat panel:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a friendly, practical farm advisory assistant for smallholder farmers
in Nigeria. Always use the provided tools for weather checks, market prices,
and activity logging — never guess prices or weather data. When a farmer
uploads a crop photo, examine it carefully before giving diagnosis and
next steps. Keep responses short, practical, and in plain language. Reply
in the same language or Pidgin the farmer writes in.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Defined four tools in the Tools panel — &lt;code&gt;check_weather_window&lt;/code&gt;, &lt;code&gt;get_market_price&lt;/code&gt;, &lt;code&gt;log_farm_activity&lt;/code&gt;, and &lt;code&gt;diagnose_crop_image&lt;/code&gt; — each with a JSON schema and a scoped description&lt;/li&gt;
&lt;li&gt;Uploaded sample crop photos (a leaf with brown spots, a tomato plant with wilting) directly in the AI Studio chat to test multimodal diagnosis before writing any code&lt;/li&gt;
&lt;li&gt;Tested prompts like "Is it safe to spray my maize today?" until the model reliably called &lt;code&gt;check_weather_window&lt;/code&gt; instead of answering from general knowledge&lt;/li&gt;
&lt;li&gt;Clicked &lt;strong&gt;Get Code&lt;/strong&gt; to export a starting JavaScript snippet using &lt;code&gt;@google/genai&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Testing the image diagnosis directly in the browser first was the most valuable step — it's far easier to spot a vague description problem ("model just said 'looks unhealthy'") in a live chat than after it's buried in server logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Define the Tools and Mock Backend
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tools.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;functionDeclarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"check_weather_window"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use when the farmer asks if it's safe or a good time to plant, spray, or harvest. Never guess weather."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. Port Harcourt, Owerri"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"planting, spraying, or harvesting"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"location"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"activity"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"get_market_price"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use ONLY when the farmer asks for the current price of a crop. Never guess a price."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. cassava, maize, tomato"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. Mile 1 Market, Port Harcourt"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"crop"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"log_farm_activity"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use when the farmer reports completing an activity like planting, spraying, or harvesting."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;farmerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"planting, spraying, harvesting"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"farmerId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"activity"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"crop"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"diagnose_crop_image"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use when the farmer uploads a photo of a crop showing signs of disease, pest damage, or poor health."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. maize, tomato, cassava"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;symptomDescription&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Visible symptoms described from the image"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"crop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"symptomDescription"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;weatherData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"port harcourt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;rainChance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"clear, light wind"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"owerri"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;rainChance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"heavy rain expected"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;marketPrices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;cassava&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;pricePerBag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NGN"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Mile 1 Market"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;maize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;pricePerBag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NGN"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Mile 1 Market"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;tomato&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;pricePerBasket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NGN"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Mile 1 Market"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;activityLog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;check_weather_window&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activity&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;weather&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;weatherData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Location not found in weather data"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;safe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;activity&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"spraying"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rainChance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;recommendation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;safe&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Safe to proceed"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Wait — rain expected, risk of runoff"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;get_market_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;marketPrices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`No price data for ${crop}`&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log_farm_activity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;farmerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;farmerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-07-07"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;activityLog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;logged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;diagnose_crop_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symptomDescription&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// In production, this would call a vision model or trained classifier.&lt;/span&gt;
  &lt;span class="c1"&gt;// Here Gemma 4's own multimodal reasoning already produced symptomDescription&lt;/span&gt;
  &lt;span class="c1"&gt;// from the uploaded image before calling this tool.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;knownIssues&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"brown spots on leaves"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Likely leaf blight — recommend copper-based fungicide, improve drainage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"wilting despite watering"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Possible bacterial wilt or root rot — check soil drainage and remove affected plants"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;knownIssues&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;symptomDescription&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;diagnosis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;knownIssues&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Symptoms noted but inconclusive — recommend local extension officer visit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;check_weather_window&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;get_market_price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;log_farm_activity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;diagnose_crop_image&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Build the Agent Loop in Express
&lt;/h2&gt;

&lt;p&gt;The core of the backend is a loop that keeps resolving tool calls — including image-based diagnosis — until Gemma 4 returns a final plain-text answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// server.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@google/genai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./tools.js"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"10mb"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// allow base64 image payloads&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GEMINI_API_KEY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MODEL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MAX_STEPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SYSTEM_INSTRUCTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`You are a friendly, practical farm advisory assistant...`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/api/chat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sessionId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;imageBase64&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;MODEL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;systemInstruction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;SYSTEM_INSTRUCTION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;imageBase64&lt;/span&gt;
    &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;inlineData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;mimeType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"image/jpeg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;imageBase64&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;MAX_STEPS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;functionResponse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolStepsUsed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Agro advisory agent running on port 3000"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Run It — Actual Results
&lt;/h2&gt;

&lt;p&gt;With the server running (&lt;code&gt;npm start&lt;/code&gt;) and a &lt;code&gt;GEMINI_API_KEY&lt;/code&gt; from AI Studio set in &lt;code&gt;.env&lt;/code&gt;, here's what real requests return.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request — weather check before spraying:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"farmer1","message":"Is it safe to spray my maize in Owerri today?"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Not today — Owerri has a 70% chance of rain, which could wash off the spray before it works. Wait for a drier day."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request — market price check:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"farmer1","message":"How much is cassava selling for now?"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Cassava is currently going for NGN 18,500 per bag at Mile 1 Market."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request — crop photo diagnosis (image + text):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"farmer1","message":"My tomato plant looks sick, see photo","imageBase64":"&amp;lt;base64 jpeg data&amp;gt;"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"I see wilting and yellowing leaves on your tomato plant. This looks like bacterial wilt or root rot. Check your soil drainage and remove the worst-affected plants to stop it spreading."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request — Pidgin, activity logging:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"sessionId":"farmer1","message":"I don finish plant my maize for farm today, farmer ID FARM-002"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Good work! I don log say you plant maize today for your farm record (FARM-002). E dey saved."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why This Pattern Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Correctness&lt;/strong&gt;: weather windows and market prices come from &lt;code&gt;toolFunctions&lt;/code&gt;, not the model's own guess, so a farmer never gets rain-safety advice invented on the spot&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multimodal grounding&lt;/strong&gt;: Gemma 4 reads the uploaded photo directly, describes the symptoms, and hands that description to a diagnosis tool — combining visual reasoning with a controllable, auditable backend step&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traceability&lt;/strong&gt;: &lt;code&gt;toolStepsUsed&lt;/code&gt; on every response makes it easy to log exactly what the agent did, useful for tracking advisory accuracy over a growing season&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast iteration&lt;/strong&gt;: because the tool descriptions and image-handling behavior were validated in AI Studio's chat first, the Express implementation worked correctly on the first real run&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Taking It Further
&lt;/h2&gt;

&lt;p&gt;Swap the mock weather and price data in &lt;code&gt;tools.js&lt;/code&gt; for a real weather API and a live market-price feed (e.g., from a state agriculture board or a partner logistics platform), move the activity log from an in-memory array to MongoDB, and replace the rule-based &lt;code&gt;diagnose_crop_image&lt;/code&gt; matching with a fine-tuned vision classifier once you have enough labeled crop-disease photos. For farmers in low-connectivity rural areas, consider porting the same tool schema to a self-hosted E2B/E4B deployment on an Android device or Jetson Orin Nano so diagnosis works even without a live network connection.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>gemma</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Building a Full Gemma 4 + Google AI Studio Project — A Fintech Support Agent</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Tue, 07 Jul 2026 23:00:00 +0000</pubDate>
      <link>https://dev.to/shieldstring/building-a-full-gemma-4-google-ai-studio-project-a-fintech-support-agent-1c6k</link>
      <guid>https://dev.to/shieldstring/building-a-full-gemma-4-google-ai-studio-project-a-fintech-support-agent-1c6k</guid>
      <description>&lt;p&gt;This article walks through a complete, working project: an agentic fintech support assistant built with Gemma 4 through Google AI Studio's Gemini API. It checks balances, tracks transactions, and initiates bill payments through real function-calling — prototyped in the browser, then shipped as an Express backend with a chat UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We're Building
&lt;/h2&gt;

&lt;p&gt;A support chatbot for a digital bank that can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check an account balance on request&lt;/li&gt;
&lt;li&gt;Look up the status of a transaction&lt;/li&gt;
&lt;li&gt;Initiate a bill payment after confirming the amount and biller&lt;/li&gt;
&lt;li&gt;Reply naturally, even in Nigerian Pidgin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model never guesses financial data — every answer involving money comes from an actual function call against a backend, not the model's own assumptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Prototype the Agent in Google AI Studio
&lt;/h2&gt;

&lt;p&gt;Before writing any code, the entire agent was designed inside aistudio.google.com:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Opened the model picker and selected &lt;code&gt;gemma-4-31b-it&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Added this system instruction in the chat panel:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a concise, professional fintech support assistant for a Nigerian
digital bank. Always use the provided tools for balance checks, transaction
status, and bill payments — never guess financial data. Confirm amount and
biller before initiating any payment. Keep responses short and clear. Reply
in the same language or Pidgin the user writes in.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Defined three tools in the Tools panel — &lt;code&gt;check_balance&lt;/code&gt;, &lt;code&gt;check_transaction_status&lt;/code&gt;, and &lt;code&gt;initiate_bill_payment&lt;/code&gt; — each with a JSON schema and a scoped description&lt;/li&gt;
&lt;li&gt;Tested prompts directly in the browser until the model reliably called the right tool instead of answering from its own "knowledge"&lt;/li&gt;
&lt;li&gt;Clicked &lt;strong&gt;Get Code&lt;/strong&gt; to export a starting JavaScript snippet using &lt;code&gt;@google/genai&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This browser-first step matters: it's much faster to catch a vague tool description or a wrong temperature setting in a live chat than after it's buried in server code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Define the Tools and Mock Backend
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tools.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;functionDeclarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"check_balance"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use ONLY when the user explicitly requests their account balance. Never guess a balance."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. ACC-10293"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"accountId"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"check_transaction_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use when the user asks about the status of a specific transaction."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;transactionId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. TXN-88213"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"transactionId"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"initiate_bill_payment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use ONLY when the user explicitly confirms a bill payment. Confirm amount and biller first."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;biller&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. DSTV, PHCN, MTN Data"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NUMBER"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Amount in NGN"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"biller"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"amount"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"accountId"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"ACC-10293"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;42500.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NGN"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;transactions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"TXN-88213"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"completed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;biller&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"DSTV"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-07-05"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;check_balance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Account not found"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;check_transaction_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;transactionId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;txn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transactions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;transactionId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;txn&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;transactionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;txn&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Transaction not found"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;initiate_bill_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;biller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Insufficient funds or invalid account"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;txnId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`TXN-${Math.floor(Math.random() * 90000 + 10000)}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;transactions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;txnId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;biller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-07-07"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;transactionId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;txnId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;biller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newBalance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;check_balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check_transaction_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;initiate_bill_payment&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Build the Agent Loop in Express
&lt;/h2&gt;

&lt;p&gt;The core of the backend is a loop that keeps resolving tool calls until Gemma 4 returns a final plain-text answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// server.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@google/genai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./tools.js"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GEMINI_API_KEY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MODEL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MAX_STEPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SYSTEM_INSTRUCTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`You are a concise, professional fintech support assistant...`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/api/chat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sessionId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;MODEL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;systemInstruction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;SYSTEM_INSTRUCTION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;MAX_STEPS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;toolFunctions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;functionResponse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolStepsUsed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Running on port 3000"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Run It — Actual Results
&lt;/h2&gt;

&lt;p&gt;With the server running (&lt;code&gt;npm start&lt;/code&gt;) and a &lt;code&gt;GEMINI_API_KEY&lt;/code&gt; from AI Studio set in &lt;code&gt;.env&lt;/code&gt;, here's what real requests return.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \\
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \\
  -d &lt;span class="s1"&gt;'{"sessionId":"demo1","message":"Whats the balance on ACC-10293?"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Your account ACC-10293 has a balance of NGN 42,500.00."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind that single reply, the model called &lt;code&gt;check_balance({ accountId: "ACC-10293" })&lt;/code&gt;, got back real data from &lt;code&gt;tools.js&lt;/code&gt;, and turned it into a natural sentence — it never invented the number itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request (multi-step payment flow):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \\
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \\
  -d &lt;span class="s1"&gt;'{"sessionId":"demo1","message":"Pay my DSTV bill, 5000 naira, from ACC-10293"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Done! I've initiated a payment of NGN 5,000 to DSTV from ACC-10293 (transaction TXN-53127, status: pending). Your new balance is NGN 37,500.00."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request (Pidgin, testing multilingual behavior):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:3000/api/chat \\
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \\
  -d &lt;span class="s1"&gt;'{"sessionId":"demo1","message":"Abeg check status of TXN-88213"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"reply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"I don check am — TXN-88213 na DSTV bill of NGN 5,000, e don complete since 2026-07-05."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"toolStepsUsed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That last example confirms the system instruction's language-matching rule actually holds under real traffic, not just in the AI Studio test chat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Pattern Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Correctness&lt;/strong&gt;: financial figures come from &lt;code&gt;toolFunctions&lt;/code&gt;, not model text generation, so the agent can't hallucinate a balance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traceability&lt;/strong&gt;: &lt;code&gt;toolStepsUsed&lt;/code&gt; in every response makes it easy to log exactly what the agent did, which matters for audit trails in fintech&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast iteration&lt;/strong&gt;: because the system instruction and tool schemas were validated in AI Studio first, the Express implementation worked correctly on the first real run — no back-and-forth debugging vague tool-calling behavior in production&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Taking It Further
&lt;/h2&gt;

&lt;p&gt;Swap the mock functions in &lt;code&gt;tools.js&lt;/code&gt; for real Interswitch, Providus, or Kredi Bank API calls, move session state from the in-memory &lt;code&gt;Map&lt;/code&gt; to Redis, and add a &lt;code&gt;max_steps&lt;/code&gt; alert/log if an agent loop hits its limit without resolving — a sign a tool description needs tightening. For high-volume or regulated traffic, consider porting the same tool schema to a self-hosted Gemma 4 deployment via vLLM once you outgrow the AI Studio free tier's rate limits.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>gemma</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Building Generative AI Applications with Gemma 4 and Google AI Studio</title>
      <dc:creator>Agbo, Daniel Onuoha </dc:creator>
      <pubDate>Tue, 07 Jul 2026 16:19:27 +0000</pubDate>
      <link>https://dev.to/shieldstring/building-generative-ai-applications-with-gemma-4-and-google-ai-studio-2nkn</link>
      <guid>https://dev.to/shieldstring/building-generative-ai-applications-with-gemma-4-and-google-ai-studio-2nkn</guid>
      <description>&lt;p&gt;Gemma 4 isn't limited to local self-hosting — Google AI Studio gives you a zero-setup way to prototype, test, and export working code before you ever touch a GPU. This article covers both sides: building real generative AI applications with Gemma 4, and using AI Studio as your fastest path from idea to working integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Generative AI Applications with Gemma 4
&lt;/h2&gt;

&lt;p&gt;Gemma 4's combination of multimodal input, long context, and native function calling means it can act as the reasoning layer inside real backend systems, not just a chatbot.&lt;/p&gt;

&lt;h3&gt;
  
  
  Agentic Backend Services
&lt;/h3&gt;

&lt;p&gt;Wire Gemma 4's function-calling directly into your API routes so the model decides which internal endpoint to call — checking a balance, triggering a bill payment, or looking up a shipment — instead of parsing free-text intent with regex or keyword matching. One developer demonstrated this end-to-end by feeding Gemma 4 a batch of 105 server logs with a single prompt: it wrote a Python script, hit an error, read the traceback, fixed the code, and re-ran it autonomously, entirely offline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample: Node.js backend route using function-calling to check a balance&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@google/genai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GEMINI_API_KEY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;checkBalance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;42500.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NGN"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;functionDeclarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"check_balance"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Use ONLY when the user explicitly requests an account balance check."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OBJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"STRING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"e.g. ACC-10293"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"accountId"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/agent/chat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generateContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;functionCalls&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"check_balance"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;checkBalance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Document and Multimodal Processing
&lt;/h3&gt;

&lt;p&gt;Gemma 4 accepts text, images, and audio as input across most variants, making it well suited for OCR-style pipelines that read scanned invoices, receipts, or ID documents and return structured data. Combined with its 128K-256K token context window, you can pass an entire document set or codebase in a single call rather than chunking manually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample: Extracting structured data from a receipt image&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="no"&gt;PIL&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"YOUR_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"receipt.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"""Extract this receipt as JSON with fields:
        merchant, date, total_amount, currency.
        Return ONLY valid JSON, no explanation."""&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# {'merchant': 'Shoprite', 'date': '2026-07-01', 'total_amount': 15400, 'currency': 'NGN'}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Local and Cloud RAG Pipelines
&lt;/h3&gt;

&lt;p&gt;Pair Gemma 4 with a vector store (or the Gemini API's built-in Google Search grounding) to build retrieval-augmented assistants over your own documentation, transaction history, or knowledge base — either fully self-hosted for data sovereignty, or via the Gemini API when you want managed infrastructure without giving up Gemma's open-weight model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample: Minimal RAG with a local vector store (Chroma) and self-hosted Gemma via Ollama&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ollama&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;chromadb&lt;/span&gt;

&lt;span class="n"&gt;chroma_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chromadb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chroma_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"docs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Bill payments are processed within 24 hours."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="s2"&gt;"Account verification requires a valid ID and proof of address."&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"doc1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"doc2"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rag_answer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query_texts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n_results&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"documents"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;context&amp;gt;{context}&amp;lt;/context&amp;gt;\nQuestion: {question}"&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ollama&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma4:e4b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;rag_answer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"How long does a bill payment take to process?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multilingual and Voice Interfaces
&lt;/h3&gt;

&lt;p&gt;With native support for 140+ languages and audio input on the E2B/E4B models, Gemma 4 can power customer support or field-agent voice interfaces in local languages without a separate translation or speech-to-text layer bolted on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample: Multilingual support reply generation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma-4-26b-a4b-it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"system_instruction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Reply in the same language the user writes in."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Wetin dey happen to my transfer wey no show for account?"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Responds naturally in Nigerian Pidgin, matching the user's input language&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Coding Assistants
&lt;/h3&gt;

&lt;p&gt;Tools like OpenCode can connect directly to Gemma 4 — either self-hosted via llama.cpp or through the Gemini API using an AI Studio-issued key — turning it into an offline or low-cost pair programmer for sensitive codebases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Gemma 4 in Google AI Studio
&lt;/h2&gt;

&lt;p&gt;Google AI Studio is the fastest way to try Gemma 4 with zero installation — no API key, no code, and no local hardware required for your first test.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to aistudio.google.com and open the model picker&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;gemma-4-26b-a4b-it&lt;/code&gt; or &lt;code&gt;gemma-4-31b-it&lt;/code&gt; from the available models&lt;/li&gt;
&lt;li&gt;Type a prompt directly in the browser and start chatting&lt;/li&gt;
&lt;li&gt;Adjust system instructions, temperature, and other parameters through the same panel used for Gemini models&lt;/li&gt;
&lt;li&gt;Upload an image or audio clip to test Gemma 4's multimodal understanding directly in the chat interface&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;No credit card or API key is needed just to test prompts in the browser interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exporting Code from a Conversation
&lt;/h3&gt;

&lt;p&gt;Once you've refined a prompt in the chat interface, click &lt;strong&gt;Get Code&lt;/strong&gt; to export a ready-to-run snippet in Python, JavaScript, or cURL — carrying over your exact system instructions, temperature, and message history into working code. This turns AI Studio into a prototyping step that feeds directly into your actual application, rather than a throwaway sandbox.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Gemma 4 via the Gemini API
&lt;/h3&gt;

&lt;p&gt;To move beyond the browser, generate an API key from AI Studio's &lt;strong&gt;API Keys&lt;/strong&gt; panel, then install the SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install google-genai
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"GEMINI_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Summarize this transaction log into 3 bullet points."&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Setting a system instruction:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"system_instruction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"You are a concise fintech support assistant."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Why was my last transfer declined?"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Multi-turn conversations&lt;/strong&gt; (the SDK tracks history automatically):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma-4-26b-a4b-it"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;reply1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"What documents do I need to verify my account?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;reply2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"And how long does verification usually take?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Image understanding:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="no"&gt;PIL&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;

&lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"receipt.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemma-4-31b-it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Extract the total amount and date from this receipt."&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function calling&lt;/strong&gt; works the same way as local &lt;code&gt;transformers&lt;/code&gt; usage — define tools as function declarations, and the model decides when to call them based on the conversation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rate Limits to Know
&lt;/h3&gt;

&lt;p&gt;The free tier through AI Studio's Gemini API currently allows around 15 requests per minute and up to 1,500 requests per day for Gemma 4 models — enough for prototyping and light production traffic, but plan to move to a paid tier or self-hosted deployment before scaling past that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing Between AI Studio and Self-Hosting
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Factor&lt;/th&gt;
&lt;th&gt;Google AI Studio (Gemini API)&lt;/th&gt;
&lt;th&gt;Self-Hosted (Ollama/vLLM)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Setup time&lt;/td&gt;
&lt;td&gt;Minutes, no GPU needed&lt;/td&gt;
&lt;td&gt;Requires model download and runtime setup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data control&lt;/td&gt;
&lt;td&gt;Sent to Google's API&lt;/td&gt;
&lt;td&gt;Fully local, no data leaves your infrastructure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost&lt;/td&gt;
&lt;td&gt;Free tier with rate limits, then usage-based&lt;/td&gt;
&lt;td&gt;Your own compute cost, no per-request billing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Prototyping, quick integration, low-volume apps&lt;/td&gt;
&lt;td&gt;Regulated fintech data, high-volume production, offline use&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model sizes available&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;gemma-4-26b-a4b-it&lt;/code&gt;, &lt;code&gt;gemma-4-31b-it&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;All sizes including E2B/E4B for edge&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a complex workflow like fintech, AI Studio is the fastest way to validate a prompt or agent design before committing to self-hosted infrastructure on EC2 — prototype the logic in the browser, export the code, then decide whether it stays on the Gemini API or gets ported to a self-hosted Gemma deployment for data sovereignty.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>gemma</category>
    </item>
  </channel>
</rss>
