
needle
14MB on-device LLM for tool calling on edge devices
Replaces Picovoice, Openai Api, Google Cloud Vertex Ai Gemini

Who it's for
Needle fits edge devices that need a persistent tool-calling agent without cloud connectivity. Declare your device's actuators as tools, pass the user query, and the model returns a grammar-guaranteed call. No API key, no network round-trip, no per-token billing.
Your device has a reliable network connection and latency is not a constraint. Cloud function-calling APIs offer larger context and more capable reasoning for connected scenarios.
The needle.extract() helper takes a Pydantic model and a text string and returns a typed object. Because extraction is tool calling with one declared schema, schema conformance is guaranteed. Fits document parsing, receipt extraction, and entity recognition steps in ETL pipelines.
Your source text exceeds roughly 200 tokens. The 256-token context limit makes Needle unsuitable for full-document extraction; chunk or preprocess the text first.
The LoRA fine-tuning workflow synthesizes training data from your tool schemas, fine-tunes on the frozen base, and exports a self-contained .cact that runs on the same engine. The tuned model is a drop-in weight replacement with no recompilation needed.
Your tool schemas are general-purpose and similar to standard function-calling patterns. The base model already handles common tool-calling tasks without fine-tuning.
The problem
Running capable AI agents on tiny devices has a hardware problem: most language models need gigabytes of RAM and depend on cloud APIs for every inference call. A phone, robot, or smart home hub running an agentic workflow cannot afford the latency, bandwidth, or per-token cost of routing every tool call to a cloud provider. The output reliability problem compounds the hardware constraint. Cloud function-calling APIs return probabilistic text that application code must parse and validate before acting on. Schema mismatches, hallucinated arguments, and malformed JSON are recurring failure modes, each requiring error-handling code that adds latency and complexity. On a device where a failed call cannot cheaply retry against a larger model, that failure handling is the difference between a working agent and a broken one.
How it works
Every token the model emits is constrained by a byte-level grammar compiled from your tool schemas. The result is JSON that is guaranteed to conform to your schema, not just likely to. The model cannot produce a malformed argument or invent a field not declared in the schema.
Weights and inference engine are baked into a single 14MB binary. A full conversation session runs in approximately 28MB of RAM. There are no separate model files to manage and inference makes no network calls after the one-time engine download.
Every response carries a confidence score computed from two signals: a calibrated post-hoc scoring head and the decoding probability of the call tokens. A call is accepted only when both agree. Set a threshold, act above it, and route to a larger model below it.
Declare more than five tools and a built-in contrastive retrieval head embeds each schema once, then selects the five highest-scoring tools per turn. The grammar rebuilds over only that subset. An unselected tool is unreachable, not just unlikely, so the model focuses correctly.
Fine-tune on your domain with LoRA on the frozen base. At export the adapter merges into the base and quantizes to a single .cact file that runs on the same engine with no recompilation. Training data can be synthesized from your tool schemas with the needle generate-data command.
A 256-token sliding window keeps tools pinned as KV sinks, so total session memory stays near 28MB regardless of conversation length. Long agentic loops do not accumulate unbounded memory over time.
Features
- Grammar-constrained tool calling
- 14MB single-binary engine
- Calibrated confidence scoring
- Tool retrieval for large catalogues
- LoRA fine-tuning and single-file export
- Bounded memory across long sessions
How to install
Install via pip; the inference engine downloads from Hugging Face on first use and caches locally.
pip install cactus-needleRecommended for this setup
Strengths
- No cloud dependency at inference time: After the one-time engine download, inference runs fully offline. No API keys, no per-token billing, no network round-trip latency. This matters for robotics, offline assistants, and edge devices where network connectivity is intermittent or restricted.
- Smallest model in its benchmark class: At 14MB in CQ2-bit quantization, Needle 2 is 5x to 70x smaller than FunctionGemma 270M, LFM2.5 230M, and Apple FM while trading benchmark wins on tool-calling tasks. The size difference is what makes it the only option when device RAM is below 100MB.
- Schema-guaranteed structured output: Decoding is constrained by a compiled byte-level grammar, so JSON output is always schema-conformant. Application code does not need to validate the model's response before acting on it. This removes an entire class of error handling from on-device agent code.
- MIT license with no usage restrictions: MIT license means you can run it commercially, fork it, and integrate it into proprietary products without restriction. No AGPL copyleft, no commercial use clause, no per-seat fee.
Trade-offs
- No free-text generation: Needle solves every request as a function call. A query that no declared tool can serve returns an empty call [] with no text output. There is no free-text fallback. If your use case requires a mix of tool calls and conversational responses, a general-purpose LLM with optional tool use is the right fit instead.
- 256-token context window: The sliding context window caps usable context at 256 tokens. Long or complex queries that require reasoning over extended input will exceed the window. Needle is designed for short, task-focused exchanges, not document-length reasoning or multi-turn planning over large histories.
- Python-only package: The pip package is Python-only. Integrating Needle into non-Python runtimes requires calling the engine via subprocess or waiting for additional language bindings to be released by the Cactus Compute team.
Tech stack
FAQ
Yes. Needle is MIT licensed. You can use it commercially, fork it, and integrate it into proprietary products without restriction. The only cost is the compute on your own device or server.
OpenAI's function calling requires a network call to OpenAI's servers; there is no on-device option. Needle runs entirely on-device with no network dependency at inference time, at the cost of a smaller context window (256 tokens vs thousands) and no free-text generation. For tool-calling tasks on edge hardware, Needle trades benchmark wins with models 5x to 70x its size.
No. Needle solves every request as a function call. A query that no declared tool can serve returns an empty call [] with no text output. If you need a mix of tool calls and conversational language generation, you need a different model. Needle is purpose-built for structured output only.
Install with pip install cactus-needle. The inference engine downloads once from Hugging Face on first use and caches locally. Subsequent runs are fully offline. Describe your tools with the @needle.tool decorator and call agent.run() to query the model.
Any device with a Python runtime and approximately 28MB of available RAM. The README lists phones, wearables, smart home hubs, robots, and microcontrollers as target hardware. The model weights and engine together are 14MB.