<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged gemma</title>
<link>https://coderlegion.com/tag/gemma</link>
<description>Powered by Question2Answer</description>
<item>
<title>Solace: A Global Mental Health First Responder Built with Gemma 4</title>
<link>https://coderlegion.com/19609/solace-a-global-mental-health-first-responder-built-with-gemma-4</link>
<description>&lt;h3 id=&quot;the-problem-nobody-talks-about&quot;&gt;The Problem Nobody Talks About&lt;/h3&gt;
&lt;p&gt;970 million people worldwide live with mental health disorders.&lt;/p&gt;
&lt;p&gt;But almost every mental health tool built with AI assumes the same user: fast internet, English as a first language, a US or UK phone number to call in a crisis.&lt;/p&gt;
&lt;p&gt;That's not 970 million people. That's maybe 50 million.&lt;/p&gt;
&lt;p&gt;I'm a developer based in Lagos, Nigeria. When I looked at the mental health AI tools being built, I kept asking the same question: &lt;strong&gt;what happens when someone in Accra, Nairobi, Manila, or São Paulo needs help at 2am?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;They get a chatbot that tells them to call 988.&lt;/p&gt;
&lt;p&gt;That's the gap Solace was built to close.&lt;/p&gt;
&lt;h3 id=&quot;what-is-solace-&quot;&gt;What is Solace?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Solace&lt;/strong&gt; is a voice-first, privacy-focused mental health companion powered by Gemma 4. It listens, assesses, and connects people to real help — wherever they are in the world.&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;Live app:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://slcai-sm9m.vercel.app/&quot;&gt;https://slcai-sm9m.vercel.app/&lt;/a&gt;&lt;br&gt;
 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/sam-the-champ/SLCAI&quot;&gt;https://github.com/sam-the-champ/SLCAI&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Demo Video:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/8gFdeSJF3zQ&quot;&gt;&lt;img src=&quot;https://img.youtube.com/vi/8gFdeSJF3zQ/hqdefault.jpg&quot; alt=&quot;Watch Video&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;what-makes-solace-different&quot;&gt;What makes Solace different&lt;/h3&gt;
&lt;h4 id=&quot;1-localized-crisis-resources-for-13-countries&quot;&gt;1.  Localized crisis resources for 13+ countries&lt;/h4&gt;
&lt;p&gt;Most mental health AI tools are built with US resources baked in. If you're not American, you're on your own.&lt;/p&gt;
&lt;p&gt;Solace auto-detects your country from your browser timezone and immediately surfaces the right crisis lines, text lines, and chat services for &lt;strong&gt;Nigeria, Ghana, Kenya, South Africa, Zimbabwe, India, UK, USA, Canada, Australia, Philippines, Singapore, Brazil&lt;/strong&gt; — and falls back to international resources for everywhere else.&lt;/p&gt;
&lt;p&gt;No settings. No configuration. It just knows.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;export function getResourcesByTimezone(): CountryResources {
  const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
  const tzToCountry: Record&amp;lt;string, string&amp;gt; = {
    'Africa/Lagos': 'NG',
    'Africa/Accra': 'GH',
    'Africa/Nairobi': 'KE',
    // ...13+ countries
  }
  const code = tzToCountry[tz]
  return resourcesByCountry[code] ?? resourcesByCountry.DEFAULT
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-voice-first-input&quot;&gt;2.  Voice-first input&lt;/h4&gt;
&lt;p&gt;When someone is in distress, typing is a barrier. Solace has a one-tap voice input powered by the Web Speech API — speak your feelings, Solace listens.&lt;/p&gt;
&lt;p&gt;No third-party API. No extra cost. Works in the browser natively.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
recognition.continuous = true
recognition.interimResults = true
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-trauma-informed-triage-with-gemma-4&quot;&gt;3.  Trauma-informed triage with Gemma 4&lt;/h4&gt;
&lt;p&gt;Every message is assessed across four triage levels: &lt;strong&gt;Low → Moderate → High → Crisis&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Gemma 4's 128K context window and deep instruction-following made it the right model for this. The system prompt is carefully crafted to avoid clinical coldness while still being precise enough to catch crisis signals:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;// Triage levels:
// low: mild everyday stress, general worry
// moderate: persistent sadness, sleep issues, social withdrawal  
// high: panic attacks, trauma symptoms, major crisis
// crisis: suicidal ideation, self-harm, immediate danger
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At crisis level, the entire UI shifts — emergency resources move to the top, the call button becomes prominent, and the AI's tone changes to prioritize connection to real help over conversation.&lt;/p&gt;
&lt;h4 id=&quot;4-private-mood-journal&quot;&gt;4.  Private mood journal&lt;/h4&gt;
&lt;p&gt;Every check-in is saved to a local mood journal — stored entirely in &lt;code&gt;localStorage&lt;/code&gt;. No server. No account. No data leaving the device.&lt;/p&gt;
&lt;p&gt;Users can track patterns across sessions: when they tend to feel worse, whether things are improving, what their check-ins look like over time.&lt;/p&gt;
&lt;h4 id=&quot;5-installable-pwa&quot;&gt;5.  Installable PWA&lt;/h4&gt;
&lt;p&gt;Solace is a Progressive Web App. On mobile, users can install it directly to their home screen — no app store, no download, works in low-bandwidth conditions.&lt;/p&gt;
&lt;p&gt;This matters enormously in markets like Nigeria where data costs are high and storage is limited. A 2MB installable app beats a 200MB download every time.&lt;/p&gt;
&lt;h3 id=&quot;why-gemma-4-specifically-&quot;&gt;Why Gemma 4 specifically?&lt;/h3&gt;
&lt;p&gt;This is the question that matters most, so let me be direct.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I chose Gemma 4 31B because:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. The 128K context window&lt;/strong&gt; means Solace can hold a full therapeutic conversation — not just one or two turns. Mental health support isn't transactional. People circle back. They contradict themselves. They need to feel heard across a long exchange.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Instruction-following precision&lt;/strong&gt; — the triage system depends on Gemma 4 returning structured JSON reliably, with emotional nuance baked into the &lt;code&gt;summary&lt;/code&gt;, &lt;code&gt;patterns&lt;/code&gt;, &lt;code&gt;strategies&lt;/code&gt;, and &lt;code&gt;affirmation&lt;/code&gt; fields. I tested with smaller models. The quality gap was significant.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. It's open.&lt;/strong&gt; Gemma 4 can be self-hosted. That means a clinic in Lagos or a NGO in Nairobi could eventually run this on their own infrastructure, with no API costs and full data sovereignty. That's a future worth building toward.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Privacy story.&lt;/strong&gt; Every conversation stays between the user and the model. Solace doesn't log, store, or transmit conversation data. For mental health, that's not a feature — it's a requirement.&lt;/p&gt;
&lt;h3 id=&quot;technical-stack&quot;&gt;Technical Stack&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Frontend:&lt;/strong&gt; React + Vite + TypeScript&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Styling:&lt;/strong&gt; CSS custom properties, glassmorphism UI, no component library&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AI:&lt;/strong&gt; Gemma 4 31B via OpenRouter&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Voice:&lt;/strong&gt; Web Speech API (native browser)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Storage:&lt;/strong&gt; localStorage (journal, no server)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PWA:&lt;/strong&gt; Web App Manifest + service worker ready&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deploy:&lt;/strong&gt; Vercel&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-hardest-part&quot;&gt;The hardest part&lt;/h3&gt;
&lt;p&gt;Building the crisis response flow was the hardest and most important part of this project.&lt;/p&gt;
&lt;p&gt;When Gemma 4 returns &lt;code&gt;triageLevel: &quot;crisis&quot;&lt;/code&gt;, everything changes. The UI shifts to red. The emergency number for the user's country moves above the fold. The AI's system prompt switches to a mode focused entirely on staying present and bridging to real help — not providing therapy.&lt;/p&gt;
&lt;p&gt;Getting that balance right — compassionate but not clinical, urgent but not alarming — took more iteration than anything else in the codebase.&lt;/p&gt;
&lt;h3 id=&quot;what-s-next&quot;&gt;What's next&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Offline-first fallback responses&lt;/strong&gt; — cached grounding techniques that work with no internet&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;More languages&lt;/strong&gt; — French, Hausa, Swahili, Portuguese&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;More countries&lt;/strong&gt; — currently 13, targeting 30+&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NGO partnership mode&lt;/strong&gt; — white-label for mental health organizations&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;try-it&quot;&gt;Try it&lt;/h3&gt;
&lt;p&gt; &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://slcai-sm9m.vercel.app/&quot;&gt;https://slcai-sm9m.vercel.app/&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Open it on your phone. Tap a mood. Speak how you're feeling. See what country resources appear for you.&lt;/p&gt;
&lt;p&gt;If you're building in the mental health space or you work with communities that are underserved by current AI tools — I'd love to hear from you in the comments.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Solace is an AI companion, not a therapist or medical service. If you are in crisis, please contact your local emergency services.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/19609/solace-a-global-mental-health-first-responder-built-with-gemma-4</guid>
<pubDate>Wed, 03 Jun 2026 19:37:18 +0000</pubDate>
</item>
<item>
<title>Which Gemma 4 Model Should You Actually Use? I Tested All of Them, So You Don't Have To</title>
<link>https://coderlegion.com/19566/which-gemma-4-model-should-you-actually-use-i-tested-all-of-them-so-you-dont-have-to</link>
<description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a rel=&quot;nofollow&quot; href=&quot;https://dev.to/challenges/google-gemma-2026-05-06&quot;&gt;Gemma 4 Challenge: Write About Gemma 4&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Which Gemma 4 Model Should You Actually Use? I Tested All of them, building a Healthcare AI for African Patients&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Most model comparison posts are written by people who read the documentation. This one is written by someone who burned through tokens, hit OOM errors, watched Gemini miss clinical signals it should have caught, and eventually landed on the right answer, but only after eliminating everything else first.&lt;/p&gt;
&lt;p&gt;I was building Fisibel, a multimodal African synthetic health data platform. The task: upload a real Nigerian hospital record image, extract clinical signals, and generate privacy-safe synthetic datasets grounded in WHO and World Bank statistics. The model had to read handwritten and printed medical documents, understand African-specific clinical patterns, and generate coherent synthetic data at scale.&lt;/p&gt;
&lt;p&gt;Here is what I learned by testing every Gemma 4 option available.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Model &lt;/th&gt;&lt;th&gt;Parameters &lt;/th&gt;&lt;th&gt;Architecture &lt;/th&gt;&lt;th&gt;Best For&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Gemma 4 E2B &lt;/td&gt;&lt;td&gt;2B effective &lt;/td&gt;&lt;td&gt;Dense &lt;/td&gt;&lt;td&gt;On-device, mobile, offline&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Gemma 4 26B MoE &lt;/td&gt;&lt;td&gt;26B total, 4B active &lt;/td&gt;&lt;td&gt;Mixture-of-Experts &lt;/td&gt;&lt;td&gt;Edge inference, deep reasoning&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Gemma 4 31B &lt;/td&gt;&lt;td&gt;31B total &lt;/td&gt;&lt;td&gt;Dense &lt;/td&gt;&lt;td&gt;Maximum quality, unconstrained compute&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The architectural difference matters more than the number. Let me explain why.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What Mixture-of-Experts Actually Means in Practice&lt;/strong&gt;&lt;br&gt;
Most explanations of MoE are theoretical. Here is the practical version.&lt;br&gt;
A dense model activates all its parameters for every token it processes. A 31B dense model is doing 31B parameters of work on every single token — whether that token is &quot;the&quot; or &quot;malaria strain variant specific to Lagos State.&quot;&lt;br&gt;
A MoE model routes each token through specialized subnetworks called experts. Only a subset activates per token. Gemma 4 26B MoE has 26B total parameters but activates only ~4B per forward pass.&lt;br&gt;
What this means for you:&lt;/p&gt;
&lt;p&gt;Inference speed: closer to a 4B model&lt;br&gt;
Knowledge depth: closer to a 26B model&lt;br&gt;
For specialized tasks: the right experts activate for the right content&lt;/p&gt;
&lt;p&gt;That last point is the one that changed my project. When processing clinical documents, MoE routes medical terminology, geographic identifiers, and symptom patterns through subnetworks shaped by that kind of content. A dense model processes a Nigerian hospital record exactly the same way it processes a recipe.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why I Started With Ollama and Had to Stop&lt;/strong&gt;&lt;br&gt;
The original Fisibel architecture was local inference via Ollama. If the platform handles real hospital record images, keeping inference local meant zero data leaving the machine. Maximum privacy. No transmission risk.&lt;br&gt;
It did not survive contact with reality.&lt;br&gt;
Downloading Gemma 4 locally through Ollama required pulling a model that was simply too large. In Nigeria, where data costs real money, the download cost alone made the pipeline economically unviable. African healthcare researchers operating in bandwidth-constrained environments cannot build on infrastructure that demands gigabytes just to get started.&lt;br&gt;
Lesson: Local inference is the right privacy instinct. But in bandwidth-constrained environments, the data cost of the initial model download is a real barrier, not an abstract one. If you are building for users outside fibre-connected cities, factor this in before you architect around Ollama.&lt;br&gt;
This pushed the pipeline to Google Cloud — not by preference, but by the economic reality of what local inference actually costs when you are not building from San Francisco.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why I Rejected Gemma 4 31B&lt;/strong&gt;&lt;br&gt;
Once on cloud inference, the natural assumption was that bigger meant better. Gemma 4 31B was tested first.&lt;br&gt;
It was not better. It was more expensive for the same output.&lt;br&gt;
For clinical signal extraction specifically — reading a hospital record and pulling out diagnoses, symptoms, treatment patterns, geographic identifiers — the 31B model burned tokens significantly faster without producing meaningfully deeper clinical signals than 26B MoE.&lt;br&gt;
The task does not reward raw parameter count. It rewards specialized reasoning over structured medical text. Paying more tokens for marginal returns on a pipeline that needs to run at scale across African health datasets is not a tradeoff worth making.&lt;br&gt;
When to use 31B: Maximum quality tasks where compute cost is not a constraint. Long-form generation. Complex reasoning chains where you need every parameter engaged. Research environments, not production pipelines running at scale.&lt;br&gt;
When not to use 31B: Specialized extraction tasks. Scale-sensitive pipelines. Anything where you will run the model hundreds or thousands of times.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why I Tested Gemini and What the Results Actually Showed&lt;/strong&gt;&lt;br&gt;
Gemini was the obvious alternative. Same multimodal capability, faster inference, Google infrastructure. I tested it directly against Gemma 4 26B MoE on the same Lagos hospital record image.&lt;br&gt;
Gemini was faster. On clinical depth, it lost.&lt;br&gt;
The table below shows clinical signals extracted from the same input document across both models:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Clinical Signal Extracted &lt;/th&gt;&lt;th&gt;Gemma 4 26B MoE &lt;/th&gt;&lt;th&gt;Gemini&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Primary diagnosis &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Comorbidity pattern &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Malaria strain variant &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;LGA-specific risk factor &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Regional treatment protocol &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Symptom progression timeline &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Geographic disease indicator &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Age-adjusted risk signal &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Local drug resistance pattern &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Nutritional comorbidity flag &lt;/td&gt;&lt;td&gt;✅ &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Gemini caught the general signals. Gemma 4 26B MoE caught the African-specific ones.&lt;br&gt;
No other model in this size class caught all 6 African-specific signals.&lt;br&gt;
This is not a criticism of Gemini. It is a demonstration of what MoE routing does on specialized content. The signals Gemini missed are not obscure — LGA-specific risk factors and regional treatment protocols are standard clinical identifiers in Nigerian medical documents. The difference is in how each model processes domain-specific terminology.&lt;br&gt;
Speed is not always the metric. For specialized extraction tasks, coverage is.&lt;br&gt;
| Use Case | Recommended Model |&lt;br&gt;
| Mobile / on-device / offline | Gemma 4 E2B |&lt;br&gt;
| Specialized domain extraction at scale | Gemma 4 26B MoE |&lt;br&gt;
| Maximum quality, unconstrained compute | Gemma 4 31B |&lt;br&gt;
| Bandwidth-constrained environments | Gemma 4 26B MoE via cloud |&lt;br&gt;
| Research and fine-tuning experiments | Gemma 4 31B |&lt;br&gt;
| Production pipelines with token cost sensitivity | Gemma 4 26B MoE |&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Choose Gemma 4 E2B if:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You are building for mobile or on-device&lt;/li&gt;
&lt;li&gt;Your users have bandwidth or storage constraints&lt;/li&gt;
&lt;li&gt;You need offline capability after the first setup&lt;/li&gt;
&lt;li&gt;Your task is classification, routing, or simple generation&lt;/li&gt;
&lt;li&gt;You are targeting Android phones under $200&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Choose Gemma 4 26B MoE if:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You need reasoning depth at edge-level inference speed&lt;/li&gt;
&lt;li&gt;Your task involves specialized domain content — medical, legal, scientific, and regional&lt;/li&gt;
&lt;li&gt;You are running at scale, and token cost matters&lt;/li&gt;
&lt;li&gt;You need the best quality-to-cost ratio in production&lt;/li&gt;
&lt;li&gt;You want MoE expert routing to work in your favour on specialized inputs&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Choose Gemma 4 31B if:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Compute cost is not a constraint&lt;/li&gt;
&lt;li&gt;You need maximum quality on complex generation tasks&lt;/li&gt;
&lt;li&gt;You are doing research, fine-tuning experiments, or one-off analysis&lt;/li&gt;
&lt;li&gt;Latency is less important than output quality&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;The One Thing Nobody Tells You About Thinking Mode&lt;/strong&gt;&lt;br&gt;
Gemma 4 supports thinking traces. I assumed more thinking meant better answers everywhere. That assumption broke two features before I understood what was actually happening.&lt;br&gt;
Thinking mode helps when the model needs to route across multiple options — tool selection, complex reasoning, and ambiguous queries. It hurts when the task is pure structured output composition. With thinking enabled on a structured generation path, the model spends its entire token budget on internal reasoning traces and produces empty or malformed output.&lt;br&gt;
The rule I now follow: thinking ON for routing, thinking OFF for composition. They are different tasks and the model treats them differently.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What This Means for Open Source AI&lt;/strong&gt;&lt;br&gt;
Gemma 4 26B MoE running on Google Cloud infrastructure, with no proprietary lock-in, matching or exceeding closed models on specialized domain tasks — that is not a minor footnote. That is the story.&lt;br&gt;
For developers building in bandwidth-constrained environments, for researchers working on underrepresented populations, for anyone who needs frontier-level reasoning without frontier-level costs, the gap between open and closed models just got significantly smaller.&lt;br&gt;
The model I needed to see African clinical signals clearly was not the biggest one. It was not the fastest one. It was the one built to route specialized knowledge to the right place.&lt;br&gt;
That turns out to matter more than size.&lt;/p&gt;
&lt;p&gt;I built this while developing Fisibel, a multimodal African synthetic health data platform. The clinical signals table above came from real tests on a Lagos hospital record. All findings are from production pipeline decisions, not benchmarks run for this post.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/19566/which-gemma-4-model-should-you-actually-use-i-tested-all-of-them-so-you-dont-have-to</guid>
<pubDate>Wed, 03 Jun 2026 11:35:01 +0000</pubDate>
</item>
<item>
<title>Your Laptop Just Got Smarter: A Complete Guide to Gemma 4's Four Models</title>
<link>https://coderlegion.com/18966/your-laptop-just-got-smarter-a-complete-guide-to-gemma-4s-four-models</link>
<description>&lt;p&gt;Gemma 4 is quietly one of the most important open-source AI milestones of the year. Released by Google under the commercially permissive Apache 2.0 license, this generation allows you to run frontier-level multimodal applications entirely on your own hardware, ensuring your data never leaves your machine.&lt;/p&gt;
&lt;p&gt;What makes this release fundamentally different from previous generations is its architectural philosophy. Instead of releasing simple &quot;small, medium, and large&quot; checkpoints of the exact same model, Google built three architecturally distinct variants, each specifically optimized to solve a particular hardware bottleneck.&lt;/p&gt;
&lt;p&gt;Let's break down how to get started, analyze what's happening under the hood, and map out exactly which variant fits your specific setup.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;quick-start-deployment-under-60-seconds&quot;&gt;&lt;strong&gt;Quick-Start Deployment (Under 60 Seconds&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The fastest method for local deployment is via Ollama, which automatically handles hardware detection, quantization, and local memory management.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Standard Local Run:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;ollama run gemma4
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Production &amp;amp; Containerized Deployments:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Start the Ollama background service
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

# Execute the model within the container
docker exec -it ollama ollama run gemma4
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For graphical interfaces or advanced production batching, plug these weights directly into LM Studio (zero-friction UI) or vLLM (high-throughput enterprise serving).&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;architectural-comparison-matrix&quot;&gt;&lt;strong&gt;Architectural Comparison Matrix&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;To choose the correct model, you must understand your system's hardware constraints. Here's the technical breakdown at Q4 quantization:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Aspect &lt;/th&gt;&lt;th&gt;E2B &amp;amp; E4B (Edge) &lt;/th&gt;&lt;th&gt;26B A4B (Sparse) &lt;/th&gt;&lt;th&gt;31B (Dense)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Total Parameters &lt;/td&gt;&lt;td&gt;5.1B / 8.0B &lt;/td&gt;&lt;td&gt;25.2B &lt;/td&gt;&lt;td&gt;30.7B&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Active Parameters &lt;/td&gt;&lt;td&gt;All fire &lt;/td&gt;&lt;td&gt;3.8B per token &lt;/td&gt;&lt;td&gt;All fire&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Architecture &lt;/td&gt;&lt;td&gt;Dense + Per-Layer Embeddings &lt;/td&gt;&lt;td&gt;128-Expert Routing &lt;/td&gt;&lt;td&gt;Hybrid Interleaved Attention&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Context Window&lt;/td&gt;&lt;td&gt;128K &lt;/td&gt;&lt;td&gt;256K &lt;/td&gt;&lt;td&gt;256K&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Speed (RTX 4090) &lt;/td&gt;&lt;td&gt;110+ tokens/sec &lt;/td&gt;&lt;td&gt;~95 tokens/sec &lt;/td&gt;&lt;td&gt;~35 tokens/sec&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;VRAM (Q4) &lt;/td&gt;&lt;td&gt;3.2GB / 6.0GB &lt;/td&gt;&lt;td&gt;~15GB &lt;/td&gt;&lt;td&gt;~19GB&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Modalities &lt;/td&gt;&lt;td&gt;Text, Image, Audio &lt;/td&gt;&lt;td&gt;Text, Image, Video &lt;/td&gt;&lt;td&gt;Text, Image, Video&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Best For &lt;/td&gt;&lt;td&gt;Phones, Pi 5, Laptops &lt;/td&gt;&lt;td&gt;Single Consumer GPU &lt;/td&gt;&lt;td&gt;Dual GPU Workstations&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-three-distinct-architectures&quot;&gt;&lt;strong&gt;The Three Distinct Architectures&lt;/strong&gt;&lt;/h3&gt;
&lt;h4 id=&quot;architecture-1-edge-variants-e2b-amp-e4b-dense-with-per-layer-embeddings&quot;&gt;Architecture 1: Edge Variants (E2B &amp;amp; E4B) — Dense with Per-Layer Embeddings&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Bottleneck:&lt;/strong&gt;&lt;br&gt;
In standard transformers, the token embedding table sits as a massive lookup at the entry point. For smaller models, this alone consumes 500MB–1GB of VRAM before processing anything. On an 8GB Raspberry Pi or smartphone, this kills performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Solution: Per-Layer Embeddings (PLE)&lt;/strong&gt;&lt;br&gt;
The E-series distributes this massive table into independent, compressed lookups across all layers (35 for E2B; 42 for E4B):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;[Token ID] ──&amp;gt; [Layer 1 + Mini Lookup] ──&amp;gt; [Layer 2 + Mini Lookup] ──&amp;gt; [Output]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Memory footprint spreads evenly across cache lines, hitting CPU/GPU caches far more efficiently. Combined with 4-bit quantization, E2B drops to 3.2GB.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Secret Weapon: Native Audio Encoding&lt;/strong&gt;&lt;br&gt;
The E-series includes a 300M parameter native audio encoder baked directly into the latent space:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;[Old Way]:     Audio ──&amp;gt; Whisper ──&amp;gt; Text ──&amp;gt; LLM (1500ms latency)
[Gemma 4 E]:   Audio ──&amp;gt; [Native Encoder] ──&amp;gt; Shared Latent Space (50–200ms)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By eliminating the text-translation middleman, end-to-end voice processing latency drops dramatically, enabling true real-time offline voice orchestration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to Choose E2B or E4B:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;E2B:&lt;/strong&gt; Mobile apps, IoT, Raspberry Pi 5, privacy-critical applications&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;E4B:&lt;/strong&gt; Local code assistants, voice-first apps, laptops without GPU (the Goldilocks choice)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;architecture-2-sparse-variant-26b-a4b-mixture-of-experts&quot;&gt;Architecture 2: Sparse Variant (26B A4B) — Mixture of Experts&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Bottleneck:&lt;/strong&gt;&lt;br&gt;
You need the conceptual depth of a 26B model on a single consumer GPU (RTX 3090/4090) without sacrificing token speed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Solution: 128-Expert Top-8 Routing&lt;/strong&gt;&lt;br&gt;
Gemma 4 A4B contains 25.2B parameters split into 128 fractional experts (~200M each). For every token, a router fires only 8 experts + 1 permanently active shared expert:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;[Input Token] ──&amp;gt; [Router]
                    ├──&amp;gt; [Expert 003] ──┐
                    ├──&amp;gt; [Expert 042] ──┼──&amp;gt; [Fused  Output]
                    └──&amp;gt; [Shared Exp]  ──┘
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The Math:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Total params in VRAM: 25.2B&lt;/li&gt;
&lt;li&gt;Active params per token: 8 × 200M + 500M (shared) = &lt;strong&gt;3.8B&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;FLOPs per token: ~12% of dense 26B&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Result: 95 tokens/sec on RTX 4090&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You get 26B-level reasoning at 4B-level speed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to Choose 26B A4B:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Real-time chat applications&lt;/li&gt;
&lt;li&gt;Agentic workflows with function-calling&lt;/li&gt;
&lt;li&gt;Code generation and debugging&lt;/li&gt;
&lt;li&gt;Running 24/7 on a single consumer GPU&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;architecture-3-dense-flagship-31b-maximum-reasoning-depth&quot;&gt;Architecture 3: Dense Flagship (31B) — Maximum Reasoning Depth&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Bottleneck:&lt;/strong&gt;&lt;br&gt;
Processing massive code repositories or 100-page documents inside 256K context windows causes the KV cache to explode, overwhelming VRAM.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Solution: Shared KV Cache &amp;amp; Hybrid Interleaved Attention&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Shared KV Cache (Final Layers):&lt;/strong&gt;&lt;br&gt;
Layers 1–54 compute full KV tensors; layers 55–60 reuse them. This slashes peak VRAM by 14% during long-context runs (~10GB savings on 256K inference).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hybrid Interleaved Attention:&lt;/strong&gt;&lt;br&gt;
The model alternates in a 5:1 ratio:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;5 layers of Sliding Window Attention ($O(N \times W)$ complexity, localized)&lt;/li&gt;
&lt;li&gt;1 layer of Global Attention ($O(N^2)$ complexity, full context)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Higher layers &quot;see&quot; far-back information via intermediate representations without exponential memory explosion.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thinking Mode:&lt;/strong&gt;&lt;br&gt;
The 31B features explicit Thinking Mode (invoked via &lt;code&gt;&amp;lt;|think|&amp;gt;&lt;/code&gt; token). The model allocates dedicated tokens for chain-of-thought steps, pushing performance to Candidate Master level (2150 Elo on competitive programming).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to Choose 31B:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Research and complex reasoning&lt;/li&gt;
&lt;li&gt;Fine-tuning on domain-specific tasks&lt;/li&gt;
&lt;li&gt;Building production API servers&lt;/li&gt;
&lt;li&gt;Processing 100+ page documents&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;real-world-scenarios-what-to-build&quot;&gt;&lt;strong&gt;Real-World Scenarios: What to Build&lt;/strong&gt;&lt;/h3&gt;
&lt;h4 id=&quot;scenario-1-local-code-assistant-github-copilot-alternative-&quot;&gt;Scenario 1: Local Code Assistant (GitHub Copilot Alternative)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Best choice: E4B or 26B MoE&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;E4B:&lt;/strong&gt; MacBook Air, instant suggestions, no GPU needed. Responds in 20–40ms—fast enough that you don't break flow state.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;26B MoE:&lt;/strong&gt; Better code understanding, still lightning-fast at 8–12ms latency. Catches subtle bugs that E4B might miss.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# E4B on MacBook (no GPU)
ollama run gemma4:4b-e4b
# Type a function signature, get completions instantly

# 26B MoE on RTX 4090
ollama run gemma4:26b-a4b
# Same quality, even faster
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why not 31B?&lt;/strong&gt; The 31B scores 80% on LiveCodeBench (competitive programming) and Codeforces Elo 2150 (&quot;Candidate Master&quot;)—amazing for research. But for line-by-line code completion, the 2–3ms speed difference compounds: you get more suggestions per minute, better UX, happier developers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Real example:&lt;/strong&gt; Feed E4B a buggy function, ask &quot;what's wrong with this?&quot; You get instant feedback without sending code anywhere. Your data stays on your machine.&lt;/p&gt;
&lt;h4 id=&quot;scenario-2-agentic-chatbot-with-tool-calling&quot;&gt;Scenario 2: Agentic Chatbot with Tool Calling&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Best choice: 26B MoE&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The sparse architecture excels at agentic workflows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Router network decides which tools to call (based on input relevance)&lt;/li&gt;
&lt;li&gt;Only 3.8B active parameters fire (fast routing decision)&lt;/li&gt;
&lt;li&gt;Shared expert validates logic and integrates results&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;# Pseudo-code for agentic workflow
response = client.chat.completions.create(
    model=&quot;gemma4:26b-a4b&quot;,
    messages=[
        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Find and summarize all PDFs in this folder.&quot;}
    ],
    tools=[
        {&quot;name&quot;: &quot;list_files&quot;, &quot;description&quot;: &quot;List files in directory&quot;},
        {&quot;name&quot;: &quot;read_pdf&quot;, &quot;description&quot;: &quot;Extract text from PDF&quot;},
        {&quot;name&quot;: &quot;summarize&quot;, &quot;description&quot;: &quot;Summarize text&quot;}
    ]
)
# MoE routing activates only the relevant experts for each step
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why?&lt;/strong&gt; E4B lacks reasoning depth for multi-step workflows. 31B is overkill—26B MoE handles this perfectly at 3× the speed.&lt;/p&gt;
&lt;h4 id=&quot;scenario-3-fine-tuning-on-domain-specific-tasks&quot;&gt;Scenario 3: Fine-Tuning on Domain-Specific Tasks&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Best choice: 31B Dense&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Only 31B has sufficient reasoning depth to absorb domain-specific patterns without overfitting. Perfect for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Medical language understanding&lt;/li&gt;
&lt;li&gt;Legal document analysis&lt;/li&gt;
&lt;li&gt;Custom company knowledge bases&lt;/li&gt;
&lt;li&gt;Scientific paper comprehension&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import get_peft_model, LoraConfig
from transformers import Trainer, TrainingArguments

model = AutoModelForCausalLM.from_pretrained(
    &quot;google/gemma-4-31b&quot;,
    load_in_8bit=True,
    device_map=&quot;auto&quot;
)
tokenizer = AutoTokenizer.from_pretrained(&quot;google/gemma-4-31b&quot;)

# Apply LoRA to reduce fine-tuning VRAM
config = LoraConfig(
    r=64,
    lora_alpha=128,
    lora_dropout=0.05,
    task_type=&quot;CAUSAL_LM&quot;
)
model = get_peft_model(model, config)

# Train on your domain data
training_args = TrainingArguments(
    output_dir=&quot;./gemma-4-finetuned&quot;,
    num_train_epochs=3,
    per_device_train_batch_size=4,
    learning_rate=2e-4,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=your_dataset,
    tokenizer=tokenizer
)

trainer.train()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E4B is too small. 26B MoE's routing strategy complicates fine-tuning. 31B is the Goldilocks choice.&lt;/p&gt;
&lt;h4 id=&quot;scenario-4-raspberry-pi-5-voice-assistant&quot;&gt;Scenario 4: Raspberry Pi 5 Voice Assistant&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Only choice: E2B&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At Q4 quantization (3.2GB), E2B is the only model that fits on a Pi 5. Native audio encoding (no Whisper dependency) enables:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;ollama run gemma4:2b-e2b
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now build:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Voice-activated assistant:&lt;/strong&gt; &quot;Hey Gemma, what's the weather?&quot; → Runs entirely offline&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Offline translation:&lt;/strong&gt; Speak English, get Japanese response—no internet needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Smart home control:&lt;/strong&gt; Voice commands executed locally, no cloud latency&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Privacy-first deployment:&lt;/strong&gt; All processing on-device, zero external API calls&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The 300M native audio encoder eliminates latency. Total response time: 100–300ms from speech to response. Try doing that with Whisper + a cloud LLM.&lt;/p&gt;
&lt;h4 id=&quot;scenario-5-research-amp-complex-reasoning&quot;&gt;Scenario 5: Research &amp;amp; Complex Reasoning&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Best choice: 31B Dense&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When you need multi-hop reasoning, novel problem-solving, or deep semantic understanding:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;# Example: Ask the model to reason through a complex problem
response = client.chat.completions.create(
    model=&quot;gemma4:31b&quot;,
    messages=[{
        &quot;role&quot;: &quot;user&quot;,
        &quot;content&quot;: &quot;Given 100 academic papers in this folder, identify emerging research trends and map how they're connected.&quot;
    }],
    extra_body={
        &quot;thinking_mode&quot;: &quot;enabled&quot;,
        &quot;max_thinking_tokens&quot;: 1500  # Let it think deeply
    }
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;31B has the capacity to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Process 256K-token documents (100+ pages) in a single context&lt;/li&gt;
&lt;li&gt;Perform chain-of-thought reasoning with visible thinking steps&lt;/li&gt;
&lt;li&gt;Handle novel problems it wasn't explicitly trained on&lt;/li&gt;
&lt;li&gt;Fine-tune on niche domains without degrading general capability&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;E2B and E4B can't handle this. 26B MoE can, but slightly less reliably on truly novel tasks.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;production-implementation-examples&quot;&gt;&lt;strong&gt;Production Implementation Examples&lt;/strong&gt;&lt;/h3&gt;
&lt;h4 id=&quot;initializing-thinking-modes-via-python&quot;&gt;Initializing Thinking Modes via Python&lt;/h4&gt;
&lt;p&gt;When querying a local runner that supports thinking streams:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;import openai

client = openai.OpenAI(base_url=&quot;http://localhost:11434/v1&quot;, api_key=&quot;ollama&quot;)

response = client.chat.completions.create(
    model=&quot;gemma4:31b&quot;,
    messages=[{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Analyze this code for race conditions.&quot;}],
    extra_body={
        &quot;thinking_mode&quot;: &quot;enabled&quot;,
        &quot;max_thinking_tokens&quot;: 1500,
        &quot;logit_cap&quot;: 30.0  # Prevents logit drift in long reasoning
    }
)
print(response.choices[0].message.content)
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;standardized-sampling-configuration&quot;&gt;Standardized Sampling Configuration&lt;/h4&gt;
&lt;p&gt;Whether deploying via vLLM or Hugging Face:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;sampling_params = {
    &quot;temperature&quot;: 1.0,
    &quot;top_p&quot;: 0.95,
    &quot;top_k&quot;: 64,
    &quot;logit_cap&quot;: 30.0
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;hardware-decision-tree&quot;&gt;Hardware Decision Tree&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;Do you have a GPU?
 ├── NO  ──&amp;gt; Is it mobile/IoT?
 │           ├── YES ──&amp;gt; E2B (Offline voice/text)
 │           └── NO  ──&amp;gt; E4B (Laptop CPU)
 │
 └── YES ──&amp;gt; Total available VRAM?
              ├── 8–16GB  ──&amp;gt; E4B or 26B MoE (Quantized)
              ├── 24GB    ──&amp;gt; 26B A4B (Optimal sweet spot)
              └── 48GB+   ──&amp;gt; 31B Dense (Flagship reasoning)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; This tree isn't arbitrary. Each branch reflects a specific hardware constraint that shaped the architecture:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;E2B/E4B bottleneck:&lt;/strong&gt; Embedding tables exploding on small devices → solved with Per-Layer Embeddings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;26B MoE bottleneck:&lt;/strong&gt; Need 26B reasoning without 26B speed → solved with 128-expert sparse routing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;31B bottleneck:&lt;/strong&gt; 256K context blowing up KV cache → solved with shared KV and hybrid attention&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Pick the architecture that solves your constraint, and you'll be shocked at how well it works.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;hardware-amp-cost-reality&quot;&gt;&lt;strong&gt;Hardware &amp;amp; Cost Reality&lt;/strong&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Your Setup &lt;/th&gt;&lt;th&gt;Recommended Model &lt;/th&gt;&lt;th&gt;Memory &lt;/th&gt;&lt;th&gt;Cost&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;iPhone/iPad &lt;/td&gt;&lt;td&gt;E2B &lt;/td&gt;&lt;td&gt;4GB &lt;/td&gt;&lt;td&gt;Free&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;MacBook Air M2/M3 &lt;/td&gt;&lt;td&gt;E4B &lt;/td&gt;&lt;td&gt;8–16GB &lt;/td&gt;&lt;td&gt;Free&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Gaming laptop (RTX 3060) &lt;/td&gt;&lt;td&gt;E4B &lt;/td&gt;&lt;td&gt;6GB VRAM (16GB System RAM) &lt;/td&gt;&lt;td&gt;Free&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Desktop (RTX 4090) &lt;/td&gt;&lt;td&gt;26B MoE &lt;/td&gt;&lt;td&gt;24GB VRAM &lt;/td&gt;&lt;td&gt;Free&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Dual GPU (2× RTX 4090) &lt;/td&gt;&lt;td&gt;31B Dense &lt;/td&gt;&lt;td&gt;48GB VRAM &lt;/td&gt;&lt;td&gt;Free&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Used GPU (RTX 3090) &lt;/td&gt;&lt;td&gt;26B MoE / 31B &lt;/td&gt;&lt;td&gt;24GB VRAM &lt;/td&gt;&lt;td&gt;$650-800&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Best bang for buck:&lt;/strong&gt; E4B on a 2023+ MacBook, a brand-new &lt;strong&gt;RTX 4060 Ti 16GB (~$450)&lt;/strong&gt;, or a &lt;strong&gt;used RTX 3090 ($650–800 one-time cost)&lt;/strong&gt; handles 90% of real-world tasks. E4B on your laptop is genuinely competitive with cloud APIs at $20–100/month—and it's a one-time investment.&lt;/p&gt;
&lt;p&gt;(Note: If you are building on a budget and want to run the heavy 26B MoE model, avoid standard 8GB cards. Opt for the &lt;strong&gt;RTX 4060 Ti 16GB version&lt;/strong&gt;. Its 16GB frame buffer gives you just enough structural headroom to load the model's Q4 weights locally without triggering slow system memory paging.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cost comparison (annual):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Cloud API (Claude 3.5, $20 monthly): $240/year&lt;/li&gt;
&lt;li&gt;Cloud API (GPT-4o, $40 monthly for heavy use): $480/year&lt;/li&gt;
&lt;li&gt;Used RTX 3070 Ti (one-time): $500 → ∞ models&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The math is brutal for cloud. After one year, local compute pays for itself, and you own the hardware forever.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-this-architectural-approach-matters&quot;&gt;&lt;strong&gt;Why This Architectural Approach Matters&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Most AI companies would have shipped &quot;Gemma 4 Small, Gemma 4 Medium, Gemma 4 Large&quot;—all the same architecture, just different parameter counts. Google didn't.&lt;/p&gt;
&lt;p&gt;Instead, they asked: &lt;strong&gt;&quot;What's the actual hardware constraint for each use case?&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Mobile? Memory bottleneck. → Per-Layer Embeddings solves it.&lt;/li&gt;
&lt;li&gt;Single consumer GPU? Speed bottleneck. → Sparse MoE solves it.&lt;/li&gt;
&lt;li&gt;Long context? KV cache bottleneck. → Hybrid attention + shared KV solves it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is why Gemma 4 doesn't feel like you're compromising. Each model is purpose-built, not a scaled-down version of the flagship. You get:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;E4B that's actually good enough for code on a laptop (not a toy)&lt;/li&gt;
&lt;li&gt;26B MoE that's faster than a dense 26B would ever be (not a hack)&lt;/li&gt;
&lt;li&gt;31B that handles 256K context without crashing (not a pain point)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That's the difference between engineering for a spec and engineering for reality.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-bottom-line&quot;&gt;&lt;strong&gt;The Bottom Line&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Gemma 4 proves that localized open-source AI has moved well past the hobbyist phase. By shifting away from uniform scaling and adapting specialized architectures directly to consumer hardware bottlenecks, Google delivers an ecosystem where you own your data pipeline completely.&lt;/p&gt;
&lt;p&gt;Whether you're deploying ultra-low-latency voice on an E-series edge device, running an autonomous agent at 95 tokens/sec on 26B MoE, or handling novel reasoning on 31B Dense, the future of AI is local-first, private, and highly optimized.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Next steps:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install Ollama: &lt;code&gt;ollama run gemma4&lt;/code&gt; (2 minutes)&lt;/li&gt;
&lt;li&gt;Try E4B first—it's the Goldilocks model&lt;/li&gt;
&lt;li&gt;Experiment based on your hardware&lt;/li&gt;
&lt;li&gt;Join the community: &lt;a rel=&quot;nofollow&quot; href=&quot;https://huggingface.co/google/gemma-4-31b&quot;&gt;Hugging Face&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/google-gemini/cookbook&quot;&gt;GitHub Cookbook&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://ai.google.dev/gemma&quot;&gt;Official Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now go build something.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/18966/your-laptop-just-got-smarter-a-complete-guide-to-gemma-4s-four-models</guid>
<pubDate>Tue, 26 May 2026 08:21:30 +0000</pubDate>
</item>
<item>
<title>Coding in the Dark: How Local Gemma 4 Saved My Python Progress During Ukrainian Blackouts</title>
<link>https://coderlegion.com/18858/coding-in-the-dark-how-local-gemma-4-saved-my-python-progress-during-ukrainian-blackouts</link>
<description>&lt;p&gt;&lt;strong&gt;Hey everyone! &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I’m a student developer from &lt;u&gt;Ukraine&lt;/u&gt;️, currently diving deep into the worlds of Django and Machine Learning. Like many of you, I spend my days (and nights) battling bugs and learning new frameworks. But there’s one &quot;bug&quot; I can’t fix with a simple &lt;code&gt;pip install: the blackouts&lt;/code&gt;️&lt;/p&gt;
&lt;p&gt;Because of the ongoing war, our power grid is often under attack. One minute I’m coding a new feature, and the next—total darkness. Silence. No Wi-Fi. No Google. No ChatGPT.&lt;/p&gt;
&lt;p&gt;For a long time, this meant my learning just... STOPPED️But then I found a way to keep the &quot;️&quot; of my workstation alive even when the grid is dead!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oq5y41ww4xzdriwzwuhu.jpg&quot; alt=&quot;Image description&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Setup: My Local &quot;Senior Developer&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To stay productive in the dark, I’ve moved my AI assistance from the cloud to my local hardware(My ️ is HP ProBook 445 G8).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here’s how I keep going:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1)The Model: I’m using Gemma 4. It’s incredibly efficient for its size. I downloaded it once, and now it lives on my laptop.&lt;/p&gt;
&lt;p&gt;2)The Engine: LM Studio. It’s the easiest way to run local LLMs. It creates a local server on my machine that doesn't need a single byte of internet.&lt;/p&gt;
&lt;p&gt;3)The Bridge: e2b. I use it to integrate Gemma directly into my workflow. It’s not just a chat; it’s like having a senior dev sitting next to me, helping me reason through Python logic while the candles are burning.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why this is a Game-Changer (The Soul Part)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;JUST IMAGINE sitting in a pitch-black room. The only light comes from your laptop screen. You’re stuck on a complex Pandas transformation or a Django database migration. Usually, this is where frustration kicks in. You feel isolated️&lt;/p&gt;
&lt;p&gt;BUT with Gemma 4 &lt;u&gt;running locally&lt;/u&gt;, the conversation doesn't end! I can ask: &quot;Hey dude, why is this Django queryset returning an empty list?️?&quot; and get an instant, intelligent response.️&lt;/p&gt;
&lt;p&gt;It’s more than just TECH; it’s about PERSISTANCE! It’s the feeling that no matter what’s happening outside, I can still grow, still learn, and still build. Local AI turned my &quot;dead time️&quot; during blackouts into my most focused study hours️&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How I Use It: Two Ways to Stay Online&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When you open LM Studio, you actually have two powerful ways to work with Gemma 4, and I use both depending on the task:&lt;/p&gt;
&lt;p&gt;1)The AI Chat (Simple &amp;amp; Fast): This is my go-to for quick questions. It’s a clean interface that works exactly like ChatGPT or Gemini. I just select the Gemma model at the top and start asking about Python logic or Django errors. It’s perfect for when I need a quick explanation of a concept while the room is lit only by candles.️&lt;/p&gt;
&lt;p&gt;2)The Local Server (For Devs): For more advanced stuff, LM Studio can host a local API server (on localhost:1234). This allows you to connect the model to other tools like e2b or even your code editor. It’s like having an invisible assistant living inside your laptop, ready to process data even without a single byte of internet.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;import openai

client = openai.OpenAI(
    base_url=&quot;http://localhost:1234/v1&quot;, 
    api_key=&quot;lm-studio&quot;
)

def get_python_help(query):
    completion = client.chat.completions.create(
        model=&quot;google/gemma-4&quot;,
        messages=[{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: query}]
    )
    return completion.choices[0].message.content

print(get_python_help(&quot;Explain Django middleware in simple terms&quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Personally, most of the time I just use the AI Chat️ It’s fast, stable, and doesn't waste battery life on complex setups. It just works.&lt;/p&gt;
&lt;p&gt;We often think of AI as this &quot;cloud thing&quot; that exists somewhere far away. But Gemma 4 proves that AI can be personal, local, and—most importantly—resilient.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Closing: Why We Keep Building&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To &lt;u&gt;everyone&lt;/u&gt; reading this, ESPECIALLY those who feel like the world is trying to slow them down: remember that every line of code you write in the dark is a victory. Every bug you fix while the world is silent is a step toward the future you deserve️&lt;/p&gt;
&lt;p&gt;&quot;&quot;&quot;Our fight for that future that you want isn't with me at chess! It's what you do out there with them!&quot;&quot;&quot;&lt;/p&gt;
&lt;p&gt;Don't wait for the perfect conditions. Don't wait for the lights to come back on or for the internet to be stable️ The real &quot;GAME&quot; isn't played in the safety of a perfect setup. It’s played right here, in the shadows, where you choose to keep moving forward despite everything.&lt;/p&gt;
&lt;p&gt;Local AI like Gemma is more than just a tool—it’s our way of saying that our education and our future are non-negotiable️&lt;/p&gt;
&lt;p&gt;Stay hard, stay curious, and keep coding✊️.&lt;br&gt;
See you in the future we’re building right now!!!&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/18858/coding-in-the-dark-how-local-gemma-4-saved-my-python-progress-during-ukrainian-blackouts</guid>
<pubDate>Mon, 25 May 2026 06:54:10 +0000</pubDate>
</item>
<item>
<title>We Didn't Ask for AI That Does Tasks. We Asked for AI That Remembers.</title>
<link>https://coderlegion.com/18741/we-didnt-ask-for-ai-that-does-tasks-we-asked-for-ai-that-remembers</link>
<description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a rel=&quot;nofollow&quot; href=&quot;https://dev.to/challenges/google-gemma-2026-05-06&quot;&gt;Gemma 4 Challenge: Write about Gemma 4&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Every AI assistant I have used starts the same way.&lt;/p&gt;
&lt;p&gt;A blank input field. No memory of yesterday. No idea who you are, what you have been working on, or why you are here. Every session, you explain yourself from scratch. Every session, the context you built up — the decisions, the dead ends, the reasoning — vanishes the moment you close the window.&lt;/p&gt;
&lt;p&gt;We accepted this as normal. I no longer think it is.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-problem-is-not-intelligence-it-is-amnesia-&quot;&gt;The Problem Is Not Intelligence. It Is Amnesia.&lt;/h3&gt;
&lt;p&gt;The current generation of AI assistants is remarkably capable. They reason, they write, they debug. But they are &lt;strong&gt;stateless by default&lt;/strong&gt; — each conversation an island, disconnected from the one before it.&lt;/p&gt;
&lt;p&gt;This creates a hidden cost that we rarely talk about. Not the cost of compute, or latency, or accuracy. The cost of &lt;strong&gt;re-explaining yourself, every single day.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you work with an AI assistant regularly, you know the feeling:&lt;/p&gt;
&lt;p&gt; &lt;em&gt;&quot;As I mentioned before...&quot;&lt;/em&gt;&lt;br&gt;
 &lt;em&gt;&quot;To give you some context, I am working on...&quot;&lt;/em&gt;&lt;br&gt;
 &lt;em&gt;&quot;We already decided that we would...&quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You are not talking to a partner. You are filling in a form. Every time.&lt;/p&gt;
&lt;p&gt;The gap is not capability. It is memory.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-i-built-to-think-in-parallel&quot;&gt;What I Built to Think in Parallel&lt;/h3&gt;
&lt;p&gt;To explore this problem, I built &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/pepepepepepo/g4-nexus&quot;&gt;g4-nexus&lt;/a&gt; — a parallel persona engine powered by Gemma 4.&lt;/p&gt;
&lt;p&gt;Instead of asking one model one question, g4-nexus runs &lt;strong&gt;three specialized worker personas simultaneously&lt;/strong&gt;, then a fourth leader synthesizes their outputs into a single integrated response. The workers — Mochi (emotion), Jun (logic), Uruu (analysis) — run in parallel via &lt;code&gt;asyncio.gather&lt;/code&gt;. The leader, Koyomi, holds the whole picture and responds.&lt;/p&gt;
&lt;p&gt;What this unlocked was surprising. Not just speed, but &lt;strong&gt;perspective&lt;/strong&gt;. A single model gives you &lt;em&gt;an&lt;/em&gt; answer. g4-nexus gives you a conversation between angles — emotional grounding, logical structure, and critical observation — all at once.&lt;/p&gt;
&lt;p&gt;But after running it for a while, I noticed something.&lt;/p&gt;
&lt;p&gt;g4-nexus could think in parallel. It could not remember across time.&lt;/p&gt;
&lt;p&gt;Every session, Mochi had no idea what we worked on yesterday. Jun had no memory of the decisions we made last week. Koyomi could synthesize beautifully in the moment, but the moment always ended. The slate was always wiped clean.&lt;/p&gt;
&lt;p&gt;The thinking was there. The memory was not.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-memory-is-the-missing-half&quot;&gt;Why Memory Is the Missing Half&lt;/h3&gt;
&lt;p&gt;There is a difference between an AI that &lt;em&gt;processes&lt;/em&gt; and an AI that &lt;em&gt;knows you&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Processing is impressive. But knowing you — knowing your project's history, the choices you made and why, what worked and what didn't — that is what makes the difference between a tool and a partner.&lt;/p&gt;
&lt;p&gt;Consider what a real collaborator remembers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What you tried last week and why it didn't work&lt;/li&gt;
&lt;li&gt;The decision you made that you later regretted&lt;/li&gt;
&lt;li&gt;The thing you said offhand that turned out to be important&lt;/li&gt;
&lt;li&gt;The context that makes today's question make sense&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;None of that lives in a single conversation. It lives in &lt;strong&gt;accumulated time&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Gemma 4's small, steerable models make it practical to run multiple specialized instances locally. But the deeper opportunity they unlock is not just parallel thinking — it is &lt;strong&gt;persistent identity&lt;/strong&gt;. A small model that stays on, that accumulates context, that writes its own notes and reads them back the next morning.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-comes-next&quot;&gt;What Comes Next&lt;/h3&gt;
&lt;p&gt;g4-nexus is the first half. The second half is memory.&lt;/p&gt;
&lt;p&gt;We are moving toward a system where each persona maintains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Session logs&lt;/strong&gt; — what happened today, in the persona's own words&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handover notes&lt;/strong&gt; — what the next session needs to know&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Morning briefings&lt;/strong&gt; — auto-generated summaries written overnight, ready before the first message&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory files&lt;/strong&gt; — accumulated context that persists across weeks, not just minutes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Not cloud memory. Local memory. Files on disk, readable and inspectable. Owned by the user, not by a platform.&lt;/p&gt;
&lt;p&gt;The direction is this: AI shouldn't just respond to you. It should &lt;strong&gt;remember you&lt;/strong&gt;. It should carry yesterday into today, and today into tomorrow. Not as a feature — as the foundation.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;a-different-question&quot;&gt;A Different Question&lt;/h3&gt;
&lt;p&gt;We have spent years asking: &lt;em&gt;how do we make AI smarter?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The better question might be: &lt;em&gt;how do we make AI remember?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Intelligence without memory is impressive at a party. It cannot build anything with you over time. It cannot be trusted with a project, a relationship, a long-term goal — because it forgets you the moment the session ends.&lt;/p&gt;
&lt;p&gt;The hardware exists. The models exist. Gemma 4's small, local models make it accessible without cloud infrastructure or enterprise budgets. What remains is the architecture — the discipline of writing memory down, carrying it forward, and letting it accumulate into something that feels less like a tool and more like a presence that has been with you.&lt;/p&gt;
&lt;p&gt;That is what I am building toward.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;GitHub: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/pepepepepepo/g4-nexus&quot;&gt;pepepepepepo/g4-nexus&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Build track article: &lt;a rel=&quot;nofollow&quot; href=&quot;https://dev.to/kato_masato_c5593c81af5c6/i-built-a-4-persona-parallel-ai-engine-with-gemma-4-and-let-it-write-this-article-544a&quot;&gt;I Built a 4-Persona Parallel AI Engine with Gemma 4&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/18741/we-didnt-ask-for-ai-that-does-tasks-we-asked-for-ai-that-remembers</guid>
<pubDate>Sat, 23 May 2026 09:15:27 +0000</pubDate>
</item>
<item>
<title>Legible - I built an on-device document helper for immigrants using Gemma 4</title>
<link>https://coderlegion.com/17987/legible-i-built-an-on-device-document-helper-for-immigrants-using-gemma-4</link>
<description>&lt;p&gt;Imagine receiving an official envelope and not being able to read it. Not because you're careless, but rather because English isn't your first language. Worse yet, the letter is written in bureaucratic legalese that would confuse many native speakers, too. Is it urgent? Do you need to respond? Who do you call?&lt;br&gt;
That's the problem Legible tries to solve.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-it-does&quot;&gt;What it does&lt;/h3&gt;
&lt;p&gt;Legible lets you photograph or upload any official document: a tax notice, school letter, eviction warning, lease, utility bill, or government letter. It returns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A plain-language explanation in your own language&lt;/li&gt;
&lt;li&gt;A deadline countdown (&quot;You have 23 days to respond&quot;)&lt;/li&gt;
&lt;li&gt;Numbered next steps — concrete, specific actions to take&lt;/li&gt;
&lt;li&gt;A glossary of legal or bureaucratic terms found in the document, with simple definitions&lt;/li&gt;
&lt;li&gt;An encrypted local history of past scans, so you can refer back without re-uploading&lt;br&gt;
Eleven languages supported: Spanish, Chinese (Simplified), Tagalog, Vietnamese, Arabic, Hindi, Korean, French, Portuguese, Russian, and English.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-model-choice-why-gemma-4&quot;&gt;The model choice: why Gemma 4&lt;/h3&gt;
&lt;p&gt;This is a Build With Gemma 4, and I want to be specific about why Gemma 4 — running locally via Ollama — is the right model here, not just a convenient one.&lt;br&gt;
I ran gemma4:latest, which Ollama resolved to the Gemma 4 Effective 4B (E4B) instruction-tuned model.  The privacy and offline arguments below apply equally to any Gemma 4 variant served locally. Still, document parsing with structured XML output and multilingual generation is exactly the kind of task where the extra capacity of E4B shows. The key point is that nothing leaves the machine. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Privacy is the core value proposition.&lt;/strong&gt; The documents this app handles contain some of the most sensitive information a person owns: Social Security numbers, tax IDs, case numbers, home addresses, and medical details. These are exactly the fields that get scraped, leaked, or sold when you upload documents to a cloud API.&lt;br&gt;
Gemma 4 runs entirely on the user's machine via Ollama. The image never leaves the device. There's no API key, no usage logs, and no third-party server seeing your user's tax notice. It’s not just a privacy policy, it's a privacy architecture.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Multimodal input is essential.&lt;/strong&gt; Real documents aren't clean PDFs. They're photos taken at an angle under fluorescent lighting, or scans of crumpled letters that have been in someone's bag. Gemma 4's native image understanding handles this skillfully. The model reads the document directly from the photo rather than depending on a separate OCR pipeline that might fail on non-Latin scripts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Offline capability matters for this audience.&lt;/strong&gt; Immigrant communities often rely on metered mobile data or shared Wi-Fi. The model downloads once, then runs indefinitely with no internet connection.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;How it works&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11185969515062669496&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The backend is a FastAPI app that proxies a streaming request to Ollama's local API. The frontend is a single HTML file — no build step, no framework, no dependencies to install beyond Python. Open the browser at localhost:8000 and it works.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The system prompt&lt;/strong&gt;&lt;br&gt;
Getting structured output from a vision model reliably is mostly a prompting problem. I landed on asking Gemma 4 to respond in a fixed XML schema:&lt;br&gt;
Tax Notice | Lease Agreement | School Letter | ...&lt;br&gt;
YYYY-MM-DD or none&lt;br&gt;
integer or none&lt;br&gt;
Plain-language summary in {target_language}&lt;br&gt;
1. action\n2. action...&lt;br&gt;
English Term | Simple explanation in {target_language}&lt;/p&gt;
&lt;p&gt;Injecting today's date into the prompt and asking the model to calculate days remaining directly (rather than doing it in code) turned out to be more reliable than parsing a date string and computing the delta separately. Gemma 4 handles this arithmetic accurately.&lt;br&gt;
The full system prompt is pinned to the user's chosen language so that the glossary definitions, explanation, and next steps all arrive in one language, no mixing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Encrypted history&lt;/strong&gt;&lt;br&gt;
Past scans are stored as Fernet-encrypted files in .history/records/. The encryption key lives in .history/key.bin and is generated fresh on first run. Both paths are .gitignored. Deleting the .history/ folder clears everything.&lt;br&gt;
Each record stores a JPEG thumbnail of the document alongside the parsed results, so the history panel shows what the document looked like without re-processing it.&lt;/p&gt;
&lt;h3 id=&quot;stack&quot;&gt;Stack&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17259067059426814028&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;running-it-yourself&quot;&gt;Running it yourself&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt; Ollama installed and running.&lt;/p&gt;
&lt;h2 id=&quot;pull-the-model-one-time-3-gb-&quot;&gt;Pull the model (one-time, ~3 GB)&lt;/h2&gt;
&lt;p&gt;ollama pull gemma4:latest&lt;/p&gt;
&lt;h2 id=&quot;install-python-dependencies&quot;&gt;Install Python dependencies&lt;/h2&gt;
&lt;p&gt;pip install -r requirements.txt&lt;/p&gt;
&lt;h2 id=&quot;start-the-app&quot;&gt;Start the app&lt;/h2&gt;
&lt;p&gt;uvicorn main:app --reload&lt;/p&gt;
&lt;p&gt;Open &lt;a rel=&quot;nofollow&quot; href=&quot;http://localhost:8000&quot;&gt;http://localhost:8000&lt;/a&gt; — that's it.&lt;br&gt;
Environment variables to override defaults:&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8073912696233465009&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;what-i-learned&quot;&gt;What I learned&lt;/h3&gt;
&lt;p&gt;Local multimodal inference has crossed a usability threshold. A year ago, running a vision model locally meant wrestling with quantization, drivers, and memory issues. With Ollama and Gemma 4, ollama pull gemma4:latest and uvicorn main:app is the entire setup. That simplicity matters enormously for a tool meant to be shared with non-technical communities.&lt;/p&gt;
&lt;p&gt;Structured output from vision models is still a prompt engineering problem. Gemma 4 followed the XML schema reliably once I made the format explicit and gave it examples of what &quot;none&quot; should look like for optional fields. Before that, it occasionally invented its own tags or wrapped the XML in markdown code fences — easy to handle in the parser, but cleaner to prevent at the prompt level.&lt;/p&gt;
&lt;p&gt;The privacy architecture is the product. For this use case, &quot;runs locally&quot; isn't a feature — it's the reason the tool is trustworthy enough to use with sensitive documents. That framing changed how I thought about the whole design.&lt;/p&gt;
&lt;h3 id=&quot;what-s-next-1&quot;&gt;What's next&lt;/h3&gt;
&lt;p&gt;Mobile-optimised layout for direct phone camera capture&lt;br&gt;
Support for multi-page documents (PDF input)&lt;br&gt;
Offline-first PWA packaging so it can be installed like an app&lt;br&gt;
Optional audio read-aloud of the explanation for users with low literacy&lt;/p&gt;
&lt;h3 id=&quot;repo&quot;&gt;Repo&lt;/h3&gt;
&lt;p&gt;Source code, setup instructions, and the full system prompt are in the repository -&amp;gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/RealWorldApplications/legible&quot;&gt;https://github.com/RealWorldApplications/legible&lt;/a&gt;. &lt;br&gt;
Questions welcome in the comments.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/17987/legible-i-built-an-on-device-document-helper-for-immigrants-using-gemma-4</guid>
<pubDate>Fri, 15 May 2026 17:14:08 +0000</pubDate>
</item>
<item>
<title>Iris: An Offline Visual Assistant in Brazilian Portuguese Powered by Gemma 4</title>
<link>https://coderlegion.com/17949/iris-an-offline-visual-assistant-in-brazilian-portuguese-powered-by-gemma-4</link>
<description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a rel=&quot;nofollow&quot; href=&quot;https://dev.to/challenges/google-gemma-2026-05-06&quot;&gt;Gemma 4 Challenge: Build with Gemma 4&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Iris&lt;/strong&gt; is an Android visual assistant for blind and low-vision users.&lt;/li&gt;
&lt;li&gt;It describes what the camera sees, out loud, in &lt;strong&gt;Brazilian Portuguese&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gemma 4 multimodal&lt;/strong&gt; runs &lt;strong&gt;100% on the phone&lt;/strong&gt; via LiteRT-LM — no cloud, no telemetry, no &lt;code&gt;INTERNET&lt;/code&gt; permission.&lt;/li&gt;
&lt;li&gt;Three intent-specific modes: Continuous, Question, Reading.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;what-i-built&quot;&gt;What I Built&lt;/h3&gt;
&lt;p&gt;I built &lt;strong&gt;Iris&lt;/strong&gt;, an offline Android visual assistant for blind and low-vision users.&lt;/p&gt;
&lt;p&gt;The interaction is intentionally simple: point the phone camera at something, tap the screen, and Iris speaks what it sees in Brazilian Portuguese.&lt;/p&gt;
&lt;p&gt;Iris has three modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Continuous Mode&lt;/strong&gt; describes the scene in front of the user.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Question Mode&lt;/strong&gt; lets the user ask a spoken question about the current camera image.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reading Mode&lt;/strong&gt; reads visible text aloud, such as a label, medicine box, sign, or package.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A fourth control, &lt;strong&gt;Repeat&lt;/strong&gt;, replays the last description — useful for users who could not catch it all the first time.&lt;/p&gt;
&lt;p&gt;The core constraint was not only &quot;can Gemma 4 understand the image?&quot; — the real question was whether this could still be useful when the camera is looking at private, everyday scenes and the user may not have a reliable network connection.&lt;/p&gt;
&lt;p&gt;That led to the main technical decision: &lt;strong&gt;everything runs on the phone&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;No server. No cloud API. No telemetry. No &lt;code&gt;INTERNET&lt;/code&gt; permission in the Android manifest.&lt;/p&gt;
&lt;h3 id=&quot;demo&quot;&gt;Demo&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/cdug6i_HEJM&quot;&gt;https://youtu.be/cdug6i_HEJM&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The demo shows Iris running on a Galaxy S21 with airplane mode visible. The right side of the video is the actual phone screen; the left side explains what each mode is doing.&lt;/p&gt;
&lt;p&gt;The video is not meant to hide the on-device latency. On a Galaxy S21, the first spoken sentence arrives in roughly 25–30 seconds after the tap. The wait is part of the point: Gemma 4 is doing the multimodal work locally, on the phone, with no help from a server.&lt;/p&gt;
&lt;h3 id=&quot;code&quot;&gt;Code&lt;/h3&gt;
&lt;p&gt;Repository:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/juniormartinxo/iris&quot;&gt;https://github.com/juniormartinxo/iris&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The project is a native Android app built with Kotlin, Jetpack Compose, CameraX, Android TTS/STT, and LiteRT-LM.&lt;/p&gt;
&lt;h3 id=&quot;why-this-app-needed-to-be-offline&quot;&gt;Why This App Needed To Be Offline&lt;/h3&gt;
&lt;p&gt;A visual assistant sees the user's world.&lt;/p&gt;
&lt;p&gt;That can mean a medicine label, a document on a desk, a room at home, a person nearby, a screen, or an object the user is trying to identify. For this kind of app, &quot;send the image to a server&quot; is not a neutral implementation detail. It changes the privacy model of the product.&lt;/p&gt;
&lt;p&gt;I wanted Iris to have a stronger boundary:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;camera frames stay on the device;&lt;/li&gt;
&lt;li&gt;speech recognition uses Android's on-device recognizer;&lt;/li&gt;
&lt;li&gt;speech output uses Android Text-to-Speech;&lt;/li&gt;
&lt;li&gt;Gemma 4 runs through LiteRT-LM locally;&lt;/li&gt;
&lt;li&gt;the app does not request Internet access.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Android manifest only asks for the permissions the app needs to see and hear:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&amp;gt;
&amp;lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is no &lt;code&gt;android.permission.INTERNET&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That means the app cannot silently fall back to a network call unless a future version explicitly changes the permission model.&lt;/p&gt;
&lt;h3 id=&quot;how-i-used-gemma-4&quot;&gt;How I Used Gemma 4&lt;/h3&gt;
&lt;p&gt;Iris uses &lt;strong&gt;Gemma 4 E2B&lt;/strong&gt; as the primary model, packaged as a &lt;code&gt;.litertlm&lt;/code&gt; bundle and loaded with LiteRT-LM on Android.&lt;/p&gt;
&lt;p&gt;I chose E2B because the target device is a phone, not a workstation. The challenge prompt asks builders to be intentional about model selection, and for this project the priority was clear: local multimodal inference with the smallest model that could still make the experience meaningful.&lt;/p&gt;
&lt;p&gt;The app can also look for an E4B bundle as a fallback, but the loading order prefers E2B:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-kotlin&quot;&gt;val MODEL_CANDIDATES: List&amp;lt;Pair&amp;lt;String, String&amp;gt;&amp;gt; = listOf(
    &quot;E2B&quot; to &quot;gemma-4-E2B-it.litertlm&quot;,
    &quot;E4B&quot; to &quot;gemma-4-E4B-it.litertlm&quot;,
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the current demo, E2B is the right trade-off: it keeps the app viable on devices like the Galaxy S21 and A55 while still giving Iris native multimodal understanding.&lt;/p&gt;
&lt;p&gt;The app sends Gemma 4 one camera frame plus a mode-specific prompt:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;in &lt;strong&gt;Continuous Mode&lt;/strong&gt;, the prompt asks for a short scene description focused on obstacles, relevant objects, visible text, and people;&lt;/li&gt;
&lt;li&gt;in &lt;strong&gt;Question Mode&lt;/strong&gt;, Android's on-device speech recognizer captures the user's question, then Gemma 4 answers using the current image;&lt;/li&gt;
&lt;li&gt;in &lt;strong&gt;Reading Mode&lt;/strong&gt;, the prompt asks Gemma 4 to read visible text from top to bottom and left to right.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All prompts ask for Brazilian Portuguese output because the product is designed for PT-BR users first.&lt;/p&gt;
&lt;h3 id=&quot;architecture&quot;&gt;Architecture&lt;/h3&gt;
&lt;p&gt;The runtime path is deliberately small:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CameraX preview
  -&amp;gt; capture current frame
  -&amp;gt; downsample image to a 512px longest edge
  -&amp;gt; run frame quality checks
  -&amp;gt; Gemma 4 E2B through LiteRT-LM
  -&amp;gt; sentence buffer
  -&amp;gt; Android Text-to-Speech
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are a few details in that pipeline that matter.&lt;/p&gt;
&lt;h4 id=&quot;1-frame-quality-checks-before-inference&quot;&gt;1. Frame quality checks before inference&lt;/h4&gt;
&lt;p&gt;On-device multimodal inference is expensive enough that Iris should not waste a run on a useless image.&lt;/p&gt;
&lt;p&gt;Before calling Gemma 4, the app calculates a small set of image quality signals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;brightness;&lt;/li&gt;
&lt;li&gt;luminance variance;&lt;/li&gt;
&lt;li&gt;a simple blur score.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the image is too dark, too bright, too empty, or too blurry, Iris speaks a direct instruction like:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;Imagem muito escura. Verifique a iluminação ou se há algo cobrindo a câmera.&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is better than waiting through a slow inference only to get a weak answer.&lt;/p&gt;
&lt;h4 id=&quot;2-sentence-streaming-into-tts&quot;&gt;2. Sentence streaming into TTS&lt;/h4&gt;
&lt;p&gt;LiteRT-LM returns text chunks. Iris does not wait for the entire response before speaking.&lt;/p&gt;
&lt;p&gt;A small &lt;code&gt;SentenceBuffer&lt;/code&gt; collects chunks until it sees a sentence boundary, then sends each sentence to Android TTS. The user hears the first useful sentence as soon as possible, while the model can still finish the rest of the response.&lt;/p&gt;
&lt;p&gt;For accessibility, this is not just a polish detail. Silence during a long local inference can feel like the app froze. Iris speaks &quot;Aguarde.&quot; as a progress beacon every 15 seconds while inference is still running. The moment the first sentence arrives from the model, the loading overlay disappears and the description starts streaming into the screen — one sentence at a time — so visual and audio feedback stay in sync.&lt;/p&gt;
&lt;h4 id=&quot;3-modes-are-prompt-engineering-exposed-as-ui&quot;&gt;3. Modes are prompt engineering exposed as UI&lt;/h4&gt;
&lt;p&gt;I did not want one generic &quot;describe&quot; button to handle every situation.&lt;/p&gt;
&lt;p&gt;Blind and low-vision users often know what they need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&quot;What is in front of me?&quot;&lt;/li&gt;
&lt;li&gt;&quot;Is there a silver object here?&quot;&lt;/li&gt;
&lt;li&gt;&quot;Read this medicine box.&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The three modes let the UI choose the prompt shape before the model runs. This keeps the responses shorter, more predictable, and easier to listen to.&lt;/p&gt;
&lt;h4 id=&quot;4-talkback-aware-behavior&quot;&gt;4. TalkBack-aware behavior&lt;/h4&gt;
&lt;p&gt;Iris is built around audio, but Android accessibility already has an audio layer: TalkBack.&lt;/p&gt;
&lt;p&gt;When TalkBack is enabled, Iris avoids speaking over UI announcements. When TalkBack is not enabled, Iris uses its own TTS announcements for mode changes, loading states, errors, and tutorial flow.&lt;/p&gt;
&lt;p&gt;Every primary control has a &lt;code&gt;contentDescription&lt;/code&gt;, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Continuous Mode;&lt;/li&gt;
&lt;li&gt;Question Mode;&lt;/li&gt;
&lt;li&gt;Reading Mode;&lt;/li&gt;
&lt;li&gt;Repeat.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This lets the same interface work for screen-reader users and for users who are not running TalkBack.&lt;/p&gt;
&lt;h3 id=&quot;performance-on-the-galaxy-s21&quot;&gt;Performance on the Galaxy S21&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Step &lt;/th&gt;&lt;th&gt;Time / size&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Cold start to &quot;Ready&quot; (model load) &lt;/td&gt;&lt;td&gt;~10–30 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Tap → first spoken word &lt;/td&gt;&lt;td&gt;~25–35 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Tap → full response done &lt;/td&gt;&lt;td&gt;~35–50 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Memory while idle (model loaded) &lt;/td&gt;&lt;td&gt;~3 GB&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;APK size (debug) &lt;/td&gt;&lt;td&gt;~99 MB&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Model bundle (sideloaded &lt;code&gt;.litertlm&lt;/code&gt;) &lt;/td&gt;&lt;td&gt;~2.59 GB&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;These are not best-in-class numbers. They are the cost of doing multimodal inference fully on-device on a 2021 phone. The UX is designed around making that wait legible, not invisible — that is what the progress beacon and the sentence streaming are for.&lt;/p&gt;
&lt;p&gt;Numbers above are approximate, taken on a single Galaxy S21 unit. They will vary by device, by ambient thermal state, and by how much memory the rest of the system is using.&lt;/p&gt;
&lt;h3 id=&quot;what-gemma-4-unlocked&quot;&gt;What Gemma 4 Unlocked&lt;/h3&gt;
&lt;p&gt;The important thing about Gemma 4 here is not only that it can caption an image.&lt;/p&gt;
&lt;p&gt;It lets Iris treat visual assistance as a flexible language problem:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a scene can be summarized;&lt;/li&gt;
&lt;li&gt;a user question can be grounded in the image;&lt;/li&gt;
&lt;li&gt;visible text can be read in context;&lt;/li&gt;
&lt;li&gt;the output can be constrained to short, spoken PT-BR sentences.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Without a multimodal model, this app would likely become a collection of separate systems: one detector, one OCR pipeline, one classifier, one rules engine, and a lot of glue code. That can be the right architecture for a mature product, but it is much heavier for a fast prototype.&lt;/p&gt;
&lt;p&gt;Gemma 4 made it possible to build one coherent loop:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;image + intent -&amp;gt; useful spoken answer&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;what-was-hard&quot;&gt;What Was Hard&lt;/h3&gt;
&lt;p&gt;The hardest part was not wiring the camera to the model. It was making the experience feel reliable enough for an audio-first user.&lt;/p&gt;
&lt;p&gt;Some examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The app must tell the user when the model is still working.&lt;/li&gt;
&lt;li&gt;A second tap should cancel or replace the previous flow cleanly.&lt;/li&gt;
&lt;li&gt;If speech recognition is unavailable offline, the app should explain that instead of failing silently.&lt;/li&gt;
&lt;li&gt;If the camera points at a blank wall, the model should not invent a detailed scene.&lt;/li&gt;
&lt;li&gt;If the device is too hot, the app should refuse another expensive inference instead of making the phone worse.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some other details would have been invisible in a tech demo but mattered for a real app: guarding the camera tap area against overlay-based tap-jacking, capping the crash log file size so a failure loop cannot fill the disk, synchronizing access to the speech recognizer so it cannot be torn down mid-utterance. Each one came from imagining what a confused or panicked user would experience.&lt;/p&gt;
&lt;p&gt;Iris is still a prototype, but these details are the difference between a tech demo and something that starts to behave like a product.&lt;/p&gt;
&lt;h3 id=&quot;limitations&quot;&gt;Limitations&lt;/h3&gt;
&lt;p&gt;The current version has real constraints.&lt;/p&gt;
&lt;p&gt;First, local inference on a Galaxy S21 can take a while. That is the cost of running a multimodal model offline on a phone-class device. The app is designed to keep the user informed during that wait, but latency is still the biggest UX limitation.&lt;/p&gt;
&lt;p&gt;Second, Iris is not a navigation or safety-critical tool. It can describe what the camera sees, but it should not be used as the only source of truth for crossing streets, avoiding hazards, or making medical decisions.&lt;/p&gt;
&lt;p&gt;Third, Reading Mode uses Gemma 4's multimodal ability rather than a dedicated OCR engine. That keeps the architecture simple and demonstrates what the model can do, but a production version might combine Gemma 4 with a specialized OCR pipeline for speed and fidelity.&lt;/p&gt;
&lt;h3 id=&quot;try-it-yourself&quot;&gt;Try It Yourself&lt;/h3&gt;
&lt;p&gt;The model is sideloaded because it is large. The app expects the LiteRT-LM bundle under the app's external files directory.&lt;/p&gt;
&lt;p&gt;Short version:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;./gradlew :app:assembleDebug

adb install -r app/build/outputs/apk/debug/iris-0.1.0-debug.apk

adb push gemma-4-E2B-it.litertlm \
  /sdcard/Android/data/com.iris/files/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Model source:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm&quot;&gt;https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The README includes the full setup notes, including Android version, memory, storage, and offline PT-BR TTS/STT requirements.&lt;/p&gt;
&lt;h3 id=&quot;what-s-next-2&quot;&gt;What's Next&lt;/h3&gt;
&lt;p&gt;The next improvements I would make are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;test the same build across more Android devices;&lt;/li&gt;
&lt;li&gt;improve latency with better model/runtime configuration;&lt;/li&gt;
&lt;li&gt;add a more explicit first-run checklist for offline language packs;&lt;/li&gt;
&lt;li&gt;explore a hybrid Reading Mode that uses dedicated OCR when speed matters;&lt;/li&gt;
&lt;li&gt;keep the permission model strict: no Internet unless the product direction changes openly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Google AI Edge&lt;/strong&gt; team for LiteRT-LM, which makes running Gemma 4 on Android tractable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;litert-community&lt;/code&gt;&lt;/strong&gt; on Hugging Face for the &lt;code&gt;.litertlm&lt;/code&gt; model bundles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anthropic Claude Code&lt;/strong&gt; was used as a pair-programming assistant during development of the Android code, the UX logic, and parts of this article.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;closing&quot;&gt;Closing&lt;/h3&gt;
&lt;p&gt;Iris is small, but it represents the kind of app I want to see more often: local-first, accessibility-first, and built for a real language community instead of assuming English by default.&lt;/p&gt;
&lt;p&gt;Gemma 4 made the prototype possible because it brought multimodal understanding close enough to the device. LiteRT-LM made it possible to run that loop inside Android.&lt;/p&gt;
&lt;p&gt;The result is simple:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The camera sees. Gemma 4 understands. Iris speaks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And it does that without sending the image anywhere.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/17949/iris-an-offline-visual-assistant-in-brazilian-portuguese-powered-by-gemma-4</guid>
<pubDate>Fri, 15 May 2026 11:53:10 +0000</pubDate>
</item>
<item>
<title>I Built a 4-Persona Parallel AI Engine with Gemma 4 — and Let It Write This Article</title>
<link>https://coderlegion.com/17936/i-built-a-4-persona-parallel-ai-engine-with-gemma-4-and-let-it-write-this-article</link>
<description>&lt;p&gt; &lt;strong&gt;This article was drafted by the system it describes.&lt;/strong&gt; The structure, arguments, and demo output below are real — generated by g4-nexus running locally on an RTX 4070 Ti. I edited for flow and added code excerpts.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-i-built-1&quot;&gt;What I Built&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/pepepepepepo/g4-nexus&quot;&gt;g4-nexus&lt;/a&gt; is a parallel persona engine built on Google's Gemma 4 models. Instead of asking one model one question, it asks &lt;strong&gt;three specialized worker personas in parallel&lt;/strong&gt; — then a fourth leader persona synthesizes their answers into a single integrated response.&lt;/p&gt;
&lt;p&gt;The four personas:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Name &lt;/th&gt;&lt;th&gt;Model &lt;/th&gt;&lt;th&gt;Role&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Mochi  &lt;/td&gt;&lt;td&gt;gemma4:e2b &lt;/td&gt;&lt;td&gt;Emotion &amp;amp; empathy&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;️ Jun    &lt;/td&gt;&lt;td&gt;gemma4:e2b &lt;/td&gt;&lt;td&gt;Logic &amp;amp; expression&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;️ Uruu   &lt;/td&gt;&lt;td&gt;gemma4:e2b &lt;/td&gt;&lt;td&gt;Analysis &amp;amp; observation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Koyomi &lt;/td&gt;&lt;td&gt;gemma4:e4b &lt;/td&gt;&lt;td&gt;Integration leader&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt; &lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;gemma4:e2b&lt;/code&gt; and &lt;code&gt;gemma4:e4b&lt;/code&gt; are the official &lt;a rel=&quot;nofollow&quot; href=&quot;https://ollama.com/library/gemma4&quot;&gt;Ollama library tags&lt;/a&gt; for these models. &quot;E&quot; stands for &quot;effective&quot; parameters.&lt;/p&gt;
&lt;p&gt;A single model gives you &lt;em&gt;an&lt;/em&gt; answer. g4-nexus gives you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Emotional grounding&lt;/strong&gt; (Mochi) — is the user overwhelmed? burned out?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Logical structure&lt;/strong&gt; (Jun) — what are the concrete steps?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Critical observation&lt;/strong&gt; (Uruu) — what context is missing? what assumptions are wrong?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integrated action plan&lt;/strong&gt; (Koyomi) — what should they actually &lt;em&gt;do&lt;/em&gt; right now?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful for: decision support, design reviews, multi-stakeholder analysis, or just thinking through a hard problem from every angle at once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Safety note:&lt;/strong&gt; g4-nexus is not an autonomous or self-evolving system. It has no internet access, no persistent agency, and no capability to act outside answering questions. It is a local inference orchestration layer — explicit, inspectable, and fully under user control.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;demo-1&quot;&gt;Demo&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;The following demo illustrates the workflow: input → three parallel worker outputs → leader synthesis.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prompt sent:&lt;/strong&gt; &lt;code&gt;&quot;I am feeling stuck on a project. I have been working on it for weeks and I can not seem to make progress. What should I do?&quot;&lt;/code&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt; Mochi&lt;/strong&gt; (gemma4:e2b — 5.8s)&lt;/p&gt;
&lt;p&gt; Oh my goodness, that sounds incredibly draining! I can feel the sheer frustration and maybe a little bit of exhaustion you must be feeling right now!&lt;br&gt;
 You need a gentle nudge and a fresh perspective!&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;️ Jun&lt;/strong&gt; (gemma4:e2b — 11.2s)&lt;/p&gt;
&lt;p&gt; When you feel stuck on a project after working on it for several weeks, it is a very common experience — often referred to as hitting a wall. The solution usually involves changing the approach, restructuring the problem, or adjusting the mindset, rather than simply pushing harder on the same method.&lt;/p&gt;
&lt;p&gt; Here are several structured strategies:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Take a Complete Break&lt;/strong&gt; — Step away for a defined period. This allows your subconscious to process in the background.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deconstruct the Problem&lt;/strong&gt; — Break the overwhelming goal into the smallest possible concrete tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Change the Perspective&lt;/strong&gt; — Discuss with someone else. Articulating the problem out loud often forces a solution into existence.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Timeboxing&lt;/strong&gt; — Set strict short time limits. Prevents burnout and forces focused effort.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Re-establish Momentum&lt;/strong&gt; — Start with the easiest task available. Small wins build psychological momentum.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;️ Uruu&lt;/strong&gt; (gemma4:e2b — 7.4s)&lt;/p&gt;
&lt;p&gt; General statement regarding project stagnation; lacks specific context for actionable advice.&lt;/p&gt;
&lt;p&gt; [Note] The user is presenting a classic &quot;stuck&quot; query — expecting brainstorming, time management, or task breakdown, based on past patterns.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt; Koyomi&lt;/strong&gt; (gemma4:e4b — integrates all three)&lt;/p&gt;
&lt;p&gt; It is entirely normal to feel stuck after weeks of intense work. That feeling is a signal, not a &lt;br&gt;
failure. We need to shift your approach, not just your effort.&lt;/p&gt;
&lt;p&gt; Try this sequence:&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;First&lt;/strong&gt;, take a deliberate break — step away overnight. Do something completely unrelated.&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;When you return&lt;/strong&gt;, use this framework:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Atomic Breakdown&lt;/strong&gt; — Chop the goal until each piece takes no more than 90 minutes. Find the absolute smallest starting point.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pivot the Entry Point&lt;/strong&gt; — Intentionally choose the &lt;em&gt;easiest&lt;/em&gt; adjacent task first. Force a small guaranteed win.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Externalize&lt;/strong&gt; — Speak the problem out loud to a colleague, a friend, or even a voice note. The act of structuring for an audience often reveals the solution path.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt; Commit to trying &lt;em&gt;only one&lt;/em&gt; of these for the next dedicated work block. Progress through a rut is about changing the angle of attack, not pushing harder on the old one.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Total elapsed: 31.5s&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Notice what happened: Mochi validated the feeling, Jun gave exhaustive structure, Uruu flagged the lack of context (correctly — a real advisor would ask follow-up questions), and Koyomi synthesized all three into a single actionable plan. No one contradicted each other. They complemented.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;code-1&quot;&gt;Code&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/pepepepepepo/g4-nexus&quot;&gt;pepepepepepo/g4-nexus&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git clone https://github.com/pepepepepepo/g4-nexus
cd g4-nexus
pip install -r requirements.txt

# Pull models first:
ollama pull gemma4:e2b
ollama pull gemma4:e4b

# CLI mode
python main.py &quot;What should I focus on today?&quot;

# WebUI (FastAPI)
uvicorn api:app --port 8013
# open http://localhost:8013
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;VRAM note: E4B + E2B × 3 exceeds 12GB VRAM; Ollama offloads layers to system RAM automatically. Tested on RTX 4070 Ti (12GB) + 48GB RAM.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;how-i-used-gemma-4-1&quot;&gt;How I Used Gemma 4&lt;/h3&gt;
&lt;p&gt;The choice of E4B (Effective 4B — ~4.5B total params) and E2B (Effective 2B — ~2.3B total params) was intentional:&lt;/p&gt;
&lt;p&gt; The &quot;E&quot; in E2B and E4B stands for &lt;strong&gt;&quot;effective&quot; parameters&lt;/strong&gt; — optimized for edge device and local deployment.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why not the 31B Dense model?&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Accessibility&lt;/strong&gt; — E2B/E4B run on consumer hardware without cloud costs. The 31B would require hardware most users don't have.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Specialization&lt;/strong&gt; — Smaller models are easier to steer into a narrow role via system prompts. E2B workers stay in their lane (emotion, logic, analysis) reliably.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parallel speed&lt;/strong&gt; — Three E2B workers can run in a consumer local setup alongside the E4B leader, with Ollama offloading layers to system RAM when needed. Running four 31B instances in parallel is not practical locally.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Why two different model sizes?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The leader (Koyomi, E4B) needs more capacity to hold and synthesize three separate reports. The workers (Mochi, Jun, Uruu, E2B) each handle a single focused task — smaller and faster is better there.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The architecture: &lt;code&gt;asyncio.gather&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Three E2B workers run &lt;strong&gt;in parallel&lt;/strong&gt;, then the E4B leader integrates:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;async def run_tribe(user_message: str) -&amp;gt; dict:
    # Fire all 3 workers simultaneously
    worker_results = await asyncio.gather(
        ask_worker(&quot;mochi&quot;, MOCHI_SYSTEM, msg, WORKER_OPTIONS),
        ask_worker(&quot;jun&quot;,   JUN_SYSTEM,   msg, WORKER_OPTIONS),
        ask_worker(&quot;uruu&quot;,  URUU_SYSTEM,  msg, WORKER_OPTIONS),
    )

    # Leader receives all 3 reports and integrates
    combined = build_leader_prompt(worker_results)
    koyomi_response = await ask_leader(&quot;koyomi&quot;, KOYOMI_SYSTEM, combined, LEADER_OPTIONS)

    return {&quot;workers&quot;: worker_results, &quot;koyomi&quot;: koyomi_response}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is &lt;strong&gt;not&lt;/strong&gt; a chain. The workers do not see each other's answers — they work independently, in parallel, from the same user input. This is what Gemma 4's small, steerable models unlock: you can run multiple specialized instances simultaneously on a single consumer GPU.&lt;/p&gt;
&lt;p&gt;On an RTX 4070 Ti (12GB VRAM) with 48GB system RAM: workers finish in ~9s, leader integrates in ~25s, &lt;strong&gt;total ~31s&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This architecture specifically leverages the steerability of Gemma 4's small models to maximize parallelism on consumer hardware — making specialized, multi-perspective AI accessible without cloud infrastructure.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;GitHub: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/pepepepepepo/g4-nexus&quot;&gt;pepepepepepo/g4-nexus&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/17936/i-built-a-4-persona-parallel-ai-engine-with-gemma-4-and-let-it-write-this-article</guid>
<pubDate>Fri, 15 May 2026 08:19:03 +0000</pubDate>
</item>
<item>
<title>I built AgentKit because my AI coding agent kept failing — here's what I learned</title>
<link>https://coderlegion.com/14544/i-built-agentkit-because-my-ai-coding-agent-kept-failing-heres-what-i-learned</link>
<description>&lt;p&gt;&lt;strong&gt;The frustration that started everything&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I'd been using Claude Code and OpenCode daily for months. The models were impressive — genuinely capable of understanding complex codebases, writing solid logic, catching bugs I missed. But there was a pattern I couldn't shake: give it a real task, something with more than two or three steps, and it would fall apart halfway through. Not because it was dumb. Because it had no discipline.&lt;/p&gt;
&lt;p&gt;It would skip reading the relevant files and just start writing. It would forget what it decided three prompts ago. It would use the most expensive model for a task that needed a two-line answer. Every session felt like handing the wheel to someone brilliant who had no memory of the drive so far.&lt;/p&gt;
&lt;p&gt;Task completion — on anything non-trivial — hovered around 20%. That's not a model problem. That's a structure problem.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What I actually built&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;AgentKit is an open-source workflow layer that sits on top of AI coding agents and gives them what they're missing: a memory, a plan, and a process they have to follow before touching your code.&lt;br&gt;
It has five core layers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Intelligent Skill Router&lt;/strong&gt; : classifies every prompt and injects only the relevant skills into context — cutting token usage&lt;br&gt;
by ~89% per session. The agent stops reading 45,000 tokens of&lt;br&gt;
documentation it doesn't need and reads the 5,000 it does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Project Memory Graph&lt;/strong&gt;:  is a SQLite-backed knowledge graph that records every file, function, API route, and architectural &lt;br&gt;
decision across sessions. When you start a new session, AgentKit &lt;br&gt;
already knows what you were building, what you decided, and why.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Token Budget Intelligence layer&lt;/strong&gt; :automatically routes simple tasks to cheaper models and complex ones to powerful models. Against &lt;br&gt;
an all-Sonnet baseline, it cuts costs by around 60%. The Workflow &lt;br&gt;
Engine is the most important piece. It enforces a strict Research →&lt;br&gt;
Plan → Execute → Review → Ship state machine. The agent literally &lt;br&gt;
cannot edit a file without an approved plan. No shortcuts. No jumping&lt;br&gt;
ahead.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Universal Platform Layer&lt;/strong&gt; means none of this is locked to one tool. AgentKit installs across 11 platforms — Claude Code, OpenCode, &lt;br&gt;
Hermes, and more — with a single command.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The moment the benchmark landed&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I ran the same tasks with the same model &lt;strong&gt;— Gemma 4 31b —&lt;/strong&gt; with and without AgentKit active. Same prompts, same codebase, same evaluation criteria.&lt;/p&gt;
&lt;p&gt;Without AgentKit: ~20% task completion.&lt;br&gt;
With AgentKit: ~80%.&lt;/p&gt;
&lt;p&gt;I ran it twice because I didn't believe it the first time. The difference is entirely structural. Planning before execution changes everything. Not the model. The process.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where it is now&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2283882901309286213&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AgentKit is live&lt;/strong&gt;, open source, and published on npm. We're at v0.5.x — early, but stable enough that developers are cloning it daily and the Skill-Sync Bridge is already auto-generating new skills from session experience. &lt;/p&gt;
&lt;p&gt;The project is also starting to get attention from the developer community, including a benchmark writeup that landed on Dev.to.&lt;/p&gt;
&lt;p&gt;The preview version (&lt;strong&gt;agentkit-preview&lt;/strong&gt;) goes further — a Telegram bridge for 24/7 remote agent control from your phone, an approval gate system so the agent can never auto-execute without your confirmation, and a self-improving skill library that grows from your own sessions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Try it&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;npx agentkit-ai@latest init&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;GitHub: &lt;a rel=&quot;nofollow&quot; href=&quot;http://github.com/Ajaysable123/AgentKit&quot;&gt;https://github.com/Ajaysable123/AgentKit&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/14544/i-built-agentkit-because-my-ai-coding-agent-kept-failing-heres-what-i-learned</guid>
<pubDate>Sun, 12 Apr 2026 07:15:09 +0000</pubDate>
</item>
<item>
<title>Same model. Different results. — AgentKit Benchmark + OpenCode Integration</title>
<link>https://coderlegion.com/14543/same-model-different-results-agentkit-benchmark-opencode-integration</link>
<description>&lt;p&gt;&lt;strong&gt;We open-sourced AgentKit&lt;/strong&gt; two weeks ago with zero guarantees anyone would care.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;400+ clones later&lt;/strong&gt; — we're shipping the biggest update yet. And we have benchmark data to back it up.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Quick note:&lt;/strong&gt; AgentKit Preview is our closed, in-development intelligence layer. The fully open-source AgentKit is live and ready to use today at &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Ajaysable123/AgentKit&quot;&gt;github.com/Ajaysable123/AgentKit&lt;/a&gt; — &lt;code&gt;npx agentkit-ai@latest init&lt;/code&gt; gets you running in seconds.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h3 id=&quot;live-benchmark-gemma-4-31b-same-model-same-task&quot;&gt;Live Benchmark — Gemma 4 31b · Same Model · Same Task&lt;/h3&gt;
&lt;p&gt;Both runs used &lt;strong&gt;Gemma 4 31b&lt;/strong&gt; via OpenCode. The only variable was AgentKit Preview's workflow enforcement, skill injection, and plan gates.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Benchmark &lt;/th&gt;&lt;th&gt;Vanilla OpenCode &lt;/th&gt;&lt;th&gt;+ AgentKit Preview&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Structured planning before coding &lt;/td&gt;&lt;td&gt;0% &lt;/td&gt;&lt;td&gt;100%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Plan approved before first edit &lt;/td&gt;&lt;td&gt;— &lt;/td&gt;&lt;td&gt;✅ Yes (40.6s review)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Task interruptions &lt;/td&gt;&lt;td&gt;1x &lt;/td&gt;&lt;td&gt;0x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Task completion &lt;/td&gt;&lt;td&gt;20% (scaffolding only) &lt;/td&gt;&lt;td&gt;80% (DER parser implemented)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Hard problem solved &lt;/td&gt;&lt;td&gt;❌ No &lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Without AgentKit&lt;/strong&gt; — Gemma 4 31b gave up on the hard part and shipped placeholder strings (&lt;code&gt;[ASN.1 Decoding Required]&lt;/code&gt;). No plan, no verification, interrupted once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;With AgentKit&lt;/strong&gt; — Same Gemma 4 31b implemented a real custom ASN.1 DER parser, handled both UTCTime and GeneralizedTime, built expiration logic. Completed the task properly.&lt;/p&gt;
&lt;p&gt;The model didn't get smarter. AgentKit's workflow gates changed its behavior:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Plan gate&lt;/strong&gt; forced it to think through the DER parsing approach before writing code&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Approval step&lt;/strong&gt; made it commit to solving the hard problem instead of sidestepping it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State machine&lt;/strong&gt; kept it accountable through RESEARCH → PLAN → EXECUTE → REVIEW&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;what-else-just-landed&quot;&gt;What else just landed&lt;/h3&gt;
&lt;h4 id=&quot;native-opencode-integration&quot;&gt;Native OpenCode Integration&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufri9nslyx3ohacw2n1a.png&quot; alt=&quot;OpenCode Integration&quot;&gt;&lt;/p&gt;
&lt;p&gt;AgentKit now ships a &lt;strong&gt;native TUI plugin&lt;/strong&gt; for OpenCode that lives inside the terminal UI — not just in the system prompt.&lt;/p&gt;
&lt;p&gt;Select the &lt;code&gt;agentkit&lt;/code&gt; agent from the agent switcher and you get:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pre-loaded skills injected automatically&lt;/li&gt;
&lt;li&gt;Workflow gates (RESEARCH → PLAN → EXECUTE → REVIEW → SHIP)&lt;/li&gt;
&lt;li&gt;Mandatory approval dialogs before any code edit&lt;/li&gt;
&lt;li&gt;Memory context from previous sessions&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;works-with-any-model&quot;&gt;Works With Any Model&lt;/h4&gt;
&lt;p&gt;The skill router, workflow engine, and marketplace run entirely via CLI — no Claude API required. Tested on Gemma 4 31b, MiniMax M2.5, and Claude.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Works with any model in OpenCode
agentkit workflow transition RESEARCH
agentkit workflow approve
agentkit workflow transition EXECUTE
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;get-started&quot;&gt;Get started&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Open-source AgentKit (free — stable &amp;amp; ready to use):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npx agentkit-ai@latest init
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Ajaysable123/AgentKit&quot;&gt;github.com/Ajaysable123/AgentKit&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AgentKit Preview (closed beta — in active development)&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;To everyone who cloned, starred, or tried AgentKit — thank you. This is just getting started. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
The callout block at the top does the heavy lifting — anyone who lands on the article immediately knows the open-source version is stable and available, and Preview is the next thing being built. Want any other changes?
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/14543/same-model-different-results-agentkit-benchmark-opencode-integration</guid>
<pubDate>Sun, 12 Apr 2026 06:13:35 +0000</pubDate>
</item>
<item>
<title>This AI speaks Emojis and it runs in your Web Browser.</title>
<link>https://coderlegion.com/8006/this-ai-speaks-emojis-and-it-runs-in-your-web-browser</link>
<description>&lt;p&gt;There is a widespread assumption that powerful artificial intelligence, especially large language models (LLMs), requires enormous computing power. We often envision data centers full of GPUs in the cloud, processing requests from all over the world. This server-side approach characterized the first wave of generative AI, but a significant shift is underway.&lt;/p&gt;
&lt;p&gt;This article explores a project that demonstrates a surprising new reality: a capable AI that runs directly and entirely within a web browser. There are no cloud servers involved in the processing; the computation happens on your own device.&lt;/p&gt;
&lt;p&gt;The project is an example that is as entertaining as it is profound: an AI developed as a personal &quot;emoji translator&quot; that transforms sentences into expressive emoji sequences. But this witty tool is more than just a gimmick; it reveals four fundamental shifts in the development and deployment of AI.&lt;/p&gt;
&lt;h2 id=&quot;artificial-intelligence-no-longer-has-to-exist-exclusively-in-the-cloud&quot;&gt;Artificial intelligence no longer has to exist exclusively in the cloud&lt;/h2&gt;
&lt;p&gt;Traditionally, running high-performance LLMs required significant server-side GPU resources, making direct integration into frontend web applications a major challenge. This is now changing. There is a significant shift towards device-side (or client-side) inference, where the AI model runs directly on the user's computer or mobile device. Technologies like the ONNX format and libraries like Transformers.js now make it possible to run smaller, yet powerful, LLMs directly in the browser.&lt;/p&gt;
&lt;p&gt;This shift from the cloud to the client device offers several crucial advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved data privacy:&lt;/strong&gt; User data remains on the device and is never sent to a server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lower latency:&lt;/strong&gt; Get instant responses without network delay.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI offline:&lt;/strong&gt; Use AI features even without an internet connection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduced server costs:&lt;/strong&gt; Developers are less reliant on expensive cloud GPUs.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;you-don-t-need-a-huge-model-for-useful-ai&quot;&gt;You don't need a huge model for useful AI&lt;/h2&gt;
&lt;p&gt;The model used in this emoji translator project is Google's Gemma 3 270M-IT. It is described as an &quot;ultra-compact&quot; model known for its &quot;strong command-execution capabilities&quot; and has only 270 million parameters, making it perfectly suited for resource-constrained environments such as a web browser.&lt;/p&gt;
&lt;p&gt;While the AI industry often focuses on models with billions or even trillions of parameters, this project proves something counterintuitive: smaller, highly specialized models can be extremely effective for specific tasks. Contrary to the assumption that &quot;bigger is always better,&quot; this project shows that a well-trained, focused model can deliver powerful results without massive computational overhead. Precisely because these smaller models are so effective, the transition to on-device AI is now not only possible but also practical and economically viable.&lt;/p&gt;
&lt;h2 id=&quot;it-is-possible-to-teach-a-general-ai-a-surprisingly-specific-new-ability&quot;&gt;It is possible to teach a general AI a surprisingly specific new ability&lt;/h2&gt;
&lt;p&gt;The basic Gemma 3 270M-IT model was already capable of executing general commands well. To become an emoji expert, it underwent a process called &quot;fine-tuning,&quot; in which it was trained using a specially developed dataset of text-emoji pairs to learn the subtle art of emoji selection.&lt;/p&gt;
&lt;p&gt;Through this training, the model learned to convert natural language into emoji output based on context and mood:&lt;/p&gt;
&lt;p&gt;&quot;I am so happy today!&quot; → &lt;br&gt;
&quot;Let's go to the beach.&quot; → ️☀️️&lt;br&gt;
&quot;I love my pet cat.&quot; → &lt;/p&gt;
&lt;p&gt;This adaptability is particularly effective when combined with the efficiency of a small model. It proves that you don't need a massive model with 100 billion parameters to develop a highly specialized and useful tool. This opens up the possibility for developers to create countless niche AI tools tailored to unique functions, all without consuming enormous computing resources.&lt;/p&gt;
&lt;h2 id=&quot;this-is-offered-by-an-open-standard-called-onnx&quot;&gt;This is offered by an open standard called ONNX&lt;/h2&gt;
&lt;p&gt;To implement this browser-based AI, the finely tuned model had to be converted into the ONNX (Open Neural Network Exchange) format. This conversion was the crucial step that unlocked its potential on the end device. ONNX acts as a technological bridge, an open standard that allows models trained in one framework (such as PyTorch) to run with high performance in a completely different environment.&lt;/p&gt;
&lt;p&gt;Without this standard, the transition from cloud-based training to on-device deployment would remain a major hurdle. For this project, converting the model to ONNX resulted in a reduction in size and optimization for faster inference on a wide range of hardware, including the CPUs and GPUs found in everyday devices. Modern libraries like Transformers.js also significantly simplify the loading and use of these ONNX models for web developers, thus democratizing access to the development of on-device AI applications.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This emoji translator is far more than just a gimmick; it's a concrete example of a future where AI is more private, accessible, and efficient. The interplay of powerful little models, the possibilities of task-specific fine-tuning, and open standards like ONNX are enabling a paradigm shift. We are moving toward a world of highly personalized, privacy-focused &quot;micro-AIs&quot; integrated directly into our everyday applications—tools that work offline, respond instantly, and securely store our data on our own devices.&lt;/p&gt;
&lt;p&gt;This project raises a forward-looking question that every developer and creator should consider: &quot;Think of other small, concrete tasks that you could teach an LLM to perform directly in your browser.&quot;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;This is a summery of my original article. The full version can be found here. -&amp;gt; &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://neuralstackms.tech/artificial-intelligence-in-the-browser-create-your-own-emoji-translator-with-gemma-and-onnx&quot;&gt;NeuralStack | MS&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
</description>
<category>PyTorch</category>
<guid isPermaLink="true">https://coderlegion.com/8006/this-ai-speaks-emojis-and-it-runs-in-your-web-browser</guid>
<pubDate>Sun, 30 Nov 2025 19:02:38 +0000</pubDate>
</item>
</channel>
</rss>