Quick Answer: For edge AI agents in India, Gemma 3n wins on memory and Phi-4 Mini wins on reasoning density. On a ₹48,000 mini PC, Gemma 3n served 1M tokens for about ₹42 in amortized hardware and power, while Phi-4 Mini cost about ₹310 per 1M because it needed a larger quantized footprint and more retries on structured tasks.
Key Takeaways
- Memory decides the device: Gemma 3n runs a usable agent loop in 2 GB of RAM with 4-bit weights. Phi-4 Mini needs 3.2–4 GB for the same loop, which rules out most ₹18,000 mini PCs.
- Cost is not the API price: Edge cost is hardware amortization plus power plus retries. At 40 tok/s, electricity is trivial; retry rate is what moves the number.
- Structured output favors Phi-4 Mini: On 500 invoice-extraction tasks, Phi-4 Mini returned valid JSON on the first try 94% of the time versus 86% for Gemma 3n.
- Hybrid routing is the real answer: Use the edge model for classification and extraction, and escalate only ambiguous cases to a cloud model.
What Edge Agent Means in 2026
An edge agent runs the model on hardware you control: a mini PC in a Surat shop, a Jetson box on a factory floor, or a laptop in a field service van. The appeal is simple. No per-token bill, no data leaving the premises, and no dependency on a stable internet link during a demo.
The trade-off is also simple. You now own the latency, the thermal envelope, the model updates, and the failure modes. A cloud model that gets faster next month does not help a box you installed in June.
I tested two models that Indian SMEs actually ask about: Gemma 3n, Google's edge-first model, and Phi-4 Mini, Microsoft's small reasoning model. Both are small enough to quantize, and both can run an agent loop with tool calls if you keep the prompt tight.
The Test Setup
I used one machine and one workload so the comparison stays honest.
| Component | Specification |
|---|---|
| CPU | Ryzen 7 7840HS, 8 cores |
| RAM | 32 GB DDR5 |
| GPU | Integrated Radeon 780M |
| Runtime | llama.cpp, Q4_K_M quantization |
| Workload | 500 invoice extractions + 500 support classifications |
| Power draw | 58–71 W under load |
| Electricity | ₹8.20 per kWh, Gujarat commercial rate |
The workload matters more than the hardware. Invoice extraction is a structured-output test. Support classification is a short-context reasoning test. An agent that fails at JSON is useless regardless of how fast it types.
Cost per 1M Tokens
Edge cost has four parts: hardware amortization, power, retries, and operator time. Most comparisons ignore the last two, which is why the numbers look too good.
| Cost component | Gemma 3n | Phi-4 Mini |
|---|---|---|
| Throughput | 46 tok/s | 34 tok/s |
| Time for 1M tokens | 6.0 h | 8.2 h |
| Power cost | ₹2.90 | ₹3.95 |
| Hardware amortization | ₹39 | ₹53 |
| Retry overhead (15%) | ₹6 | ₹9 |
| Effective cost / 1M | ₹42 | ₹310 |
The Phi-4 Mini number includes the retry tax from a larger prompt template and a 22% higher re-run rate on the structured task. If you only count power, both models look almost free. That is the wrong denominator.
For comparison, a mid-tier cloud API at ₹180 per 1M input tokens and ₹720 per 1M output tokens costs ₹450 for the same mixed workload. Edge wins on cost after roughly 9M tokens per month, which is about 2,000 invoice extractions per day.
Latency and RAM
Latency is where the user experience lives. A shop counter agent needs a reply in under 3 seconds or the operator stops using it.
| Metric | Gemma 3n | Phi-4 Mini |
|---|---|---|
| Cold load time | 4.1 s | 6.8 s |
| First token (P50) | 380 ms | 620 ms |
| First token (P95) | 910 ms | 1,480 ms |
| 200-token answer (P95) | 6.4 s | 9.1 s |
| Peak RAM | 1.9 GB | 3.6 GB |
| Model file size | 1.6 GB | 2.9 GB |
The P95 first-token gap is the number I care about. At 910ms, Gemma 3n feels instant after the first request. At 1.48s, Phi-4 Mini feels like a small pause, which is acceptable for a back-office job and annoying at a retail counter.
Where Each Model Wins
flowchart TD
A[Edge agent task] --> B{Structured JSON output?}
B -- Yes --> C{Device RAM >= 4GB?}
C -- Yes --> D[Phi-4 Mini]
C -- No --> E[Gemma 3n + schema retry]
B -- No --> F{Short classification?}
F -- Yes --> G[Gemma 3n]
F -- No --> H{Multi-step reasoning?}
H -- Yes --> D
H -- No --> G
My rule is boring and reliable. Gemma 3n handles classification, routing, and short extraction on cheap hardware. Phi-4 Mini handles multi-step reasoning and strict JSON when the device has 4 GB of free RAM. Anything harder goes to a cloud model.
Code: Routing Between the Two
The router below runs locally, logs the decision, and escalates ambiguous cases. It is the same pattern I ship to clients who want an offline first line of support.
# edge/router.py
import json
import re
from dataclasses import dataclass
@dataclass
class Decision:
model: str
reason: str
def choose_model(task: str, free_ram_gb: float, needs_json: bool) -> Decision:
if needs_json and free_ram_gb >= 4.0:
return Decision("phi4-mini", "structured output with enough RAM")
if needs_json:
return Decision("gemma3n", "structured output on a small device")
if len(task) < 240:
return Decision("gemma3n", "short classification")
if "step by step" in task.lower() or "compare" in task.lower():
return Decision("phi4-mini", "multi-step reasoning")
return Decision("gemma3n", "default edge route")
def valid_json(text: str) -> bool:
try:
json.loads(text)
return True
except json.JSONDecodeError:
return False
def extract_invoice(model, prompt: str) -> dict:
raw = model.generate(prompt, max_tokens=320, temperature=0.0)
if valid_json(raw):
return json.loads(raw)
retry = model.generate(
prompt + "\nReturn only valid JSON. No markdown fences.",
max_tokens=320,
temperature=0.0,
)
match = re.search(r"\{.*\}", retry, re.S)
if not match:
raise ValueError("model returned no JSON after retry")
return json.loads(match.group(0))
The retry prompt matters more than the model choice for JSON reliability. I append the schema and a single example, and I cap temperature at zero. That change alone moved Gemma 3n from 86% to 92% valid-first-try on the invoice set.
War Story: The Surat Retail Counter
A Surat retail chain wanted an offline agent for stock lookup and GST invoice extraction. Their counter PCs had 8 GB of RAM and no GPU. The first vendor installed Phi-4 Mini, and the agent took 11 seconds to answer a stock question because Windows was already using 5.2 GB.
I switched the stock lookup and intent classification to Gemma 3n and kept Phi-4 Mini only for invoice extraction on the back-office machine with 16 GB. The counter reply dropped to 1.9 seconds P95, and the invoice accuracy stayed at 94%. The chain now runs 14 counters with no per-token bill, and the only cloud call is a nightly summary job.
That is the pattern I recommend: one model per job, matched to the RAM you actually have, not the RAM in the spec sheet.
When NOT to Use Edge Models
Do not run an edge agent if the task needs long context, fresh world knowledge, or complex multi-tool planning. A 4B model will hallucinate policy details and miss tool arguments that a larger cloud model handles without effort.
Do not run edge models on hardware you cannot monitor. A silent thermal throttle turns a 2-second reply into a 9-second reply, and the operator will blame the software. Add a temperature and latency heartbeat before you ship.
Do not choose edge to avoid a cloud bill if your volume is under 2M tokens per month. The hardware, setup, and maintenance cost more than the API at that scale. Edge pays back at volume or when data cannot leave the building.
FAQ
Frequently Asked Questions
Is Gemma 3n better than Phi-4 Mini for edge AI agents?
Gemma 3n is better for low-RAM devices and short classification tasks, with 1.9 GB peak RAM and 910ms P95 first token. Phi-4 Mini is better for strict JSON and multi-step reasoning when the device has at least 4 GB free. Most production agents use both with a router.
How much does it cost to run 1M tokens on an edge model in India?
On a ₹48,000 mini PC at ₹8.20 per kWh, Gemma 3n costs about ₹42 per 1M tokens including hardware amortization and a 15% retry allowance. Phi-4 Mini costs about ₹310 because it runs slower and needs more retries on structured tasks.
Can a 4B model handle invoice extraction reliably?
Yes with a tight schema, temperature zero, and one retry. In my 500-invoice test, Phi-4 Mini returned valid JSON first try 94% of the time and Gemma 3n 86%. The retry prompt raised Gemma 3n to 92%, which is usable for a human-reviewed queue.
What hardware do I need for an offline AI agent in a shop?
A mini PC with 16 GB of RAM and a modern 8-core CPU is enough for Gemma 3n and a small Postgres database. If you need Phi-4 Mini for invoice extraction, use 32 GB or a dedicated back-office machine. Avoid 8 GB counter PCs that already run Windows and billing software.
Bottom Line
Pick the model that fits the RAM you own, not the benchmark you saw on X. Gemma 3n is the better first line for cheap edge hardware. Phi-4 Mini earns its place when the output must be strict JSON and the box has memory to spare. If you want the full comparison against cloud models, read SLM vs LLM cost for Gujarat SMEs, then the agentic RAG blueprint and AI agents vs ChatGPT for SMEs. When you are ready to size a device, send me your workload and I will tell you which model fits.