zclaw docs

chapter 5

Build Your Own Tool

Custom tools let you package recurring intent into reusable actions. They are natural-language macros, not new firmware code.

Mental Model

A user tool stores a short action string. Later, when the model calls that tool, zclaw returns the action text and the model executes it with built-in tools.

1) create_tool(name, description, action)
2) Tool is saved in NVS
3) Model calls tool by name
4) Firmware returns: "Execute this action now: ..."
5) Model performs gpio/memory/cron calls

No dynamic code loading. You are shaping behavior through promptable intent.

Creation Contract

FieldRuleNotes
nameAlphanumeric + underscore onlyNo spaces or punctuation.
descriptionShort and explicitUsed by model selection logic.
actionConcrete imperative textShould map cleanly to built-in tools.
capacityUp to 8 user toolsDelete stale tools to free slots.

Authoring Workflow

  1. Pick one job with clear start/end conditions.
  2. Name it by intent: water_plants, prep_night_mode, check_lab_sensor.
  3. Write action text as ordered steps the model can execute.
  4. Create the tool in chat and immediately invoke it with a test prompt.
  5. Adjust wording if the model takes unexpected paths.

Concrete Examples

You: Create a tool named "water_plants".
Description: Water plant zone A.
Action: Set GPIO 5 high, wait 30000 milliseconds, then set GPIO 5 low.

You: Run water_plants
Agent: (calls tool) -> executes gpio_write + delay + gpio_write
You: Create tool "night_shutdown" to prepare lab for night.
Action: Turn GPIO 7 low, remember u_last_shutdown=completed, and set a once schedule in 600 minutes to run morning_startup.

Memory-Driven Tool Creation

Tool creation gets stronger when zclaw already knows your hardware map from memory.

You: Remember that GPIO 5 controls the office lighting.
Agent: Stored as memory key (for example: u_office_lighting_pin=5)

Later...

You: Build a tool to control the lights.
Agent: Creates a tool using the remembered lighting pin instead of asking you to restate wiring.

Pattern: teach wiring once with memory, then create higher-level tools in plain language.

Validation Checklist

  • Does the action text reference only supported built-in capabilities?
  • Are durations explicit in milliseconds/minutes (avoid vague words like "later")?
  • Does it avoid unsafe GPIO pins per your board policy? (The agent will generally prevent this anyway.)
  • Can the outcome be observed via gpio_read, memory_get, or cron_list?

Versioning and Retirement

Treat tool names like API contracts. If behavior changes meaningfully, create a new name and migrate callers.

# Discover current tools
list_user_tools

# Remove stale tool
delete_user_tool(name="night_shutdown_v1")

Pattern: append a version suffix only when compatibility breaks (_v2, _v3).

Failure Modes To Watch

  • Overly broad actions that invite hallucinated extra steps.
  • Tool names that overlap semantically and confuse model choice.
  • Implicit assumptions about hardware state (pin mode, sensor presence, wiring).
  • Long multi-domain macros that should be split into smaller tools.