<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rajab Baig</title>
    <description>The latest articles on DEV Community by Rajab Baig (@rajab_baig_a3929cefc3758b).</description>
    <link>https://dev.to/rajab_baig_a3929cefc3758b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3920991%2F50162320-09ca-4dfd-9876-57b86fef30ec.jpg</url>
      <title>DEV Community: Rajab Baig</title>
      <link>https://dev.to/rajab_baig_a3929cefc3758b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajab_baig_a3929cefc3758b"/>
    <language>en</language>
    <item>
      <title>AGENT Mr. PERFECT AND GEMMA 4 E4B</title>
      <dc:creator>Rajab Baig</dc:creator>
      <pubDate>Sat, 23 May 2026 06:13:50 +0000</pubDate>
      <link>https://dev.to/rajab_baig_a3929cefc3758b/agent-mr-perfect-and-gemma-4-e4b-f99</link>
      <guid>https://dev.to/rajab_baig_a3929cefc3758b/agent-mr-perfect-and-gemma-4-e4b-f99</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/google-gemma-2026-05-06"&gt;Gemma 4 Challenge: Build with Gemma 4&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;My project is based on Google Gemma 4 variant E4B model. 1- I created an Agent that perform different agentic tasks named as tools which consists of powershell commands, content creation, coding tasks using python, html, php, c, c++ languages. I used gguf file of E4B model 4.63 GB named gemma-4-E4B-it-Q4_K_M.gguf&lt;br&gt;
I developed powerful Agentic AI - Local LLM Assistant, a high-performance desktop orchestration layer powered by the Google Gemma 4 E4B (it-Q4_K_M) model.&lt;br&gt;
As many AI assistants are confined to a chat box, my project bridges the gap between conversational AI and OS-level execution. I designed it for developers, system administrators, and power users who need a powerful local, private agent capable of managing a Windows environment through natural language.&lt;br&gt;
By leveraging the advanced reasoning and instruction-following capabilities of the Gemma 4 E4B model, the agent can intelligently select and chain together over 50+ specialized tools to perform complex system tasks. No doubt Agent Mr. Perfect works as Brain and Gemma 4 E4B as Heart in the project. &lt;br&gt;
Core Capabilities:&lt;br&gt;
🖥️ Advanced System &amp;amp; Windows Admin: The agent uses Gemma 4’s logic to generate and execute precise authorized PowerShell commands for monitoring system health, managing Windows services, inspecting registry keys, and analyzing event log and using other tools----- all without the user needing to remember complex syntax.&lt;br&gt;
💻 Multi-Language Coding Assistant: A sandbox-ready environment where the agent can write, debug, and execute code in Python, HTML, PHP, C, and C++. It doesn't just write code; it can create the files and execute them locally to verify results.&lt;br&gt;
🌐 Autonomous Web-Augmented Reasoning: When the local model identifies a gap in its training data (such as current events or specific documentation), it autonomously triggers a web search via the Tavily API, parses the results, and provides answers with verified URLs.&lt;br&gt;
📁 Intelligent File Management: A robust suite of tools for file operations (create, hash, move, search) protected by a sophisticated Self-Protection Layer that prevents the AI from modifying critical system files or its own source code.&lt;br&gt;
🛡️ Secure Local Execution: Built for privacy-conscious users, the system runs entirely on a local server (via text-generation-webui), ensuring that sensitive system data and code never leave the local machine.&lt;br&gt;
Here is the command used to load Gemma4 E4B &lt;br&gt;
python server.py --cpu --listen-host 127.0.0.1 --listen-port 7860 --loader llama.cpp --model "D:\NEW-MODELS\New folder (22)\gemma-4-E4B-it-Q4_K_M.gguf" --auto-launch&lt;br&gt;
Here is the output of generated command&lt;br&gt;
main: model loaded&lt;br&gt;
main: server is listening on &lt;a href="http://127.0.0.1:5005" rel="noopener noreferrer"&gt;http://127.0.0.1:5005&lt;/a&gt;&lt;br&gt;
main: starting the main loop...&lt;br&gt;
22:33:57-707819 INFO     Loaded "D:\NEW-MODELS\New folder (22)\gemma-4-E4B-it-Q4_K_M.gguf" in 42.22 seconds.&lt;br&gt;
22:33:57-707819 INFO     LOADER: "llama.cpp"&lt;br&gt;
22:33:57-707819 INFO     CONTEXT LENGTH: 131072&lt;br&gt;
22:37:00-762808 INFO     OpenAI/Anthropic-compatible API URL:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                     http://127.0.0.1:5000/v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Running on local URL:  &lt;a href="http://127.0.0.1:7860" rel="noopener noreferrer"&gt;http://127.0.0.1:7860&lt;/a&gt;&lt;br&gt;
As model is running on http port 7860 with chat-ui. It means user can chat directly with Gemma 4 E4B and set Question &amp;amp; Answer session with loaded model.&lt;br&gt;
And for agentic tasks I would first run my agent.py file which would use OpenAI/Anthropic-compatible API URL:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                     http://127.0.0.1:5000/v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;to make API calls to the loaded Gemma 4 E4B model i.e Agent would work as Brain and Gemma 4 E4B as Heart of the project.&lt;br&gt;
Here is the command to launch my Agent Mr. Perfect&lt;br&gt;
C:\Users\RAJAB BAIG\Documents\GitHub\BAIG\PERFECT&amp;gt;python agent.py&lt;br&gt;
It would open our GUI-Interface based Agent Mr. PERFECT&lt;br&gt;
The Brain (Agent Mr. Perfect): This is the orchestration layer of my Project. It handles the "cold logic"—the 65+ tools, the PowerShell administration, file hashing, and multi-language code execution (Python, C, PHP). It is the structural "Perfect" execution of tasks.&lt;br&gt;
My Agent Mr. PERFECT answers in FOUR STEPS ONE BY ONE.&lt;br&gt;
The Problem It Solves:&lt;br&gt;
As modern workflows often require jumping between a web browser for research or visiting a URL, a terminal for system commands, and an IDE for coding. Agentic AI combines and unifies these into a single, modern GUI. By using Gemma 4 E4B, the assistant understands the "intent" behind a user's request—like "Optimize my system for gaming"—and translates that into a series of diagnostic and administrative actions. It works as mind body relationship.&lt;br&gt;
I also added SAVE SESSION AND LOAD SESSION functionalities to make my Agent and Gemma 4 E4B project modern and robust. The Save/Load functionality transforms Agent Mr. Perfect from a temporary chat interface into a persistent engineering assistant. By capturing and ensuring the synergy between Gemma 4’s reasoning and local tool execution in a structured JSON format, I provide users with a transparent, safe, auditable, and private record of their AI-driven workflow that they can check and use anytime.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;[(&lt;a href="https://youtu.be/cbrrgWRNvkw)" rel="noopener noreferrer"&gt;https://youtu.be/cbrrgWRNvkw)&lt;/a&gt;]&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/rajab-rajab/gemma4-agentic-gui-app" rel="noopener noreferrer"&gt;https://github.com/rajab-rajab/gemma4-agentic-gui-app&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Used Gemma 4
&lt;/h2&gt;

&lt;p&gt;For this project, I chose the Gemma 4 E4B (it-Q4_K_M) model. As an "Engineering-for-Business" variant, it provides the precise reasoning required to handle system-level administration and multi-language coding tasks without the massive hardware requirements of larger dense models. As it has suitable memory space i.e 4.63 GB, it is easy to work for 20 GB RAM of mine only CPU machine. &lt;br&gt;
🧠 The Heart of the Orchestration Layer&lt;br&gt;
Gemma 4 E4B serves as the central decision-maker. Unlike standard chat models, I utilized Gemma’s advanced instruction-following capabilities to act as a Tool Orchestrator. When a user submits a prompt like "Check my CPU and if it's over 80%, tell me which process is the culprit," Gemma 4:&lt;br&gt;
Analyzes the intent.&lt;br&gt;
Selects the appropriate system tools (get_system_info and get_processes).&lt;br&gt;
Parses the raw data returned by the OS.&lt;br&gt;
Synthesizes a human-readable explanation.&lt;br&gt;
🛠️ Precision Engineering &amp;amp; PowerShell Generation&lt;br&gt;
The E4B variant shines in its ability to generate syntactically correct code. I leveraged its strengths to:&lt;br&gt;
Generate PowerShell Scripts: Gemma 4 generates complex Windows Admin commands for registry queries and service management on the fly.&lt;br&gt;
Multi-Language Logic: The model handles logic across Python, HTML, PHP, C, and C++, allowing the agent to not only write scripts but also explain the logic and debug execution errors in the local environment.&lt;br&gt;
🔍 Autonomous Reasoning &amp;amp; Web Fallback&lt;br&gt;
I implemented a "Self-Awareness" loop using Gemma 4. If the model determines that its local tools or internal training data are insufficient to answer a query (e.g., "What is the current version of React?"), it is programmed to autonomously trigger a Web Search Fallback. It then processes the search snippets to extract the most relevant information and presents them as interactive, URLs.&lt;br&gt;
🛡️ Safety and Constraint Adherence&lt;br&gt;
A critical part of using Gemma 4 was its ability to respect strict Self-Protection Rules. I provided the model with a system context that forbids it from interacting with its own source code (agent.py) or the LLM's binary files or pc system files and system disk. Through testing, Gemma 4 E4B demonstrated superior adherence to these safety guardrails compared to smaller models, ensuring the agent remains a helpful assistant rather than a system risk.&lt;br&gt;
⚡ Optimized Local Performance&lt;br&gt;
By using the 4.63 GB GGUF quantization (Q4_K_M), I achieved a balance of high intelligence and low latency. The model runs locally on consumer-grade hardware, ensuring that the system monitoring and file operations happen in near real-time, providing a "snappy" desktop experience while keeping all user data 100% private.&lt;br&gt;
"Mr. Perfect is not just a wrapper for Gemma 4; but it is a safety-first orchestration layer that translates Gemma’s engineering-grade reasoning into safe, fast, reliable, local actions."&lt;br&gt;
Here is a comprehensive list of the "Plus Points" for my project. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The "Heart &amp;amp; Brain" Architecture (Conceptual Innovation)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dual-Layer Intelligence: Instead of a generic chatbot, I have created a synergy between the Heart (Gemma 4 E4B) for high-level reasoning and the Brain (Mr. Perfect) for precise and exact and error free system execution. 
Intent Recognition: The system doesn't just "chat"; it also understands and uses engineering intent. If a user asks to "Fix the PC or want to run system commands," the agent knows to trigger diagnostic tools and commands rather than just giving advice.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Powered by Gemma 4 E4B (Model Optimization)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Engineering-for-Business (E4B) Precision: I chose the E4B variant specifically for its superior performance in generating high level technical programming code (Python, PowerShell, C++) and following complex and difficult business logic.&lt;/li&gt;
&lt;li&gt;Local Performance: By using the it-Q4_K_M GGUF quantization, I have achieved a perfect balance: high intelligence (reasoning) and accuracy with low latency (speed) on consumer-grade hardware. As it uses minimal resources in RAM and disk space.&lt;/li&gt;
&lt;li&gt;Private &amp;amp; Offline: The model runs 100% locally. A protected environment where no data ever leaves the user's machine, making it suitable and important for corporate and sensitive engineering environments.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Professional Grade Toolset (65+ Built-in Tools)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS-Level Integration: While most AI agents are "sandboxed," Mr. Perfect has deep integration with Windows via PowerShell Admin Tools, allowing for real-time system monitoring, registry edits, and service management.&lt;/li&gt;
&lt;li&gt;The Developer's Swiss Army Knife: Built-in capabilities for Code Creation, Creating files and folders, Syntax Checking, and Immediate Execution across multiple languages (Python, HTML, JS).&lt;/li&gt;
&lt;li&gt;Web-Augmented Reasoning: When local knowledge isn't enough, the agent autonomously and efficiently uses the Tavily API to fetch real-time data, presenting it with Verified URLs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Advanced Session Management (The "Black Box")&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Persistence (Save/Load): Its ability to save sessions to JSON transforms the agent from a temporary chat into a persistent workspace for developers and software engineers.&lt;/li&gt;
&lt;li&gt;Auditability: The JSON logs provide a transparent and neat record of each and every step of "Action" and "Argument," which is critical for business stability, accountability and debugging.&lt;/li&gt;
&lt;li&gt;Ease of Any time Context Restoration: Users can stop and close mid-project, save their current session, and reload it later to pick up and start exactly where Gemma 4 left off.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;"Responsible AI" &amp;amp; Safety (The Self-Protection Layer)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Self-Preservation Logic: The agent is hard-coded to never delete its own source code (agent.py) or the LLM binaries. This prevents "Agentic Suicide" or accidental system damage.&lt;/li&gt;
&lt;li&gt;System Guardrails: It recognizes protected Windows directories and system files, refusing to perform "Delete" operations on critical OS components.&lt;/li&gt;
&lt;li&gt;Human-in-the-Loop: Critical actions (like system shutdown or bulk file deletion) require explicit user confirmation through the modern GUI.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Modern &amp;amp; Intuitive UX (CustomTkinter GUI)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clean Dark Theme: A professional, tech-focused interface that reduces eye strain for long engineering and coding sessions.&lt;/li&gt;
&lt;li&gt;Dynamic Status Feedback: The UI provides real-time updates (e.g., "Step 1/4: Tool Execution: "), so the user is never left wondering what the agent is "thinking."&lt;/li&gt;
&lt;li&gt;Rich Text Features: Support for URLs, color-coded message tags. Quick Prompt buttons for common tasks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Resilient Execution (The 4-Iteration Loop)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Autonomous Problem Solving: The agent uses a multi-step thinking process while working with Gemma4. If a code execution fails, it reads the error, searches for a fix, modifies the code, and tries again—all in one session.&lt;/li&gt;
&lt;li&gt;Synthetic Final Answers: if the agent exhausts its loop during a tool call, it provides a logical summary of its actions, ensuring the user is always well informed and aware.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Clean and neat Code &amp;amp; High Portability&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single-File Power: Most of the core logic is contained in agent.py, making it incredibly easy for other developers to download, inspect, and run.&lt;/li&gt;
&lt;li&gt;Standardized Data: By using standard JSON for sessions and Markdown for code, your project integrates perfectly into existing developer workflows (like GitHub and VS Code).
I am still working on Install, Uninstall, Update, Shutdown and Restart functionalities. However, most of powershell tools are working fine.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttrupbm4ybnknwrxmscj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttrupbm4ybnknwrxmscj.png" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>gemmachallenge</category>
      <category>gemma</category>
    </item>
  </channel>
</rss>
