Small Models for AI Agents: A Practical Guide to Low-Cost Inference
Learn how to build cost-effective AI agents by separating planning from execution, routing tasks between small and large models, and improving tool and context design. This guide covers core agent capabilities, per-task costs, structured-output validation, and task-level evaluation.
Recent industry discussion has focused less on how much larger models have become and more on how smaller models are beginning to match—or outperform—some flagship models on core AI agent capabilities. Meanwhile, free inference allowances and lower pricing have brought the cost of each completed task back into engineering discussions.
Rather than examining a particular product, this article treats these developments as a reusable engineering problem: when capability no longer maps directly to parameter count, how should developers redesign agent systems?
1. Break Down the Core Capabilities of an Agent
Evaluating an agent as a single unit often leads to the vague conclusion that “the model is not strong enough.” A more rigorous approach is to break its behavior into independently measurable capabilities:
- Instruction following: Does the model consistently follow system-level constraints, output requirements, and prohibitions?
- Structured output: Can it reliably produce machine-parseable JSON or form data without missing fields or invalid enum values?
- Tool calling: Does it select the right tool at the right time and supply valid arguments?
- Multi-step planning: Can it break a goal into ordered subtasks and revise the plan based on intermediate results?
- Error recovery: After a tool error, empty response, or timeout, can it retry, take another path, or stop appropriately?
- Long-context utilization: Can it locate relevant information in lengthy histories and tool results without being distracted by irrelevant content?
Small models can be sufficient for agent workloads not necessarily because of a broad increase in reasoning ability, but because many of these capabilities—particularly structured output and tool calling—can be substantially improved through high-quality training data, post-training, and constrained decoding.
Agent capability is therefore a collection of skills that engineering can isolate and strengthen, not a single property attainable only by increasing parameter count.
2. Measure Cost per Task, Not Model Size
Model evaluation has traditionally emphasized parameter counts and benchmark scores. For agents, the metric that determines practical viability is cost per task:
Cost per task ≈ model-call token costs across planning and execution+ retry count × cost per retry+ additional input costs from context growth
The token-cost component depends on the number of calls, input and output token volumes, and their applicable prices.
Agents are inherently multi-turn, multi-call workloads. A single user request may trigger a dozen or more model calls, each carrying a growing context. Small reductions in inference prices are therefore amplified across calls. Conversely, uncontrolled context growth can have a greater cost impact than the model’s unit price.
Free inference allowances or substantially cheaper pricing tiers have two engineering implications:
- Lower barriers to prototyping and regression testing: Teams can run evaluation sets more frequently.
- Tiered model routing becomes a default architectural choice: It is no longer merely a cost-saving technique.
3. Use Tiered Model Routing
The central idea is to separate “thinking” from “doing.” A more capable model handles infrequent planning and exception resolution, while a smaller model handles frequent execution and output formatting.
def agent_step(state):# 1) Frequent execution path: small model with strict constraintsif state.plan and not state.needs_replan:action = small_model.generate(prompt=build_action_prompt(state),response_format=TOOL_SCHEMA, # Structured-output constraintstemperature=0.0,)return execute(action)# 2) Infrequent planning path: large model, invoked only when neededif state.needs_replan or state.fail_count >= 2:state.plan = large_model.generate(prompt=build_plan_prompt(state),response_format=PLAN_SCHEMA,)state.fail_count = 0# 3) Fallback: stop after repeated failures and request user confirmationif state.fail_count >= 3:return ask_user(state)return agent_step(state)
Routing should be triggered by explicit, observable signals: repeated tool failures, plan completion falling below a threshold, or a user changing the goal. It should not depend on an ambiguous judgment that the model “feels” it needs help.
Explicit triggers make costs easier to control and failures easier to diagnose.
4. Design Tools and Context for Smaller Models
Smaller models are more sensitive to prompt noise. The engineering priority should shift from “use a stronger model” to “make the task simpler.”
- Limit tools and simplify descriptions. Too many tools can substantially reduce selection accuracy. Divide agents by business domain and expose only a small, cohesive set of tools to each subagent.
- Trim tool responses. Raw tool data is often verbose. Filter fields, paginate results, and summarize responses before adding them to the context. Retain only what the next decision requires.
- Externalize state. Store task state in explicit external structures, such as task tables and checkpoints. Include only the state relevant to the current step in the model context rather than allowing conversation history to grow indefinitely.
- Combine constrained decoding with validation. Structured output still requires server-side schema validation and automatic repair retries. Do not assume the model will produce valid output every time.
- Make tool operations idempotent and reversible. Idempotency makes retries safe, while rollback support helps recover from failures. These properties are essential when a smaller model may need multiple attempts.
5. Evaluate and Observe at the Task Level
Agent quality must be measured by task-level outcomes, not by how convincing an individual response appears.
Track the following metrics:
- Task success rate: The proportion of tasks completed end to end, broken down by business scenario.
- Cost per task and P95 latency: Hard constraints on operating cost and user experience.
- Tool-selection accuracy and argument validity: Separate choosing the wrong tool from supplying incorrect parameters.
- Average step count and retry rate: Unexpected growth in the number of steps often signals a context-design problem.
In practice, maintain a regression set of 50–200 real-world tasks. Run it whenever prompts, tool descriptions, or routing policies change.
Tracing should capture an input summary, output, duration, and token consumption for every call. Combine these traces with logging, monitoring, and alerts to create a continuous feedback loop.
Standard cloud infrastructure categories—model serving, container platforms, message queues, and object storage—can support this setup without tying it to a particular vendor.
6. Common Misconceptions
- “Small models are too weak to use.” Many failures stem from poor tool design and bloated context rather than the model alone.
- “Using the strongest model for everything is the safest approach.” Frequent calls can make cost and latency difficult to control, and a stronger model does not necessarily make fewer mistakes.
- “Free allowances mean unrestricted usage.” Production systems still need rate-limit handling, quota management, and fallback strategies. Free tiers are better suited to development and regression testing.
- “Prompt tuning is a one-time task.” Agents are continuously evolving systems. They require a stable regression set and versioned prompts.
7. A Practical Implementation Sequence
If you are starting an agent project, follow this sequence:
- Break the task into measurable capabilities and establish a regression set.
- Simplify the tools and reduce unnecessary context.
- Introduce tiered routing, with a larger model handling planning and escalation and a smaller model handling execution.
- Iterate using task success rate and cost per task.
As inference costs become less of a bottleneck, the main source of differentiation shifts back to task modeling and engineering constraints—the parts developers can control most directly.
