v1.1.0 · MIT · pub.dev

The agent SDK that runs on phones.

Open-source. MIT-licensed. Claude-Code-grade primitives — subagents, skills, snapshots, 21 hooks, an Sh mini-shell, MCP — all native iOS & Android, on-device or cloud.

  • iOS 12+
  • Android API 21+
  • macOS
  • Dart 3.10+ · Flutter 3.38+
  • 7 model providers
  • 21 hooks
  • 12 builtin CLIs
  • MIT
why · mobile-native

Every other agent SDK is a Node subprocess away from your users.

The Claude Agent SDK and OpenAI Agents SDK are wonderful — and they need a Python or Node runtime. That runtime doesn't fit inside an iOS app sandbox or an Android JVM. agentlib does. It's pure Dart, no exec, no Node subprocess, native bridges for on-device models — so the same agent code runs on a phone with zero infrastructure.

01

Native iOS & Android

Pure Dart with platform channels for Foundation Models and Gemini Nano. No subprocess, no shell escape, no JNI ceremony.

02

On-device or cloud, same code

ModelRoute.preferOnDevice([...]) picks the first capable on-device provider and falls back to cloud only when needed.

03

Claude-Code-grade primitives

Subagents, skills, snapshots, 21 hooks, an Sh mini-shell, MCP — the surface frontier LLMs are most fluent in.

04

Lifecycle-aware

Serializable RunState, push-resume via APNs/FCM, hooks for OnLowBattery and OnNetworkChange.

primitives

Eight load-bearing primitives.

Every one is real, documented, tested. Click any to read the deep dive.

  • 01

    AgentSpec + Runner

    A composable agent descriptor paired with a streaming event-driven loop.

    Same RunConfig runs on-device or in the cloud. Real-time TextDelta, ToolCalled, Finished events.

    • streaming
    • tools
    • composable
  • 02

    Subagents

    Spawn child agents sync, in parallel, or in the background — each with its own context window.

    Independent compaction so deep work doesn't bloat the parent. Dispatch via Task or task CLI.

    • parallel
    • background
    • isolated context
  • 03

    Skills

    Markdown bundles with progressive disclosure — only name + description in the orchestrator.

    A 30-skill catalog costs ~600 tokens, not 12K. Body loads only when invoked.

    • markdown
    • progressive disclosure
  • 04

    Snapshots

    snapshot() · revert() · fork() — content-addressed, SQLite-backed, auto before highImpact.

    Users can undo. You can fork to a different model mid-run. Safe mobile automation.

    • sqlite
    • content-addressed
    • fork & revert
  • 05

    21 Hooks

    Deterministic interception points: PreToolUse, OnSuspend, OnLowBattery, OnNetworkChange…

    Consent sheets, analytics, battery-aware re-routing, audit logs — without prompt hacking.

    • lifecycle
    • guardrails
    • audit
  • 06

    Vfs + Sh

    Virtual filesystem with /workspace, /scratch, /system, /bin — plus a sandboxed Unix mini-shell.

    Models speak pipes natively. contacts grep 'Mom' | jq -r .number | xargs whatsapp send.

    • sandbox-safe
    • pipes
    • redirects
  • 07

    ModelRoute

    Capability-aware fallback between on-device and cloud providers.

    preferOnDevice([...]) escalates to cloud only when needed. No if/else in app code.

    • on-device
    • cloud fallback
    • capability-aware
  • 08

    MCP

    HTTP and WebSocket transports for the Model Context Protocol.

    Plug in any MCP server. Tools surface as /bin/mcp.<server>.<tool> CLIs in Sh pipelines.

    • http
    • websocket
    • notifications
the idiom

Frontier LLMs already speak Unix.

GPT-4o, Claude, Gemini — all trained on millions of cmd --flag value | jq ... > file examples. agentlib's Sh gives the model exactly that surface inside a sandbox: pipes, redirects, $VAR, $(cmd). Composing tools becomes one line of model output.

  • safe no real exec, no & backgrounding, no eval
  • familiar cat, jq, head, tail, sort, xargs
  • native first-party CLIs: whatsapp, gmail, calendar, browser, phone
Read: CLI-first agent design →
agent stdout
// model emits one Sh tool call:
> Sh("contacts grep 'Mom' | jq -r .number | xargs whatsapp send --message 'Late'")

// agentlib parses pipes safely:
contacts grep 'Mom'              → /bin/contacts.grep
  | jq -r .number              → /bin/jq
  | xargs whatsapp send       → /bin/whatsapp.send

// PermissionRequestHook surfaces a consent sheet
// auto-snapshot (whatsapp.send is highImpact: true)
// → ToolResult { ok: true, deliveredAt: ... }
the loop

Every tool call passes through hooks.

21 deterministic interception points. Consent sheets, analytics, audit logs — without prompt hacking.

ModelProvider stream tokens PreToolUse hook Tool dispatch VFS · Sh · MCP PostToolUse hook ToolResult → feed back Snapshot if highImpact
Agent loop. Hooks intercept every tool call. Snapshots before destructive ops.
on-device + cloud

Seven providers. Same agent code.

Prefer on-device when capable; escalate to cloud when not. No branching in your app code.

on-device

Private, offline, free

  • FoundationModelsProvider iOS 19+

    Apple Foundation Models

    Native Tool-protocol tool calling. Private, offline, free of API key.

  • GeminiNanoProvider Pixel 8+, Samsung S24+

    Gemini Nano (AICore)

    Tool calling on nano-v3. Auto-detects device support.

  • MediaPipeProvider Android 12+

    Gemma 3 · Phi · Llama 3.2 · Qwen

    Google AI Edge LlmInference — cross-vendor Android.

  • FllamaProvider iOS · Android · macOS

    Any GGUF via llama.cpp

    Family-aware tool-call parsers for Qwen, Llama 3.2, Phi-4, Gemma 3.

cloud

Frontier reasoning, multi-modal

  • AnthropicProvider Anthropic Messages API

    Claude Sonnet · Opus · Haiku

    Streaming tool calls, vision input, extended thinking.

  • OpenAIProvider OpenAI Chat Completions

    GPT-4o · GPT-4.1 · o-series

    Function-calling tools, streaming, vision.

  • GoogleProvider Gemini API

    Gemini 2.5 Pro · Flash

    StreamGenerateContent, native tool calls.

how it stacks up

The only mobile-native option.

agentlib vs the four agent SDKs you're likely considering today.

Capability agentlib Claude SDK OpenAI Agents Mastra LangChain
Native iOS + Android Dart, no subprocess Python/TS, Node subprocess Node/JS only Node/TS backend via wrappers
On-device model providers Foundation Models · Gemini Nano · llama.cpp · MediaPipe Anthropic cloud only OpenAI cloud cloud only via separate libs
Subagents sync · parallel · background sync only via handoffs agent-as-tool via LCEL
Progressive-disclosure skills name+desc only until invoked same shape
Snapshots (fork / revert) public API, SQLite-backed internal checkpoints suspend/resume
Hooks (interception points) 21 hooks ~10 hooks guardrails only lifecycle
Unix-shell-shaped CLI surface Sh mini-shell · /bin/* CLIs real bash via Node JSON-RPC only JSON-RPC only JSON-RPC only
MCP transports HTTP · WebSocket HTTP/stdio HTTP
Suspend / resume + push-resume serialisable RunState · APNs/FCM suspend/resume
License MIT MIT Apache-2.0 MIT MIT
install

One pubspec line.

Add the dep, run flutter pub get, paste the snippet, you're streaming agent output in under a minute.

Full quickstart →
pubspec.yaml
dependencies:
  agentlib: ^1.1.0
lib/main.dart
import 'package:agentlib/agentlib.dart';

final agent = AgentSpec(
  name: 'helper',
  instructions: 'You are a helpful assistant.',
  model: AnthropicProvider(apiKey: const String.fromEnvironment('ANTHROPIC_API_KEY')),
);

final run = Runner.runStreamed(
  agent.toRunConfig(vfs: Vfs(), threadId: 'main'),
  input: 'Why is agentlib mobile-native?',
);
await for (final e in run.events) {
  if (e is TextDelta) print(e.delta);
}
faq

Frequently asked

agentlib is the mobile-native AI agent SDK for Flutter and Dart. It's an open-source (MIT) alternative to the Claude Agent SDK and OpenAI Agents SDK that runs natively inside iOS and Android app sandboxes — with both on-device models (Apple Foundation Models, Gemini Nano, llama.cpp via Fllama, MediaPipe) and cloud providers (Anthropic, OpenAI, Google).

ship it

The agent SDK your phone has been waiting for.

Open source, MIT, on pub.dev. Install in 60 seconds. Build agents that survive backgrounding, run offline, and pipe like Unix.