Nucleus (Mobile App)

Flutter mobile app - Primary agent execution platform

Overview

The Nucleus is the heart of StemCell - a Flutter mobile app where all AI agent execution happens locally. It calls the Gemini API directly, executes tools on-device, and controls robots via BLE. Uses Google File Search API for cloud-powered RAG.

Platform

Flutter 3.24.5 (Dart 3.5.4)

Lines of Code

~1,400 lines (13 files)

Response Time

200-500ms

Key Services

Agent Runtime

• Orchestrates ReAct loop

• Calls Gemini API directly

• Executes tools locally

• Manages conversation state

File Search Service

• Google File Search API integration

• Cloud-powered RAG

• No local vector storage needed

• Fast knowledge retrieval

Conversation Service

• Local conversation history

• SQLite storage with FTS5

• Background sync to cloud

• Context-aware responses

BLE Service

• BLE GATT protocol

• <50ms latency

• Command/telemetry

• Audio streaming

Directory Structure

packages/nucleus/lib/
├── config/
│   ├── api_config.dart      # API endpoints
│   └── gemini_config.dart   # Gemini API config
├── models/
│   ├── ai_message.dart      # AI message model
│   ├── ble_device.dart      # BLE device model
│   ├── robot_telemetry.dart # Telemetry data
│   └── knowledge_chunk.dart # Knowledge base chunk
├── providers/
│   ├── ai_chat_provider.dart       # AI chat state
│   ├── auth_provider.dart          # Auth state
│   ├── robot_control_provider.dart # Robot control
│   └── robot_provider.dart         # Robot state
├── services/
│   ├── agent_runtime.dart          # ReAct loop
│   ├── ai_service.dart             # Gemini API
│   ├── ble_service.dart            # BLE communication
│   ├── local_knowledge_service.dart # Vector search
│   ├── local_memory_service.dart    # FTS5 search
│   └── tool_executor.dart          # Tool execution
├── screens/
│   ├── home_screen.dart            # Home screen
│   ├── conversation_screen.dart    # Chat interface
│   └── robot_control_screen.dart   # Robot control
└── main.dart                       # App entry point

Development

Run Development Server

cd packages/nucleus
fvm flutter pub get
fvm flutter run

Build APK

fvm flutter build apk --release

Run Tests

fvm flutter test