๐ค Run AI Agents on Microcontrollers
TinyAgent is a lightweight AI agent framework designed to run on ESP32 and Arduino-compatible microcontrollers. It brings the power of LLM-driven autonomous agents to the embedded world โ with minimal memory footprint and maximum flexibility.
Modern AI agents (LangChain, AutoGPT, etc.) require powerful servers. But what if your IoT device could think for itself? TinyAgent bridges the gap:
- ๐ง ReAct Loop โ Observe โ Think โ Act cycle running on your ESP32
- ๐ LLM Integration โ Call OpenAI, Ollama, or any compatible API over WiFi
- ๐ง Tool System โ GPIO, sensors, HTTP requests, MQTT โ all as agent tools
- ๐ฆ Tiny Footprint โ Designed for constrained environments (~20KB RAM usage)
- โก Easy Setup โ Arduino IDE & PlatformIO compatible
- Multiple LLM backends: OpenAI API, Ollama, any OpenAI-compatible endpoint
- Built-in tools: GPIO read/write, analog sensors, HTTP requests, MQTT publish
- Custom tools: Register your own tools with a simple callback API
- Streaming support: Process LLM responses as they arrive
- Configurable: System prompts, max iterations, tool selection โ all runtime-configurable
- Memory efficient: Reuses buffers, streams JSON parsing, minimal allocations
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TinyAgent โ
โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ Observe โโโโโถโ Think โโโโโถโ Act โ โ
โ โ (sensors) โ โ (LLM) โ โ (tools) โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โฒ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ ReAct Loop โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Tool Registry โ
โ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโ โโโโโโโโโโโโ โ
โ โ GPIO โ โ Sensor โ โ HTTP โ โ MQTT โ โ
โ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโ โโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ LLM Client (WiFi) โ
โ OpenAI โ Ollama โ Custom โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
PlatformIO (recommended):
; platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
redbasecap-buiss/TinyAgent
bblanchon/ArduinoJson@^7.0.0Arduino IDE:
- Download this repository as ZIP
- Sketch โ Include Library โ Add .ZIP Library
- Install dependency: ArduinoJson by Benoรฎt Blanchon
#include <WiFi.h>
#include <TinyAgent.h>
TinyAgent agent;
void setup() {
Serial.begin(115200);
WiFi.begin("your-ssid", "your-password");
while (WiFi.status() != WL_CONNECTED) delay(500);
// Configure LLM
agent.getLLMClient().configure("https://api.openai.com/v1/chat/completions",
"your-api-key", "gpt-4o-mini");
// Set agent behavior
agent.setSystemPrompt("You are a helpful IoT assistant. Use tools to interact with hardware.");
agent.setMaxIterations(5);
// Register built-in tools
agent.registerBuiltinTools();
// Run the agent
agent.run("What is the current temperature reading from the analog sensor on pin 34?");
}
void loop() {
// Agent runs in setup(), or call agent.run() here for continuous operation
delay(10000);
}| Tool | Description | Example |
|---|---|---|
gpio_read |
Read digital pin state | {"pin": 13} |
gpio_write |
Write digital pin state | {"pin": 2, "value": 1} |
analog_read |
Read analog value (ADC) | {"pin": 34} |
http_get |
Make HTTP GET request | {"url": "http://api.example.com/data"} |
http_post |
Make HTTP POST request | {"url": "...", "body": "..."} |
mqtt_publish |
Publish MQTT message | {"topic": "home/temp", "payload": "23.5"} |
agent.getToolRegistry().registerTool(
"read_dht",
"Read temperature and humidity from DHT22 sensor",
"{\"type\":\"object\",\"properties\":{}}",
[](const String& params) -> String {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
return "{\"temperature\":" + String(temp) + ",\"humidity\":" + String(hum) + "}";
}
);- basic_agent โ Minimal agent setup with GPIO tools
- sensor_monitor โ Autonomous sensor monitoring and reporting
- home_automation โ MQTT-based home automation agent
- Core ReAct loop
- OpenAI API integration
- Built-in GPIO and sensor tools
- MQTT tool
- Ollama native support
- Conversation memory (SPIFFS/LittleFS persistence)
- Multi-agent communication
- BLE tool
- OTA update tool
- Web dashboard for monitoring
- Function calling (structured tool use)
- ESP-IDF native support (no Arduino)
- ESP32 board (ESP32, ESP32-S2, ESP32-S3, ESP32-C3)
- Arduino framework
- ArduinoJson >= 7.0.0
- WiFi connectivity
- LLM API endpoint (OpenAI, Ollama, or compatible)
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
MIT License โ see LICENSE for details.
Made with โก for the embedded AI community