CoolFace
Modelpublic

enfuse/smol-tools-4b

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
2likes26downloads
Model Card

smol-tools-4b — Agentic Tool-Use Model

A 4B parameter text-only model fine-tuned for reliable tool selection, structured JSON output, and knowing when NOT to use tools. Built on Qwen3.5-4B-Claude-4.6-Opus-Reasoning-Distilled, trained with LoRA on 6,855 quality-filtered synthetic examples.

Architecture: Qwen3_5ForCausalLM (text-only, no vision encoder). Vision weights from the base model have been stripped — this model is purpose-built for text-based tool calling.
Need longer context? See smol-tools-4b-16k (16K context) and smol-tools-4b-32k (32K context) for multi-turn agent workflows.

Available Formats

FormatSizeUse Case
BF16 safetensors (this repo)9.0 GBGPU inference with transformers / vLLM
Q8_0 GGUF4.9 GBNear-lossless quantized — Jetson Orin NX/AGX, any 8GB+ GPU
Q4_K_M GGUF2.9 GBEdge deployment — Jetson Orin Nano, phones, Raspberry Pi

GGUF files available in enfuse/smol-tools-4b-GGUF.

Results (200-example held-out eval)

MetricScore
Tool Selection F10.955
Tool Precision0.955
Tool Recall0.980
JSON Validity100%
Argument Correctness100%
No-Tool Accuracy100%

Per-Scenario Breakdown

ScenarioF1CountDescription
multitoolparallel1.00018Multiple independent tool calls
multitoolsequential1.00036Chained tool calls with dependencies
notoolneeded1.00018Questions answerable without tools
single_tool0.98153One tool call needed
error_recovery0.94418Handling malformed inputs or missing data
reasoning_heavy0.91435Complex reasoning before tool selection
complexmultistep0.81822Multi-step workflows with planning

Capabilities

  • Tool selection: Picks the right tool(s) from a provided set with 95.5% F1
  • Structured output: Produces valid <tool_call>{"name": "...", "arguments": {...}}</tool_call> JSON — 100% validity
  • Tool refusal: Correctly answers directly when no tool is needed — 100% accuracy
  • Multi-tool: Handles parallel and sequential multi-tool scenarios perfectly
  • Reasoning: Generates chain-of-thought reasoning in <think> tags before acting

Available Tools (training set)

The model was trained with these 15 tools but generalizes to new tool schemas provided at inference:

web_search, get_webpage, execute_python, read_file, write_file, list_directory, send_email, get_current_datetime, calculate, translate, get_weather, create_calendar_event, database_query, http_request, shell_command

Quick Start

python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model = AutoModelForCausalLM.from_pretrained(
    "enfuse/smol-tools-4b",  # or local path
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained("enfuse/smol-tools-4b", trust_remote_code=True)

tools = [
    {"type": "function", "function": {
        "name": "web_search",
        "description": "Search the web for information",
        "parameters": {"type": "object", "properties": {
            "query": {"type": "string"}
        }, "required": ["query"]}
    }}
]

messages = [
    {"role": "system", "content": "You are a helpful assistant with access to tools."},
    {"role": "user", "content": "What's the latest news about SpaceX?"},
]

prompt = tokenizer.apply_chat_template(messages, tools=tools, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=512, temperature=0.1, do_sample=True)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False))

With vLLM (faster)

python
from vllm import LLM, SamplingParams

llm = LLM(model="enfuse/smol-tools-4b", dtype="bfloat16", max_model_len=4096, enforce_eager=True)
sampling = SamplingParams(max_tokens=2048, temperature=0.1, stop=["<|im_end|>"])
outputs = llm.generate([prompt], sampling)

Output Format

The model responds with optional thinking followed by tool calls or a direct answer:

With tool call:

<think>
The user wants to search for SpaceX news. I should use the web_search tool.
</think>

I'll search for the latest SpaceX news for you.

<tool_call>
{"name": "web_search", "arguments": {"query": "latest SpaceX news"}}
</tool_call>

Without tool call (direct answer):

<think>
This is a general knowledge question I can answer directly without any tools.
</think>

The capital of France is Paris. It has been the capital since...

Training Details

ParameterValue
Base modelQwen3.5-4B-Claude-4.6-Opus-Reasoning-Distilled
MethodLoRA (rank 32, alpha 64)
Target modulesqproj, kproj, vproj, oproj, gateproj, upproj, down_proj
Training examples6,855 (4,578 quality-filtered + 2,277 targeted)
Epochs3
Batch size4 (× 8 gradient accumulation = effective 32)
Learning rate1e-4 (cosine schedule)
Max sequence length4,096
Training loss0.160
Token accuracy95.7%
Training time~5.3 hours on 1× NVIDIA H200
FrameworkTRL SFTTrainer + PEFT

Data Pipeline

  1. 1.Teacher model: Qwen3.5-27B-Claude-4.6-Opus-Reasoning-Distilled generated synthetic tool-use conversations
  2. 2.Quality filtering: Removed examples with malformed JSON, missing tool calls, or incorrect tool usage (5,000 → 4,578)
  3. 3.Targeted generation: Generated 2,277 additional examples focusing on reasoning_heavy and complex_multi_step scenarios with explicit <think> tag prompting
  4. 4.Combined dataset: 6,855 examples across 7 scenario types

What Worked (Experiment Log)

ExperimentF1Key Finding
Base model (no training)0.888Strong baseline from Claude distillation
R1: 5K unfiltered data0.913Fine-tuning helps
R2: 15K unfiltered data0.905More dirty data hurts
R3: 4.6K filtered data0.950Data quality > quantity
R3: 6.9K filtered + targeted0.955Targeted reasoning data helps
R4: 13.6K all-clean data0.935Too much data overfits
R4: 5 epochs0.920More epochs overfits
R5: Higher LoRA rank (64)0.930Rank 32 is sufficient
R5: Lower LR (5e-5)0.9101e-4 is optimal

smol-tools Family

All models share the same base architecture, tool schema, and output format. Choose based on your context length needs:

ModelContextTool F1JSON ValidNo-Tool AccParametersHF Repo
smol-tools-4b4K0.955100%100%Rank 32, α=64this repo
smol-tools-4b-16k16K0.948100%100%Rank 64, α=128enfuse/smol-tools-4b-16k
smol-tools-4b-32k32K0.940100%100%Rank 64, α=128enfuse/smol-tools-4b-32k

How to choose:

  • 4K (this model): Single-turn tool calls, short tool outputs — highest accuracy, lowest memory
  • 16K: Multi-turn conversations (5-10 rounds), moderate tool outputs — also available in GGUF quantized formats
  • 32K: Extended agent sessions (10-20 rounds), large tool outputs — also available in GGUF quantized formats

When to Use This Model

  • You're building an agent or copilot on the edge — local devices, Jetson, phones, on-prem servers with limited GPU
  • You need thousands of tool-calling inferences per minute cheaply — a 4B model serves 10–50x faster than a 70B at a fraction of the cost
  • You need structured output you can trust — 100% JSON validity means no crashed pipelines from malformed tool calls
  • You're tired of paying per-token API costs for tool-use that a small local model can handle

When NOT to Use This Model

  • If your agent needs multi-turn conversations or long tool outputs, use smol-tools-4b-16k or smol-tools-4b-32k instead
  • If you need GPT-4-level complex multi-step planning (our weakest category at F1=0.818), use a bigger model
  • If latency and cost don't matter, just call a frontier API — they'll outperform any 4B model on hard reasoning
  • If your use case requires tools not seen during training, test carefully — the model generalizes to new tool schemas but hasn't been validated on every possible tool type

Limitations

  • complex_multi_step scenarios (F1=0.818) remain the weakest — the model sometimes struggles with multi-step planning involving 3+ chained tools
  • No thinking rate in evaluation (0%) — the model reasons but doesn't always use explicit <think> tags at low temperature
  • Trained on synthetic data only — real-world tool-use patterns may differ
  • Inherits Qwen3.5-4B base model limitations (context window, knowledge cutoff)

Hardware

  • Training: 1× NVIDIA H200 NVL (141 GB HBM3e)
  • Inference (BF16): Any GPU with ≥10 GB VRAM
  • Inference (Q8_0 GGUF): Any device with ≥6 GB RAM — Jetson Orin NX, consumer GPUs
  • Inference (Q4_K_M GGUF): Any device with ≥4 GB RAM — Jetson Orin Nano, phones, Raspberry Pi 5

Attribution