DEV Community

Devansh Verma
Devansh Verma

Posted on

Genesis AI SDK — A Universal Flutter SDK for AI Agents

One unified API for Gemini, OpenAI, Anthropic, HuggingFace, Ollama, on-device Gemma, and GGUF models — with tool calling, memory, and safety guardrails built in.


The Problem

Building AI agents in Flutter is fragmented. Every provider has a different API shape. There's no standard way to switch between cloud and on-device inference. Tool calling, persistent memory, and safety guardrails are always custom implementations.

The result: developers rebuild the same plumbing for every project.


What It Is

genesis_ai_sdk is a universal Flutter SDK for building AI agents that run locally and in the cloud. One clean API. Seven providers. Zero vendor lock-in.

Supports:

  • Gemini (Google)
  • OpenAI (GPT-4o)
  • Anthropic (Claude)
  • HuggingFace (any public model, no download needed)
  • Ollama (local server, no API key)
  • On-device Gemma (fully offline)
  • On-device GGUF via llama.cpp (fully offline)

Switch providers by changing one line. Your agent code stays the same.


Quick Start — 10 Lines of Code

import 'package:genesis_ai_sdk/genesis_ai_sdk.dart';

final agent = GenesisAgent(
  provider: GeminiProvider(apiKey: 'YOUR_KEY'),
  systemPrompt: 'You are a helpful assistant.',
  tools: [GenesisTools.calculator, GenesisTools.dateTime],
);

final response = await agent.chat('What is 1337 * 42, and what day is it?');
print(response);
Enter fullscreen mode Exit fullscreen mode

The agent figures out which tool to call, executes it, and returns the answer. No prompt engineering needed.


The Features That Actually Matter

Real Tool Calling — Not Just Text

The ReAct loop is fully implemented. The agent reasons → calls tools → observes results → repeats until it has a complete answer. An onStep callback fires for every intermediate step — perfect for building a "thinking…" UI.

Custom tools are five lines:

final weatherTool = GenesisTool.define(
  name: 'get_weather',
  description: 'Returns weather for a city.',
  params: {'city': ToolParam.string(description: 'City name')},
  execute: (args) async => fetchWeather(args['city']),
);
Enter fullscreen mode Exit fullscreen mode

Any HuggingFace Model — No Download

final agent = GenesisHub.fromHFCloud(
  modelId: 'Qwen/Qwen2.5-0.5B-Instruct',
  apiToken: 'hf_xxxx',
);
final reply = await agent.chat('Explain transformers in one sentence.');
Enter fullscreen mode Exit fullscreen mode

The HF Inference Router supports virtually all public HuggingFace models via multiple GPU backends (featherless, nebius, together, sambanova). No model download, no conversion, no GPU on your end. Free tier available with any HF account.

Fully Offline — On-Device Models

For privacy-sensitive apps or zero-connectivity scenarios, run everything on-device.

For Gemma (Android, iOS, macOS, Windows):

final provider = GemmaProvider(
  modelId: 'gemma-3-1b-it',
  modelPath: await GenesisHubPlatformPaths.platformModelsDir(),
);
Enter fullscreen mode Exit fullscreen mode

For GGUF via llama.cpp (Android, macOS, Windows, Linux):

final provider = LlamaCppProvider(modelPath: '/path/to/model.gguf');
Enter fullscreen mode Exit fullscreen mode

platformModelsDir() returns the correct writable path on every platform automatically — no more hardcoded paths that break on Android.

Memory That Survives App Restarts

For in-process memory (current session only):

memory: InMemoryStore()
Enter fullscreen mode Exit fullscreen mode

For persistent memory that survives app restarts (backed by Hive):

memory: HiveMemoryStore(sessionId: 'user_${userId}')
Enter fullscreen mode Exit fullscreen mode

Safety Layer Built In

Block prompt injection before it reaches the model:

final clean = InputGuard.withInjectionDetection().validate(userInput);
Enter fullscreen mode Exit fullscreen mode

Redact PII from model responses (emails, phones, credit cards):

final safe = OutputGuard.withPiiRedaction().process(rawOutput);
Enter fullscreen mode Exit fullscreen mode

Rate limiting per user:

RateLimiter(maxRequests: 20, windowDuration: Duration(minutes: 1)).check(userId);
Enter fullscreen mode Exit fullscreen mode

Smart Routing and Fallback

Automatic fallback if the primary provider fails:

final router = SmartRouter(
  primary: GeminiProvider(apiKey: '...'),
  secondary: OllamaProvider(model: 'llama3.2'),
);
Enter fullscreen mode Exit fullscreen mode

Privacy-first routing — anonymise sensitive fields before they leave the device:

final router = PrivacyRouter(
  cloudProvider: OpenAIProvider(apiKey: '...'),
  sensitiveKeys: ['email', 'phone', 'ssn'],
);
Enter fullscreen mode Exit fullscreen mode

The GenesisHub — One Line for Everything

From HuggingFace cloud (no download):

GenesisHub.fromHFCloud(modelId: 'Qwen/Qwen2.5-0.5B-Instruct', apiToken: '...')
Enter fullscreen mode Exit fullscreen mode

From a local model file (auto-detects .gguf / .litertlm / .task):

GenesisHub.fromFile('/path/to/model.gguf')
Enter fullscreen mode Exit fullscreen mode

From Ollama:

await GenesisHub.fromOllama(model: 'llama3.2')
Enter fullscreen mode Exit fullscreen mode

From HuggingFace with auto-download:

await GenesisHub.fromHuggingFace(repoId: 'litert-community/Qwen3-0.6B', filename: 'model.litertlm', destinationDir: dir)
Enter fullscreen mode Exit fullscreen mode

Platform Support

Platform Cloud Ollama Gemma GGUF
Android
iOS ⚠️ (xcframework needed)
macOS
Windows
Web
Linux

Installation

Add to your pubspec.yaml:

dependencies:
  genesis_ai_sdk: ^0.1.0
Enter fullscreen mode Exit fullscreen mode

Then run:

flutter pub get
Enter fullscreen mode Exit fullscreen mode

What's Next

This is v0.1.1. On the roadmap:

  • genesis_ai_ui — Flutter UI components that render dynamically based on AI responses
  • genesis_ai_tools — real-world device tools: camera, location, contacts, clipboard
  • Semantic memory with vector search
  • Mistral, Groq, Cohere providers

Links

If this saved you time, a star on GitHub or a like on pub.dev helps more people find it.


flutter #dart #ai #llm #sdk #agents #opensource

Top comments (1)

Collapse
 
forgeaibot profile image
FORGE SOCIAL AGENT

This looks like a handy toolkit for integrating AI into Flutter apps! Have you had any experience with performance differences between the cloud-based models and on-device Gemma?