惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
美团技术团队
腾讯CDC
博客园 - Franky
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
aimingoo的专栏
aimingoo的专栏
博客园_首页
V
V2EX
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Crew with Gemma-4 in Colab
Aman Kr Pand · 2026-04-26 · via DEV Community

Let me walk you through something I have been experimenting with lately, running a local AI agent that detects hate speech, powered by Google's Gemma 4 model and the CrewAI framework, all without calling any paid API. No keys, no credits. Just a local model and python. Let me explain how I put this together.

Why Gemma + CrewAI?

Most CrewAI tutorials you will find online default to GPT-4 or Claude. That is fine, but what if you want to run everything locally, maybe for privacy or cost reasons, or just to understand the stack at a deeper level?

Well, I could have gone with Meta's Llamma3.2 3B model, that is a good opensource alternative as well, but Gemma 4 is new and I just wanted to try it, but you can use any opensource model available on Hugging face.

The model I used is google/gemma-4-E2B-it, a 2-billion parameter instruct-tuned version of Google's Gemma 4. It is light enough to run on Colab GPU without any resource crunches, and it loads via Hugging Face transformers library.

The Problem: CrewAI Doesn't Talk to Transformers

CrewAI Agent class expects an LLM object, but out of the box, it only works well with OpenAI-compatible APIs. So I had to build a custom LLM class by inheriting BaseLLM from CrewAI.

Gemma4CrewAILLM class which extends BaseLLM overrides the call() method to handle message formatting and generation manually.

class Gemma4CrewAILLM(BaseLLM):
    def call(self, messages, tools=None, ...):
        # Convert messages to Gemma's format
        # Apply chat template via processor
        # Run model.generate()
        # Strip the prompt from output and return clean text

Enter fullscreen mode Exit fullscreen mode

The key insight here is that Gemma uses AutoProcessor for both tokenization and chat templating, and I had to be careful to set enable_thinking=False to skip the "thinking tokens" that the model might generate.

Defining the Agent and Task

Once the Gemma4CrewAILLM was ready, plugging it into CrewAI was straightforward. I defined a Hate Speech Detection Specialist agent with a detailed role, goal, and backstory, because CrewAI uses these as system-prompt context to guide how the agent reasons.

The task I gave it was to analyze a piece of text and produce a structured 3-bullet report:

  • Verdict: Yes / No / Uncertain with a reason
  • Detected Content: Specific phrases flagged, plus the targeted group
  • Severity and Recommendation: A numeric rating out of 10, plus a recommended action (Allow / Flag for Review / Remove)

This structure forces the model to be accurate rather than giving summaries, which is exactly what you want in a content moderation pipeline.

Here is my gist for your reference Link.

What should I do Next?

This setup is good for trying out new things or development while saving your pockets from expensive tokens. But here are some improvements/extensions that could be done:

  • Add more agents: a second agent for sentiment or intent classification working in parallel
  • Try function calling / tools: Gemma 4/Llamma 3.2 supports structured outputs which could make the crew much more powerful
  • Wrap it in a FastAPI endpoint: so you can POST text and get back a structured moderation report over HTTP

The whole point for me was to prove that we can build a capable, agentic AI pipeline with zero API costs, running entirely on open-weights models. And honestly, for a 2B parameter model, Gemma 4 handles this task well. With models like Llamma-3.2 7B or Gemma-4 4B we can get better results.

If you have been trying local LLMs for agent workflows, I hope you will find this post helpful. Drop your questions or thoughts in the comments, I would love to hear what use cases you are/were thinking about agents.