MrMoz33/tokioai-coder-iot
TokioAI-Coder IoT Package
Turn a 30B open-weight model into a fully autonomous IoT/smart-home agent.
This package contains everything needed to deploy TokioAI-Coder as an autonomous IoT controller:
- The complete TokioAI Engine -- inference pipeline that wraps any Ollama model and adds reliable tool calling
- A production-tested IoT system prompt with a full Home Assistant cookbook
- 12 native tools for system administration, file operations, network diagnostics, and robot vision
- Server-side investigation -- the engine autonomously chains 8+ tool calls to answer a single question
What It Does
You say: "is Home Assistant running?"
The engine:
- Checks
systemctl status home-assistant-- not found - Checks
docker ps | grep home-- not found - Checks
ss -tlnp | grep 8123-- port listening - Checks
curl -s http://localhost:8123/api/-- HA API responds - Answers: "Yes, HA is running on port 8123 via Docker"
All 5 steps happen in a single API call. The client sees only the final answer.
You say: "play some blues"
The engine:
- Calls HA API to send
play_mediato the Alexa - Waits 3 seconds
- Queries the media player state to verify the music actually changed
- Reports: "Now playing: Blues Essentials on Jarvis"
Architecture
TokioAI Engine (OpenAI-compatible API)
====================================
User Query ──> Router ──> Ollama Model ──> Verifier ──> Tool Executor ──>
| | | |
Intent System Retry Local
Classifier Prompt + Loop (2x) Execution
(0ms regex) Few-Shot (read-only safe)
| | | |
v v v v
tool_call Guided Validates Feeds result
/ text / Generation JSON + back to model
decision (schema- correct for next step
constrained) tool names
|
v
Investigation Loop
(up to 8 rounds,
90s timeout)
|
v
Final AnswerComponents
1. TokioAI Engine (engine/)
The core inference pipeline (3,774 lines of Python):
2. IoT System Prompt (prompts/iot_system_prompt.md)
A production-tested system prompt that includes:
- Complete Home Assistant API cookbook (media, lights, switches, sensors, vacuum, TTS)
- Alexa voice control via
alexa_mediaintegration - Robot vision via moondream (1.4B vision model)
- Investigation playbooks for multi-step problem solving
- Anti-hallucination rules (never simulate tool execution)
- Verification protocol (always confirm state changes actually happened)
3. Tool Definitions (tools/)
12 native tools in OpenAI function-calling format:
execute_local-- Run shell commandsexecute_raspi/execute_gcp/execute_router-- Remote executionread_file/write_file/edit_file-- File operationssearch_files-- grep across codebasesdiagnose-- System health checksrobot_vision-- Camera capture + AI analysismemory-- Persistent memory across sessionstask-- Task tracking for multi-session projects
Quick Start
Prerequisites
- Python 3.8+
- Ollama with a model (recommended:
qwen3-coder30B MoE) - Home Assistant instance (for IoT features)
Install
# Clone this repo
git clone https://huggingface.co/MrMoz33/tokioai-coder-iot
cd tokioai-coder-iot
# Install dependencies
pip install flask requests
# Pull a model
ollama pull qwen3-coder # 30B MoE (3B active), recommended
# or: ollama pull qwen2.5-coder:7b # lighter alternativeConfigure Home Assistant
Set your HA token:
export HA_TOKEN="your-long-lived-access-token"
export HA_URL="http://localhost:8123" # or your HA URLStart
# Start the engine
python -m engine serve --model qwen3-coder --port 8080
# Use it (any OpenAI-compatible client works)
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "tokioai-engine",
"messages": [{"role": "user", "content": "is home assistant running?"}]
}'With TokioAI CLI
pip install git+https://github.com/TokioAI/tokioai.git
export TOKIOAI_ENGINE_HOST=http://localhost:8080
tokioai # Interactive agent with full tool callingCustomization
Adding Your Own Home Assistant Entities
Edit prompts/iot_system_prompt.md and add your entities to the cookbook section:
LIGHTS: light.living_room, light.bedroom, light.kitchen
SWITCHES: switch.fan, switch.heater
SENSORS: sensor.temperature, sensor.humidity
MEDIA: media_player.living_room_speakerAdding Custom Tools
Edit engine/schemas.py to add new tool definitions:
{
"type": "function",
"function": {
"name": "my_custom_tool",
"description": "What this tool does",
"parameters": {
"type": "object",
"properties": {
"param1": {"type": "string", "description": "First param"}
},
"required": ["param1"]
}
}
}Then add the executor in engine/executor.py.
Adapting for Different Smart Home Platforms
The system prompt is platform-agnostic in concept. To use with:
- Google Home: Replace HA API calls with Google Home API
- Apple HomeKit: Use HomeKit Accessory Protocol
- MQTT Direct: Replace curl commands with
mosquitto_pub/sub
The engine and tool pipeline remain identical -- only the system prompt changes.
Performance
Tested on Raspberry Pi 5 (8GB) + L4 GPU (via SSH tunnel):
Cost Comparison
After initial GPU investment ($0.50-1.50/hr for L4 on GCP, or free on local hardware), all inference is free and private.
Model Compatibility
The engine's guided generation + retry logic compensates for weaker models.
Related Projects
- TokioAI CLI -- Multi-provider AI CLI with native tool calling
- TokioAI Fine-Tuning Guide -- Train your own tool-calling model
- TokioAI Fine-Tuning Paper -- Research paper on LLM fine-tuning for tool use
- TokioNav -- AI-controlled autonomous robot navigation
License
MIT
Credits
Built by Daniel Dieser (daletoniris) and the TokioAI team.
The TokioAI Engine was developed to make small open models competitive with GPT-4 and Claude for autonomous tool calling -- specifically for IoT, cybersecurity, and DevOps tasks. The key insight: you don't need a bigger model, you need a smarter pipeline around it.
