Views
No views yet



pip install cactus-needlerun() completes the loop: model picks the call, Needle executes your function, feeds the result back, and returns the model's final answer.1import needle
2
3@needle.tool
4def get_weather(city: str):
5 "Get the current weather for a city."
6 return {"city": city, "temp_c": 27, "sky": "clear"}
7
8agent = needle.Needle(tools=[get_weather])
9print(agent.run("what's it like in Lagos right now?")["reasoning"])Args: block for per-parameter descriptions; a default makes an argument optional; a Literal becomes a fixed set the model must choose from (it cannot emit anything else).1from typing import Literal
2
3@needle.tool
4def set_thermostat(temperature: int, mode: Literal["heat", "cool", "auto"] = "auto"):
5 """Set the thermostat.
6
7 Args:
8 temperature: target temperature in Celsius
9 mode: heating strategy to use
10 """
11 return {"temperature": temperature, "mode": mode}
12
13agent = needle.Needle(tools=[set_thermostat])
14agent.run("make it 21 and cool the room")needle.Field, attached inline via Annotated. Ranges, patterns, lengths, and item counts are compiled into the decode grammar, so the model can only ever emit values that satisfy them.1from typing import Annotated
2
3@needle.tool
4def send_money(
5 amount: Annotated[float, needle.Field(gt=0, le=10000, description="USD, up to 10,000")],
6 to: Annotated[str, needle.Field(pattern=r"^@[a-z0-9_]+$", description="recipient handle")],
7 memo: Annotated[str, needle.Field(max_length=80)] = "",
8):
9 "Send money to a handle."
10 return {"sent": amount, "to": to}Field supports description, enum, const, ge/le/gt/lt, multiple_of, min_length/max_length, pattern, format, min_items/max_items, and unique_items.extract(). Pass a Pydantic model and you get a typed object back.1from pydantic import BaseModel
2
3class Invoice(BaseModel):
4 vendor: str
5 total: float
6 due_date: str
7
8invoice = needle.extract("Invoice from Acme Corp, $1,200.00, due 2026-09-01", Invoice)
9print(invoice.vendor, invoice.total) # -> Acme Corp 1200.0tools.json for the CLI is the same shape):1tools = [{
2 "name": "set_lights",
3 "description": "Turn a room's lights on or off and set brightness",
4 "parameters": {
5 "type": "object",
6 "properties": {
7 "room": {"type": "string", "description": "which room to control"},
8 "on": {"type": "boolean"},
9 "brightness": {"type": "integer", "minimum": 0, "maximum": 100},
10 },
11 "required": ["room", "on"],
12 },
13}]
14agent = needle.Needle(tools=tools)run()? complete() returns the raw call and you execute it:1import json
2response = agent.complete("dim the living room to 30")
3if response["type"] == "call":
4 result = set_lights(**response["function_calls"][0]["arguments"])
5 response = agent.complete(json.dumps(result)) # feed the result backneedle.Needle(tools=..., tool_index_path="tools.idx"). Every turn returns one JSON object:1{
2 "type": "call",
3 "success": true,
4 "error": null,
5 "error_code": null,
6 "function_calls": [ { "name": "set_lights", "arguments": { "room": "living room", "on": true, "brightness": 30 } } ],
7 "reasoning": "'living room' -> room; 'dim' -> on true, brightness 30",
8 "confidence": 0.94,
9 "prefill_tps": 4300.0,
10 "decode_tps": 850.0,
11 "peak_ram_mb": 28.0
12}[]. That is the whole contract for off-topic input; there is no free-text fallback.[].reasoning is the model's short derivation of each argument from its source span ('ten minutes' -> minutes 10). It is generated unconstrained; only the call itself is grammar-constrained, so the JSON cannot be malformed while the derivation stays legible.complete(). The model continues from it, and later arguments may depend on earlier results: search_for_contact first, then send_instant_message with the returned contact_id. A final step may answer in plain text from the results: "type": "respond" with empty function_calls.reset() rewinds the conversation and keeps the tools loaded.date: 2026-07-21 Tue 14:30; locale: en-US; device: phone; battery: 62%date, locale, device, battery, network, location, user, and assistant. The model resolves relative language against them: "tomorrow at 7" becomes an absolute time only when a date: fact licenses it, otherwise the human phrase passes through verbatim. assistant: declares the identity the model binds to. Pass the turn with --system system.txt on the CLI or needle.Needle(tools=tools, system="date: ...") in Python. Needle trains with and without the turn, so omitting it is safe; instructions placed there do not steer the model.| your device | folder | command-line | library |
|---|---|---|---|
| Mac (Apple Silicon) | macos-arm64 | needle | libneedle.a |
| Linux x86-64 (PC, server, AMD) | linux-x86_64 | needle | libneedle.a |
| Linux ARM64 (Raspberry Pi, server) | linux-arm64 | needle | libneedle.a |
| Linux ARMv7 (32-bit) | linux-armv7 | needle | libneedle.a |
| Linux RISC-V | linux-riscv64 | needle | libneedle.a |
| Linux MIPS32el (Ingenic cameras, routers) | linux-mipsel | needle | libneedle.a |
| Windows x64 | windows-x86_64 | needle.exe | libneedle.a |
| Windows ARM | windows-arm64 | needle.exe | libneedle.a |
| Android | android-arm64 / android-armv7 / android-riscv64 | needle | libneedle.a |
| iOS / watchOS / tvOS | ios-arm64 / watchos-arm64 / tvos-arm64 | - | libneedle.a |
| Browser / Node (WebAssembly) | wasm | - | needle.js + needle.wasm |
1# answer one query and exit
2./needle --tools tools.json --prompt "dim the living room to 30"
3
4# or an HTTP server on localhost:8080 (POST /complete {"input": "..."})
5./needle --tools tools.json --serve
6
7# with a large tool catalogue, persist tool embeddings across runs
8./needle --tools tools.json --tool-index tools.idx --servetools.json is a JSON array of the functions the assistant may call:1[
2 {
3 "name": "set_lights",
4 "description": "Turn a room's lights on or off and set brightness",
5 "parameters": {
6 "type": "object",
7 "properties": {
8 "room": { "type": "string" },
9 "on": { "type": "boolean" },
10 "brightness": { "type": "integer", "description": "0 to 100" }
11 },
12 "required": ["room", "on"]
13 }
14 },
15 {
16 "name": "play_music",
17 "description": "Play music matching a mood, genre, or artist",
18 "parameters": {
19 "type": "object",
20 "properties": { "query": { "type": "string" } },
21 "required": ["query"]
22 }
23 },
24 {
25 "name": "send_message",
26 "description": "Text a contact",
27 "parameters": {
28 "type": "object",
29 "properties": {
30 "to": { "type": "string" },
31 "body": { "type": "string" }
32 },
33 "required": ["to", "body"]
34 }
35 }
36]--tool-index <path> (CLI) or tool_index_path (Python) persists the embeddings on disk, keyed by a fingerprint over the schemas and the model; a matching fingerprint loads instantly, a changed schema re-embeds only what changed.confidence field is the minimum of two signals: a calibrated post-hoc head that scores the full prompt plus the call the model just produced, and the decoding probability of the call tokens. A call is accepted only when both agree, so the failure mode is escalation, not wrong execution. The contract: pick a threshold for your product, act at or above it, re-ask or route to a bigger model below it. Off-topic requests return the empty call []..cact and ship it like the base model. See the needle repo for training and export.arguments are the extracted fields. With one declared tool the grammar admits exactly one call of that name, the tool_choice equivalent, so schema conformance is guaranteed rather than requested. There is no separate JSON mode.schema.json describes the record to extract:1[
2 {
3 "name": "receipt",
4 "description": "A purchase receipt shared as text",
5 "parameters": {
6 "type": "object",
7 "properties": {
8 "merchant": { "type": "string" },
9 "total": { "type": "number" },
10 "currency": { "type": "string" },
11 "line_items": { "type": "array", "items": { "type": "object" } }
12 },
13 "required": ["merchant", "total"]
14 }
15 }
16]./needle --tools schema.json --prompt "GreenMart receipt: oat milk 3.50, total 7.75 paid by visa"{ "type": "call", "function_calls": [ { "name": "receipt", "arguments": { "merchant": "GreenMart", "total": 7.75 } } ] }1@misc{needle2_2026,
2 title = {Needle 2: A 45M-Parameter Foundation Tool-Calling Model for Tiny Devices},
3 author = {Ndubuaku, Henry and Mosoyan, Karen and Mroz, Jakub and Cylich, Noah and
4 Kumar, Satyajit and Sandhu, Parkirat and Shemet, Roman and Lee, Justin H.},
5 year = {2026},
6 organization = {Cactus Compute, Inc.},
7 howpublished = {\url{https://github.com/cactus-compute/needle}}
8}