Lesson 4: On-Device Local LLM Agent (clawchips: rk_claw_server + nanobot)
This lesson deploys the on-board Agent stack with App Portal in one shot:
app-portal install clawchipsinstalls the three wheels rknn3-toolkit, rk-claw-server,
nanobot into a dedicated venv, and deliversgateway.toml, two systemd services, the
AgentModel models and skills — ready out of the box.Prerequisite: App Portal is installed on the board (see Lesson 1, section 1.2).
Objectives
- Deploy the full Agent stack with
app-portal install clawchips(no manual pip / manual model downloads) - Understand the three components: rknn3-toolkit (NPU inference), rk_claw_server (model serving), nanobot (Agent)
- Read ports and context length from
gateway.toml, and verify the service really runs - Talk to the Agent via both CLI and Web
- Master common failures: venv isolation, port conflicts, model paths, long-context requirements
1. Prepare the Environment
1.1 Hardware and System
| Item | Requirement |
|---|---|
| Board | RK3588 + RK182X (RKNN3 Runtime 1.1.0) |
| Disk | /userdata ≥ 15GB (models + wheels + venv) |
| Network | Access to the cloud drive; first install downloads wheels/models |
1.2 Board Prerequisites
app-portal check # valid: True
app-portal list # output must include clawchips
Also configure a Chinese PyPI mirror (strongly recommended — without it the dependency install can
crawl for ten-plus minutes and then fail; see FAQ Q5):
sudo tee /etc/pip.conf <<'EOF'
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
EOF
1.3 Directories (after install)
| Path | Content |
|---|---|
/clawchips/RKClawServer/gateway.toml |
model server config (ports/context) |
/userdata/models/<AgentModel>/ |
AgentModel files (.rknn/.weight/.embed.bin/.tokenizer.gguf) |
~/.nanobot/config.json |
nanobot config (uid1000 user home, mode 0600) |
/etc/systemd/system/rkclaw-server.service |
model server |
/etc/systemd/system/nanobot-gateway.service |
nanobot gateway |
/userdata/app_portal/venv/clawchips/ |
dedicated Python virtual environment |
2. Task Overview
flowchart TD
U["User"] -- "nanobot CLI / Web :8765" --> NB["nanobot<br/>Agent: tool calls / multi-turn"]
NB -- "OpenAI-compatible API" --> RCS["rk_claw_server<br/>(port configured in gateway.toml)"]
RCS --> AM["AgentModel (rknn)<br/>running on RK182X"]
- Three wheels, three roles:
rknn3_toolkit_lite(runtime),rk_claw_server(wraps the model
in an OpenAI API),nanobot(Agent framework) - venv isolation: the catalog sets
venv: truefor clawchips; all Python dependencies live in
/userdata/app_portal/venv/clawchips/and never pollute the system Python - Service management: App Portal installs both systemd units, so
app-portal start clawchips
just works
3. Steps
Step 1: Install
sudo app-portal install clawchips
App Portal proceeds: download tarballs/wheels → sha256 verify → install apt dependencies
(python3-venv etc.) → create the venv → install the 3 wheels plus their pip dependencies →
deliver gateway.toml, the two service units and nanobot-config.json → extract AgentModel to
/userdata/models with a symlink → install skills.
Many dependencies (pip installs dozens of packages for nanobot); the first run takes a while.
Re-running after an interruption resumes the install.
Step 2: Check Status
sudo app-portal status clawchips
Step 3: Start and Tune Config If Needed
sudo app-portal start clawchips
Inspect ports and context length:
sudo grep -E "^port|max_context|model" /clawchips/RKClawServer/gateway.toml
ss -ltn | grep -E "8765|8081"
Long context is a hard requirement in this lesson: the Agent must read tool outputs and keep
multi-turn history; a too-smallmax_contextcauses frequent truncation/errors.
The officialgateway.tomldefault is usually sufficient; to change it, edit the file then
app-portal restart clawchips.
Step 4: Verify the Model Service
# is the model server listening (port from gateway.toml)?
ss -ltn | grep -E "8081|8000|8080"
# OpenAI-compatible API self-check
curl -s http://127.0.0.1:<port>/v1/models | head -20
Step 5: Talk to the Agent
CLI:
source /userdata/app_portal/venv/clawchips/bin/activate
# use the regular user (uid1000); config lives in ~/.nanobot/config.json
nanobot agent --message "What time is it? Check with a shell command"
Web: open http://<board-IP>:8765/ in a browser
4. Principles and Code Walkthrough
Yes, this lesson is basically “one install command” — but that command drives a
full deployment transaction over a layered on-device Agent stack. Everything in
this section comes from two places inside the SDK:
applications/app_portal/configs/apps/20-clawchips.yaml(App Portal’s install
manifest) andapplications/agent/(manual adaptation docs plus the
rkllm3-server launcher script).
4.1 The Big Picture: a Four-Layer Stack
flowchart TD
U["User (CLI / Web :8765)"] --> NB["nanobot (nanobot-gateway.service)<br/>agent loop: multi-turn + tool calls"]
NB -- "OpenAI-compatible API (/v1/chat/completions)" --> RCS["rk_claw_server (rkclaw-server.service, :8081)<br/>wraps the NPU model as an OpenAI API"]
RCS --> RT["RKClawServer runtime<br/>KV cache: /userdata/RKClawServer/kv_cache"]
RT --> TK["rknn3_toolkit_lite"]
TK --> NPU["RK182X NPU (AgentModel *.rknn)"]
The three wheels and their roles (the three packages in the catalog):
| Wheel | Role | Key deps (registered in catalog) |
|---|---|---|
rknn3_toolkit_lite-1.1.0-cp311 |
Python binding of the NPU runtime | transformers==5.14.1 (tokenizer) |
rk_claw_server-*-cp311 |
model server (FastAPI + uvicorn) | fastapi / uvicorn / httpx / jinja2 / numpy |
nanobot_ai-0.2.2 |
agent framework | openai / mcp / playwright / tiktoken, dozens more |
This explains two things: ① why installation is slow — nanobot alone pulls dozens
of pip dependencies; ② why the catalog setsvenv: truefor clawchips —
everything goes into/userdata/app_portal/venv/clawchips/, leaving the system
Python untouched and getting removed together on uninstall.
4.2 The Four Model Files: *.rknn / *.weight / *.embed.bin / *.tokenizer.gguf
During install, AgentModel-*-RKNN.tgz is extracted into /userdata/models/ with
a symlink created under /userdata. What each file is for can be read straight
from the SDK’s rkllm3-server launcher, applications/agent/rkllm3-server/run.sh:
rkllm3-server -m ${LLM_RKNN} \
--vocab ${GGUF_FILE} \
--embed ${EMBED_FILE} \
--host 0.0.0.0 --port 8080 ...
| File | Purpose |
|---|---|
*.rknn |
main LLM (RKNN format, executed on NPU) |
*.tokenizer.gguf |
tokenizer (GGUF format) |
*.embed.bin |
embedding-table weights |
*.weight |
remaining auxiliary weights |
The model-selection logic in run.sh is worth reading: it picks models by
filename inside the model directory — names containing llm become the main
LLM, vision the vision tower, and names containing kivi win top priority
(KIVI is the KV-cache-quantized variant, friendlier to long contexts in limited
RAM); if no tokenizer/embedding shares the main model’s name, the newest one in
the directory is used. When a vision model is present, image placeholders are set
per model family — qwen3-series vision input is 384×384.
4.3 The Three Config Files, Field by Field
① /clawchips/RKClawServer/gateway.toml — model server config
Port and context length (max_context) live here; after editing, apply with
app-portal restart clawchips. App Portal’s health check pins the server port
down: rk_claw_server listens on 8081 (catalog health_checks requires
http://127.0.0.1:8081/readyz to return 200) — which is exactly why it clashes
with lesson 1’s meeting backend (WS on 8081); the two apps cannot run at the
same time.
② ~/.nanobot/config.json — nanobot config (0600)
The SDK ships a reference copy at applications/agent/nanobot/config.json; key
fields:
"agents": { "defaults": {
"model": "rkllm3", "provider": "auto",
"maxTokens": 16384, "temperature": 0.1,
"maxToolIterations": 40,
"memoryWindow": 100 }},
"providers": { "custom": {
"apiKey": "dummy",
"apiBase": "http://127.0.0.1:8080/v1" }},
"gateway": { "host": "0.0.0.0", "port": 18790 },
"tools": { "exec": { "timeout": 60 } }
maxToolIterations: 40— cap on consecutive tool calls per conversation turn,
a guard against infinite loops;memoryWindow: 100+maxTokens— how much multi-turn memory survives; read
them together with gateway.toml’smax_context— tool outputs are the first
thing truncated when context runs out;providers.custom.apiBase— the OpenAI-compatible endpoint; for a local
server theapiKeyis a dummy;- everything under
channels(telegram/slack/QQ/Feishu/…) defaults to
enabled: false; the board only enables socket (WebUI/CLI). Change this only
when wiring an IM bot.
③ ~/.nanobot/nanobot.env — WebUI password (randomly generated)
The catalog’s deploy hook generates a random 16-byte password into this file on
first install:
sudo cat ~firefly/.nanobot/nanobot.env # NANOBOT_WEBUI_PASSWORD=xxxx
Log into http://<board-ip>:8765/ with this password. If lost, delete the file
and run app-portal install clawchips --force; the hook regenerates it.
4.4 What One install Command Actually Does
Read against 20-clawchips.yaml, app-portal install clawchips performs:
- Download + sha256 verify: 3 wheels, gateway.toml, 2 service units,
nanobot-config.json, the AgentModel tgz, and the skills tgz — each with a
matching.sha256; - apt dependencies: python3 / python3-pip / python3-venv / ca-certificates,
etc.; - create the venv, install wheels in dependency order: rknn3-toolkit →
rk-claw-server → nanobot (the latter twodepends_onthe former); - deliver resources: gateway.toml →
/clawchips/RKClawServer/; service
units →/etc/systemd/system/; config.json →~/.nanobot/(mode 0600);
models →/userdata/models+ symlink; skills →/userdata/skills; - run the deploy hook (a bash snippet):
sedtheUser=line of nanobot-gateway.service to the real login user
(uid1000);install -d -m 0700 ~/.nanobotand generate the random WebUI password
(see 4.3③);mkdir /userdata/RKClawServer/kv_cache(the model server’s KV-cache
directory);systemctl daemon-reload;
- four health checks must all pass before “installed”: rkclaw-server.service
active, nanobot-gateway.service active,127.0.0.1:8081/readyz→ 200, and
127.0.0.1:18790/health→ 200.
The uninstall hook runs the reverse: systemctl disable --now both services →
pip uninstall nanobot-ai rk-claw-server rknn3-toolkit-lite inside the venv →
daemon-reload.
4.5 Skills: the Agent’s Hands
The skills.tgz extracts into /userdata/skills/; the catalog’s
required_paths names three skills:
| Skill | Content |
|---|---|
qwen3-vl/ |
image understanding: Qwen3-VL-2B w8a8 model (qwen3-vl-2b-instruct_w8a8_rk3588.rkllm) + run.sh |
rk-asr/ |
speech recognition: rockasr demo + run.sh |
rk-ocr/ |
OCR: scripts/run.sh |
Each skill is just an executable entry point (run.sh); the nanobot agent loop
routes by user intent — send a picture and ask “what is this”, and it goes to
qwen3-vl, not the main LLM. Note the _rk3588 in the skill model filename:
skill models run on the host RK3588’s own NPU, while the main AgentModel sits on
the RK182X — the main model reasons and decides, skills provide specialist
capabilities, each on the most suitable silicon.
4.6 For Contrast: the Manual Adaptation Route (fastest way to grok the architecture)
The SDK’s applications/agent/nanobot/nanobot.md records the original wiring
without App Portal:
# ① start rkllm3-server directly (single-model OpenAI service on :8080)
cd /userdata/models/Qwen3-4B-Instruct-2507 && ./run.sh
# wait for "server is listening on http://0.0.0.0:8080"
# ② point nanobot's provider at it
# providers.custom.apiBase = http://127.0.0.1:8080/v1
# ③ talk to it
nanobot agent
clawchips is essentially: replace ①’s rkllm3-server with the more capable
rk_claw_server (multi-model management, KV-cache directory, WebUI auth,
skills integration), then let App Portal automate everything ②③ need — config,
services, models, skills. The sibling directory openclaw/ holds a Node.js-based
agent gateway whose openclaw.json likewise wires
baseUrl: http://127.0.0.1:8080/v1 to the local model — “OpenAI-compatible
endpoint + swappable frontend” is the universal convention of this whole
on-device Agent design; once you see that, any agent framework plugs into the
same wiring diagram.
5. Verification
| Item | Criterion |
|---|---|
| Install | app-portal status clawchips shows an installed version |
| venv | /userdata/app_portal/venv/clawchips/ exists; pip list shows rk-claw-server/nanobot |
| Models | /userdata/models/<AgentModel>/ contains *.rknn, *.weight, *.tokenizer.gguf |
| Config files | /clawchips/RKClawServer/gateway.toml, ~/.nanobot/config.json (0600) |
| Services | after app-portal start clawchips both systemd units are active and ports listening |
| Conversation | nanobot agent --message "..." answers; when asked to run a command, the answer matches the real system |
The best test that “the Agent really works”: ask something only command execution can answer
(e.g. “what time is it” / “which files are in this directory”) and compare with reality.
6. FAQ
Q1: nanobot command not found after install?
It lives in the clawchips venv, not on the system PATH. Two options:
# ① Let App Portal manage the lifecycle (recommended)
sudo app-portal status clawchips
# ② Enter the venv manually
sudo -u firefly /userdata/app_portal/venv/clawchips/bin/nanobot agent --message "hello"
Q2: Port conflict (both meeting backend and this use 8081)?
sudo app-portal status meeting clawchips 2>/dev/null || true
ss -ltn | grep -E "8081|8765"
Run only one 8081 app at a time: app-portal stop meeting first, then start clawchips
(or change the port in gateway.toml).
Q3: Models incomplete / model-not-found errors?
ls -la /userdata/models/
ls -la /userdata/ | grep -i agent # symlinks
If files are missing, reinstall: sudo app-portal install clawchips --force
(re-verifies and re-downloads).
Q4: Answers truncated / context too small?
Raise max_context in gateway.toml (match the model’s actual supported length), then restart:
sudo app-portal restart clawchips
Q5: pip slow, timing out, or No matching distribution found for numpy>=1.17 (from versions: none)?
Verified incident (2026-11, Debian 12 board): without a mirror, pip connects to pypi.org at only a
few dozen KB/s; after ~13 minutes the index page fetch fails and pip wrongly concludes the package
has no versions at all (from versions: none). The web UI reports
Task failed: ... transformers==5.14.1. numpy is not actually missing — it is the network.
Fix: configure the Aliyun mirror in /etc/pip.conf as shown in 1.2 (measured 800KB/s+), then click
install again. Already-downloaded resources (~9.5GB) are reused automatically — the log shows
reusing the verified target — so only the pip dependencies are re-fetched and the install
finishes within minutes; watch for the rk_claw_server and nanobot_ai download lines that follow.
Q6: Want a completely fresh start?
sudo app-portal uninstall clawchips
sudo rm -rf /userdata/app_portal/venv/clawchips # clear the venv too if needed
sudo app-portal install clawchips
Lesson Summary
- The on-board Agent stack = rknn3-toolkit + rk_claw_server + nanobot + AgentModel — App Portal
installs it all at once app-portal install clawchipsarranges services, configs, models and the venv — no manual pip /
model extraction- Verification order: status → ports listening → /v1/models → have it run a command and check the
real result - Long context and port conflicts are the two most common pitfalls of this lesson