Native iOS & Android
Pure Dart with platform channels for Foundation Models and Gemini Nano. No subprocess, no shell escape, no JNI ceremony.
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.
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.
Pure Dart with platform channels for Foundation Models and Gemini Nano. No subprocess, no shell escape, no JNI ceremony.
ModelRoute.preferOnDevice([...]) picks the first capable on-device provider and falls back to cloud only when needed.
Subagents, skills, snapshots, 21 hooks, an Sh mini-shell, MCP — the surface frontier LLMs are most fluent in.
Serializable RunState, push-resume via APNs/FCM, hooks for OnLowBattery and OnNetworkChange.
Every one is real, documented, tested. Click any to read the deep dive.
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.
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.
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.
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.
21 Hooks Deterministic interception points: PreToolUse, OnSuspend, OnLowBattery, OnNetworkChange…
Consent sheets, analytics, battery-aware re-routing, audit logs — without prompt hacking.
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.
ModelRoute Capability-aware fallback between on-device and cloud providers.
preferOnDevice([...]) escalates to cloud only when needed. No if/else in app code.
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.
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.
exec, no & backgrounding, no evalcat, jq, head, tail, sort, xargswhatsapp, gmail, calendar, browser, phone// 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: ... } 21 deterministic interception points. Consent sheets, analytics, audit logs — without prompt hacking.
Prefer on-device when capable; escalate to cloud when not. No branching in your app code.
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.
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.
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 |
The same eight primitives, composed for real mobile agent problems.
Add the dep, run flutter pub get, paste the snippet,
you're streaming agent output in under a minute.
dependencies:
agentlib: ^1.1.0 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);
} Deep dives on mobile-native agents, on-device routing, CLI-first design, and more.
Wire voice input, vision-based screen understanding, accessibility-driven app automation, and on-device routing together. The pocket-assistant pattern in agentlib.
agentlib speaks Model Context Protocol over both HTTP and WebSocket. MCP tools surface as /bin/mcp.<server>.<tool> CLIs, ready for Sh pipelines. Notifications stream live.
iOS backgrounds apps. Android kills processes under memory pressure. agentlib's Runner state is serialisable, lifecycle hooks fire on every transition, and push notifications can wake the agent.
agentlib has more interception points than any other agent SDK. PreToolUse, PostToolUse, OnSuspend, OnLowBattery, OnNetworkChange — guardrails without prompt hacking.
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).
Open source, MIT, on pub.dev. Install in 60 seconds. Build agents that survive backgrounding, run offline, and pipe like Unix.