By Sagar Shankaran, Founder of CallSphere
Deploy AI agents on edge devices using Google's Gemma and Microsoft's Phi small language models. Cover resource requirements, agent patterns for constrained environments, and mobile deployment strategies.
Key takeaways
Not every agent needs a 70B parameter model. Many practical agent tasks — classification, extraction, simple Q&A, form filling, and basic tool calling — can be handled by models with 2-4 billion parameters. Small Language Models (SLMs) open up deployment scenarios that large models cannot reach: mobile phones, IoT devices, laptops without GPUs, and environments with no internet connectivity.
Google's Gemma and Microsoft's Phi families lead the SLM space. Both deliver surprisingly strong performance relative to their size, often matching models 3-5x larger on targeted benchmarks.
Gemma 2 2B — Google's smallest model. 2.6B parameters, trained on 2 trillion tokens of web data. Excels at summarization, classification, and code generation for its size. Licensed under a permissive Gemma license for commercial use.
flowchart LR
INPUT(["User intent"])
PARSE["Parse plus<br/>classify"]
PLAN["Plan and tool<br/>selection"]
AGENT["Agent loop<br/>LLM plus tools"]
GUARD{"Guardrails<br/>and policy"}
EXEC["Execute and<br/>verify result"]
OBS[("Trace and metrics")]
OUT(["Outcome plus<br/>next action"])
INPUT --> PARSE --> PLAN --> AGENT --> GUARD
GUARD -->|Pass| EXEC --> OUT
GUARD -->|Fail| AGENT
AGENT --> OBS
style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style OBS fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
Gemma 2 9B — The mid-range option. Outperforms Llama 3.1 8B on several benchmarks while being slightly more efficient to serve.
Phi-3.5-mini — Microsoft's 3.8B model. Trained on a mix of filtered web data and synthetic data generated by larger models. Remarkably strong at reasoning and code generation.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
Phi-3-small — 7B parameters with a focus on reasoning. Competes with larger models on math and logic benchmarks.
Using Ollama is the quickest way to get started:
# Pull Gemma 2B (1.6 GB)
ollama pull gemma2:2b
# Test it
ollama run gemma2:2b "Classify this as positive or negative: The product is excellent"
For Python integration:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:11434/v1",
api_key="ollama",
)
def classify_sentiment(text: str) -> str:
response = client.chat.completions.create(
model="gemma2:2b",
messages=[
{"role": "user", "content":
f"Classify the sentiment as positive, negative, or neutral. "
f"Respond with one word only.\n\nText: {text}"},
],
temperature=0.0,
max_tokens=5,
)
return response.choices[0].message.content.strip().lower()
print(classify_sentiment("This product exceeded my expectations!")) # positive
print(classify_sentiment("The delivery was late and the item was damaged.")) # negative
Phi models are optimized for ONNX Runtime, making them deployable on a wide range of hardware including CPUs and mobile NPUs:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "microsoft/Phi-3.5-mini-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a concise assistant that extracts structured data."},
{"role": "user", "content": "Extract the name, date, and amount from: "
"Invoice from John Smith dated March 15, 2026 for $2,500."},
]
inputs = tokenizer.apply_chat_template(
messages, return_tensors="pt", add_generation_prompt=True
).to(model.device)
outputs = model.generate(inputs, max_new_tokens=100, temperature=0.1, do_sample=True)
result = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
print(result)
SLMs require different agent design patterns than large models. The key principle is to simplify the task structure so the model can handle each step reliably.
Pattern 1: Single-Purpose Agents — Instead of one general agent, deploy multiple specialized micro-agents:
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
class EdgeAgentRouter:
def __init__(self, client):
self.client = client
def route(self, user_input: str) -> str:
# Step 1: Classify intent with the SLM
intent = self._classify_intent(user_input)
# Step 2: Route to specialized handler
handlers = {
"weather": self._handle_weather,
"reminder": self._handle_reminder,
"question": self._handle_question,
}
handler = handlers.get(intent, self._handle_question)
return handler(user_input)
def _classify_intent(self, text: str) -> str:
response = self.client.chat.completions.create(
model="gemma2:2b",
messages=[{"role": "user", "content":
f"Classify this user request into one category: "
f"weather, reminder, question.\n"
f"Respond with the category only.\nRequest: {text}"}],
temperature=0.0,
max_tokens=10,
)
return response.choices[0].message.content.strip().lower()
def _handle_weather(self, text: str) -> str:
# Extract city, call weather API
return "Weather handler triggered"
def _handle_reminder(self, text: str) -> str:
# Extract time and message, set reminder
return "Reminder handler triggered"
def _handle_question(self, text: str) -> str:
response = self.client.chat.completions.create(
model="gemma2:2b",
messages=[{"role": "user", "content": text}],
temperature=0.3,
max_tokens=200,
)
return response.choices[0].message.content
Pattern 2: Structured Output with Constrained Generation — Use explicit output formats to compensate for smaller models' tendency to be less structured:
def extract_entities(client, text: str) -> dict:
response = client.chat.completions.create(
model="phi3.5:latest",
messages=[{"role": "user", "content":
f"Extract entities from this text. Respond in exactly this format:\n"
f"NAME: <name or NONE>\n"
f"DATE: <date or NONE>\n"
f"AMOUNT: <amount or NONE>\n\n"
f"Text: {text}"}],
temperature=0.0,
max_tokens=50,
)
result = {}
for line in response.choices[0].message.content.strip().split("\n"):
if ": " in line:
key, value = line.split(": ", 1)
if value.strip() != "NONE":
result[key.strip()] = value.strip()
return result
| Model | Parameters | RAM (Q4) | Tokens/sec (CPU) | Tokens/sec (GPU) |
|---|---|---|---|---|
| Gemma 2 2B | 2.6B | 1.8 GB | 15-25 | 80-120 |
| Phi-3.5-mini | 3.8B | 2.5 GB | 10-20 | 60-100 |
| Gemma 2 9B | 9.2B | 5.5 GB | 5-10 | 40-70 |
| Phi-3-small | 7B | 4.5 GB | 5-12 | 35-60 |
CPU token rates are measured on a modern laptop (Apple M2 / Intel i7-13th gen). GPU rates are on an RTX 3060 12 GB.
For narrowly scoped tasks like classification, entity extraction, and template-based responses, yes. A Gemma 2B model fine-tuned on your specific task can be remarkably reliable. For open-ended reasoning or complex multi-step tool calling, you need at least a 7B model.
Use the GGUF format with llama.cpp compiled for ARM. On Android, libraries like android-llama.cpp provide JNI bindings. On iOS, use llama.cpp with Metal for GPU acceleration. Expect 5-15 tokens/second on flagship phones with quantized 2-3B models.
Fine-tuning is more impactful for SLMs than for large models. A generic 2B model may struggle with your specific output format, but a fine-tuned version can match larger models on that narrow task. Use LoRA fine-tuning with 500-2000 examples of your expected input/output pairs for the best results.
#Gemma #Phi #SmallLanguageModels #EdgeAI #MobileDeployment #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
By 2026, sub-10B models beat 2024-era GPT-4 on most benchmarks. The Phi-4, Gemma-3, and SmolLM-3 family compared head-to-head.
On-device voice LLMs are now real. What Apple Intelligence, Gemini Nano, and Phi-4 ship in 2026 — and what they cannot do yet.
Sub-$250 NVIDIA Jetson Orin Nano Super runs a full Whisper + 8B LLM + Piper voice loop offline at 15 tok/s. Here's the full Docker-based build with thermals, models, and code.
How to run AI agents on edge devices using NVIDIA Nemotron, Meta Llama, GGUF quantization, local inference servers, and offline-capable agent architectures.
Edge AI runs inference directly on devices, eliminating cloud latency and enabling real-time decisions. Learn how on-device AI works and where it delivers the most value.
Learn how to export AI agent models to ONNX format, optimize them with ONNX Runtime, and deploy cross-platform for consistent inference performance on any hardware.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.