Skip to content

Repository files navigation

TinyAgent Logo
๐Ÿค– Run AI Agents on Microcontrollers

License Platform Version Issues


TinyAgent

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.

Why TinyAgent?

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

Features

  • 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

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   TinyAgent                      โ”‚
โ”‚                                                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  Observe   โ”‚โ”€โ”€โ”€โ–ถโ”‚  Think   โ”‚โ”€โ”€โ”€โ–ถโ”‚    Act    โ”‚ โ”‚
โ”‚  โ”‚ (sensors)  โ”‚    โ”‚  (LLM)   โ”‚    โ”‚  (tools)  โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚       โ–ฒ                                  โ”‚       โ”‚
โ”‚       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ”‚                  ReAct Loop                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                 Tool Registry                    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  GPIO  โ”‚ โ”‚ Sensor โ”‚ โ”‚ HTTP  โ”‚ โ”‚   MQTT   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚               LLM Client (WiFi)                  โ”‚
โ”‚         OpenAI  โ”‚  Ollama  โ”‚  Custom             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Start

Installation

PlatformIO (recommended):

; platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
    redbasecap-buiss/TinyAgent
    bblanchon/ArduinoJson@^7.0.0

Arduino IDE:

  1. Download this repository as ZIP
  2. Sketch โ†’ Include Library โ†’ Add .ZIP Library
  3. Install dependency: ArduinoJson by Benoรฎt Blanchon

Minimal Example

#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);
}

Built-in Tools

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"}

Custom Tools

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) + "}";
    }
);

Examples

Roadmap

  • 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)

Requirements

  • ESP32 board (ESP32, ESP32-S2, ESP32-S3, ESP32-C3)
  • Arduino framework
  • ArduinoJson >= 7.0.0
  • WiFi connectivity
  • LLM API endpoint (OpenAI, Ollama, or compatible)

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

License

MIT License โ€” see LICENSE for details.


Made with โšก for the embedded AI community

About

Lightweight AI Agent Framework for ESP32/Arduino - Run autonomous AI agents on microcontrollers

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages