Gemma 4 Local: Summarize AI Agent Activity
In this article
This guide shows you how to run Gemma 4 on your own machine and use it to summarize the logs or activity reports your AI agents generate. By keeping the model local, you avoid sending sensitive agent data to external APIs, reduce latency, and gain full control over the summarization process. You'll need a computer with sufficient RAM and a GPU (or a CPU-only setup for slower but functional results), plus some basic familiarity with the command line.
What You'll Need
- A computer with at least 16 GB of RAM (32 GB recommended for larger models).
- Python 3.10 or newer installed.
- Pip package manager.
- Optional but recommended: an NVIDIA GPU with at least 8 GB VRAM for faster inference.
- Your AI agent's logs in a text format (e.g., .txt, .log, .json).
Step-by-Step
- Install Ollama. Ollama is a free, open-source tool that simplifies running large language models locally. Download the installer from ollama.com and run it. After installation, verify it works by opening a terminal and typing
ollama --version. You should see a version number. - Pull the Gemma 4 model. In your terminal, run
ollama pull gemma4. This downloads the model weights (several gigabytes) to your machine. The exact model name may vary if a newer version is released; checkollama listto see available models. Wait for the download to complete. - Prepare your agent logs. Collect the logs you want summarized. Ensure they are in a plain text file (or a few files). If your logs are in JSON, you can either convert them to text or use a small script to extract the relevant fields. For this guide, we'll assume a simple text file named
agent_logs.txt. - Create a Python script for summarization. Open a text editor and create a new file named
summarize.py. Paste the following code:
This script reads the log file, constructs a prompt asking Gemma 4 to summarize it, and runs the model via Ollama's command-line interface.import subprocess def summarize_logs(file_path): with open(file_path, 'r') as f: content = f.read() prompt = f"Summarize the following AI agent activity log in 3-5 bullet points. Focus on key actions, decisions, and outcomes.\n\nLog:\n{content}" result = subprocess.run( ['ollama', 'run', 'gemma4', prompt], capture_output=True, text=True ) return result.stdout.strip() if __name__ == '__main__': summary = summarize_logs('agent_logs.txt') print(summary) - Run the script. Save the file and run it from the terminal:
python summarize.py. The first run may take a few minutes as the model loads into memory. Subsequent runs will be faster. The summary will be printed to the console. - Customize the prompt (optional). You can adjust the prompt in the script to get different types of summaries. For example, ask for a chronological timeline, a list of errors, or a decision log. Experiment with the wording to get the output you need.
- Automate the process. To summarize logs regularly, you can schedule the script using cron (Linux/macOS) or Task Scheduler (Windows). For example, run it every hour and save the output to a file:
python summarize.py > summary_$(date +%Y%m%d_%H%M).txt.
Common Mistakes
- Using the wrong model name. Ensure you type
gemma4exactly as it appears in Ollama's model list. If you get an error like "model not found", runollama listto see the correct name. - Running out of memory. Gemma 4 is a large model. If you have less than 16 GB RAM, the process may crash. Try using a smaller variant (e.g.,
gemma4:2b) or close other memory-hungry applications. - Not escaping special characters in logs. If your logs contain quotes or backslashes, they might interfere with the prompt. Use a library like
json.dumps()to safely embed the content. - Ignoring the context window. Gemma 4 has a maximum input length. If your log file is very large, the model will truncate it. Split long logs into chunks and summarize each chunk separately.
Tips
- Use a GPU if possible. Running on CPU is noticeably slower but still works for occasional summaries.
- Keep your logs clean. The better the input, the better the summary. Remove irrelevant timestamps or debug noise before feeding them to the model.
- Experiment with different prompts. Instead of a generic summary, ask for "key decisions" or "unusual events" to get more targeted output.
- If you need structured output (e.g., JSON), ask the model to return JSON in the prompt and parse it with Python's
jsonmodule. - Store your summaries in a dedicated folder so you can track agent behavior over time.
Troubleshooting
- Ollama command not found. Make sure Ollama is installed and its binary is in your PATH. On Windows, you may need to restart your terminal after installation.
- Model download fails. Check your internet connection. If you're behind a firewall, you may need to configure a proxy for Ollama.
- Python script errors. Ensure you have Python 3.10+ and that the
subprocessmodule is available (it is by default). If you get aFileNotFoundError, theollamaexecutable is not in your PATH; provide the full path to the executable in the script. - Out-of-memory errors. Reduce the model size (e.g.,
ollama pull gemma4:2b) or use a smaller log file. Also, close other applications to free up RAM. - Summary is too long or too short. Adjust the prompt to specify the desired length. For example, "in exactly 3 bullet points" or "in 100 words or fewer".
Frequently Asked Questions
Do I need a GPU to run Gemma 4?
Not strictly. You can run it on CPU, but it will be much slower. A GPU with at least 8 GB VRAM is recommended for reasonable performance.
How much disk space does Gemma 4 require?
The model weights are around 5-10 GB depending on the variant. Make sure you have enough free space before pulling.
Can I use Gemma 4 to summarize logs in real-time?
Yes, but with latency. Each summary may take a few seconds to a minute depending on your hardware and log length. For real-time streaming, you would need to chunk the logs and call the model repeatedly.
Is it safe to process sensitive agent logs locally?
Yes, that's a key advantage of local inference. The data never leaves your machine. However, ensure your system is secure and the logs are not accessible to unauthorized users.
Can I use a different model instead of Gemma 4?
Yes. Ollama supports many models. You can replace gemma4 with any other model name in the script, such as llama3 or mistral. Just ensure you pull it first.
What if my logs are in JSON format?
You can either convert JSON to plain text using a script, or modify the Python script to parse JSON and extract the fields you want to summarize. The model can also read JSON directly if you include it in the prompt.