← Back to articles

Running AI Agents Locally: The Complete Guide to Privacy, Speed, and Cost

I moved my agents from cloud APIs to local hardware. Here's everything I learned about when it works, when it doesn't, and how to do it right.

Six months ago, I got a $500 API bill from OpenAI. One agent had gone into a loop overnight, and I’d burned through tokens while I slept. That was the moment I got serious about running models locally.

Today, about 40% of my agent workloads run on local hardware. Not because I’m paranoid about privacy—though that’s a bonus—but because the economics and control are genuinely better for certain use cases. Here’s everything I’ve learned.

Why Go Local?

Let me show you the math that convinced me.

With GPT-4 Turbo, you’re paying about $0.01 per 1,000 input tokens and $0.03 per 1,000 output tokens. A typical agent run with five reasoning steps uses around 8,000 input tokens and 2,000 output tokens, costing roughly $0.14 per task. That’s $14 per day if you run 100 tasks, which works out to $420 per month. At 1,000 tasks daily, you’re looking at $4,200 monthly.

A capable local setup costs around $1,800 one-time—$1,600 for an RTX 4090 GPU and about $200 for everything else. You break even in four to five months at 100 runs per day. After that, you’re just paying for electricity, roughly $20 per month at heavy usage.

But cost isn’t the only reason. I work with clients who have legitimate privacy requirements—healthcare data that can’t touch third-party servers, financial data with strict compliance rules, proprietary code they can’t risk exposing. “Trust me, OpenAI won’t do anything bad with your data” doesn’t fly in regulated industries. Local models solve this completely because data never leaves the machine.

Speed is another factor. Each cloud API call adds 100 to 500 milliseconds of network latency. For agents that make many calls, this compounds. A ten-step agent using cloud APIs might spend three seconds just on network round-trips, plus processing time, totaling 15 to 30 seconds. The same agent locally spends zero time on network latency—just inference time, often 10 to 20 seconds total. That’s 30-50% faster for the same work.

And then there’s availability. Cloud APIs go down. OpenAI has had multiple significant outages in the past year. Rate limits exist. Capacity constraints happen during high-usage periods. Local models run when you want them to run.

The Honest Limitations

Before you buy hardware, understand the downsides.

GPT-4 and Claude 3.5 are better than local models. Period. For complex reasoning, nuanced understanding, and novel problems, cloud models win. The gap is shrinking, but it exists.

Based on my testing (methodology similar to the model comparison article), local models achieve roughly these relative performance levels compared to GPT-4:

Task TypeLlama 3.1 8BLlama 3.1 70B (Q4)
Simple Q&A90-95%95-98%
Following instructions80-85%90-95%
Code generation65-75%80-90%
Complex reasoning50-60%70-80%
Novel problems40-50%60-70%

These are rough estimates and vary significantly by specific task. The point is: local models work well for well-defined, structured tasks but struggle compared to frontier models on tasks requiring deep reasoning or broad knowledge synthesis.

Hardware isn’t cheap either. To run useful models locally, you need real compute. And operational overhead is real—installing drivers, managing memory, handling crashes, monitoring temperature. It’s not terrible, but it’s more than zero.

Hardware Guide

The ecosystem is built for NVIDIA. Drivers work, libraries support it, tutorials assume it.

GPUVRAMUsed PriceBest For
RTX 30708GB~$3507B models only
RTX 308010GB~$4007B-13B models
RTX 309024GB~$75070B quantized, best value
RTX 409024GB~$1,60070B quantized, fastest

The RTX 3090 is the sweet spot for most users—24GB VRAM handles everything you’d reasonably run, and the used market has plenty of supply at reasonable prices.

VRAM Requirements by Model and Quantization

This is crucial for planning. The same model at different quantization levels needs dramatically different VRAM:

ModelQ4_K_MQ5_K_MQ8_0FP16
Llama 3.1 8B5GB6GB9GB16GB
Llama 3.1 70B40GB48GB75GB140GB
Mistral 7B4GB5GB8GB14GB
Mixtral 8x7B26GB32GB50GB93GB

Q4_K_M is the practical choice for most people—it’s the best balance of quality and VRAM usage. Quality loss is minimal for most tasks (roughly 1-3% on benchmarks). Q8 is noticeably better but needs twice the VRAM.

For a 24GB GPU like the 3090 or 4090: you can run Llama 3.1 70B at Q4_K_M (barely—you’ll use about 40GB with some offloading to system RAM) or comfortably run any 7B-13B model at higher quantization.

Apple Silicon

If you have a Mac, Apple Silicon handles local AI surprisingly well. The unified memory architecture means RAM equals VRAM—a 32GB Mac can run models that would need 32GB of GPU VRAM on a PC.

ConfigWhat It RunsSpeed
M1/M2 16GB7B models15-25 tok/s
M2/M3 32GB13B models comfortably, 70B squeezed15-30 tok/s
M2/M3 Max 64GB+70B models comfortably10-20 tok/s

One caveat: Apple’s Metal Performance Shaders (MPS) backend has known bugs with some models and operations. Most things work, but if you hit weird errors, check GitHub issues for your specific model—there may be workarounds or you may need to wait for fixes.

Cloud GPU Rentals

If you want local benefits without buying hardware, services like RunPod, Vast.ai, and Lambda let you rent by the hour. An RTX 4090 runs about $0.40/hour, and an A100 about $1.50/hour.

Good for testing and variable workloads. But for 24/7 operation, buying hardware is cheaper within 3-4 months.

Model Selection

Not all models work equally well for agent tasks.

Llama 3.1 8B Instruct is my default for most tasks. Best quality-to-size ratio, reliable instruction following, runs on 8GB VRAM. This handles the majority of structured agent tasks well.

Llama 3.1 70B Instruct (Q4_K_M quantization) is for when you need more capability. Near-frontier quality for many tasks, but needs 24GB+ VRAM and runs slower.

For tool use specifically, consider models fine-tuned for function calling. Hermes 2 Pro (based on Mistral 7B) and NousHermes variants are trained specifically for tool use and produce more reliable function call formatting than base models.

For code tasks, DeepSeek Coder models are strong. The 6.7B version runs fast on modest hardware and handles code generation, review, and debugging well.

Serving Options

Ollama is the easiest starting point but not the only option.

Ollama: Best for getting started. Simple installation, easy model management, good defaults. Runs one request at a time by default, which limits throughput.

llama.cpp: Lower level, more control. Supports more quantization formats and hardware configurations. Good for squeezing performance out of limited hardware.

vLLM: Designed for serving at scale. Supports continuous batching, which dramatically improves throughput when handling multiple concurrent requests. Needs more setup but handles production workloads better.

text-generation-inference (TGI): Hugging Face’s serving solution. Good balance of features and ease of use. Supports batching and streaming.

For development and personal use, Ollama is fine. For production serving with multiple users or high throughput, look at vLLM or TGI.

Getting Started with Ollama

Install Ollama—on Mac or Linux, run curl -fsSL https://ollama.com/install.sh | sh. On Windows, download the installer from ollama.com.

Pull a model:

# Start with 8B for most hardware
ollama pull llama3.1:8b

# If you have 24GB+ VRAM
ollama pull llama3.1:70b-instruct-q4_K_M

Test it:

ollama run llama3.1:8b "What is an AI agent? Answer in 2 sentences."

Ollama exposes an API at localhost:11434. Connect it to your code:

import requests

def query_ollama(prompt: str, model: str = "llama3.1:8b") -> str:
    response = requests.post(
        "http://localhost:11434/api/generate",
        json={
            "model": model,
            "prompt": prompt,
            "stream": False
        }
    )
    return response.json()["response"]

# Example
result = query_ollama("Explain RAG in one paragraph.")
print(result)

Or with LangChain:

from langchain_community.llms import Ollama

llm = Ollama(model="llama3.1:8b")
response = llm.invoke("Explain the ReAct pattern for AI agents.")
print(response)

The Hybrid Strategy

I don’t run everything locally. Here’s my actual decision process:

If the task requires frontier-model quality (complex reasoning, nuanced analysis), I use Claude or GPT-4 in the cloud. The quality gap is too large for these tasks.

If the task involves data that cannot leave the machine (client data, regulated information), I use local models regardless of other factors.

If the task is high-volume where API costs would add up significantly, I use local models. Simple, well-defined tasks run fine on Llama 8B.

If latency matters and the task is simple enough, local wins—zero network round-trip beats any API.

For everything else, I default to Claude 3.5 Sonnet as a reliable cloud option.

This results in roughly 40% of my workloads running locally. Local handles high-volume simple tasks, sensitive data, and latency-critical operations. Cloud handles complex reasoning, novel problems, and situations where I need the best quality available.

Common Problems

Out of memory: The model doesn’t fit in VRAM. Use a smaller quantization (Q4 instead of Q8), use a smaller model, close other GPU applications, or enable partial offloading to system RAM in your runner’s config.

Slow generation: Check if you’re accidentally running on CPU instead of GPU—look for CUDA/MPS initialization messages when the model loads. Try smaller quantization. Reduce context length if you’re not using it all.

Bad output quality: Not all models handle all tasks well. If output quality is poor, try a different model before assuming local AI doesn’t work for your use case. Also, local models often need clearer, more explicit prompts than GPT-4—they’re less forgiving of ambiguity.

Inconsistent results: Temperature and sampling settings matter more with smaller models. Try reducing temperature (0.3-0.5 instead of 0.7) for more consistent outputs on structured tasks.

The Bottom Line

Local AI isn’t for everything. But for high-volume workloads, sensitive data, latency-critical applications, and cost-conscious operations, it’s genuinely better than cloud APIs.

Start with Ollama and Llama 3.1 8B. See if it fits your use case. Upgrade hardware and models if you need more capability. Just don’t expect local models to match GPT-4 on complex tasks—use the right tool for the job.