How orailnoor/private-agent works
Purpose and Runtime
PrivateAgent is a Flutter Android application that translates text, voice, or Telegram commands into multi-step automation across installed apps. Its core loop combines an LLM provider with Android Accessibility APIs: inspect current UI, ask the model for the next action, execute it natively, and repeat. Primary Flutter entry points are lib/main.dart and the overlay entry point lib/overlay_main.dart; Android starts through android/app/src/main/kotlin/com/orailnoor/privateagent/MainActivity.kt.
UI, Onboarding, and User Control
Flutter screens expose command interaction, setup, configuration, and history. Onboarding guides required Android accessibility permissions; settings holds AI-provider and Telegram configuration; the home screen is the primary interactive surface. Key paths: lib/screens/home_screen.dart, lib/screens/onboarding_screen.dart, lib/screens/settings_screen.dart. Feature availability is gated centrally in lib/config/feature_flags.dart.
Task Models and Execution Orchestration
The task domain is represented by actions, chat messages, and reusable saved skills. TaskExecutor is the likely orchestration boundary for a requested task, while ActionHandler dispatches individual AI-selected operations and recovery handles failure/retry behavior. Relevant paths: lib/models/agent_action.dart, lib/services/task_executor.dart, lib/services/action_handler.dart, lib/services/recovery_engine.dart.
AI Decision and Feedback Loop
AIService is the external-model boundary, expected to package task context, screen state, and prior action result for DeepSeek/OpenRouter-compatible APIs. Its output becomes AgentAction data, which the execution layer performs; subsequent screen inspection feeds the next iteration. Conversation and persistent skill context are managed separately through lib/services/chat_history_service.dart and lib/services/skill_memory_service.dart. The principal paths are lib/services/ai_service.dart, lib/models/chat_message.dart, and lib/models/saved_skill.dart.
Native Android Automation Boundary
Android Accessibility is the privileged actuator and UI-reader boundary. The declared service and its accessibility metadata are in android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt and android/app/src/main/res/xml/accessibility_service_config.xml. Flutter-facing automation abstractions include lib/services/screen_automation_service.dart and lib/services/system_control_service.dart. This boundary requires user-enabled Accessibility Service permissions and is Android-specific.
Command Inputs, Remote Control, and Device Integrations
Commands can originate locally, through speech recognition, or Telegram polling. Telegram is an external Bot API integration rather than an application backend; it forwards remote task commands and likely progress. Device-facing services cover voice, notifications, contacts, alarms, and app launch. Core paths: lib/services/telegram_service.dart, lib/services/voice_service.dart, lib/services/communication_service.dart, lib/services/notification_service.dart, and lib/services/app_launcher_service.dart.
Overlay and Platform Plugins
A separate Flutter overlay runtime supports persistent on-screen agent UI over other apps, backed by a vendored Android foreground/overlay plugin: lib/overlay_main.dart, local_plugins/flutter_overlay_window/lib/flutter_overlay_window.dart, and local_plugins/flutter_overlay_window/android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java. A second local method-channel plugin bridges custom native functions via local_plugins/agent_native/lib/agent_native_method_channel.dart and local_plugins/agent_native/android/src/main/kotlin/com/example/agent_native/AgentNativePlugin.kt.
Build and Release Infrastructure
The deployable target is Android/Flutter, built with Gradle Kotlin DSL under android/app/build.gradle.kts. Automated Android release packaging is defined in .github/workflows/android-release.yml. Runtime dependencies include Android API 26+, Accessibility Services, LLM HTTP APIs (DeepSeek/OpenRouter), Telegram Bot API polling, and native speech-to-text.
Main entry points: task_executor.dart Task executor · action_handler.dart Action handler · AgentAccessibilityService.kt Accessibility service · main.dart App entry point
Components 22
Flutter app
- App entry point
lib/main.dart - Home command UI · Primary local command surface.
lib/screens/home_screen.dart - Accessibility onboarding · Guides users through required permissions.
lib/screens/onboarding_screen.dart - Provider settings · Configures AI provider and Telegram.
lib/screens/settings_screen.dart - Feature flags · Central availability gates.
lib/config/feature_flags.dart
Agent automation
- Task executor · Runs the inspect-decide-act loop.
lib/services/task_executor.dart - Action handler
lib/services/action_handler.dart - Recovery engine
lib/services/recovery_engine.dart - Agent actions · Model-selected operations.
lib/models/agent_action.dart - AI service · Sends task, UI state, and prior results to configured models.
lib/services/ai_service.dart - Conversation and skills · Stores chat history and reusable skills.
lib/services/chat_history_service.dart - Saved skills
lib/models/saved_skill.dart
Android native
- Screen automation · Reads UI and performs automation requests.
lib/services/screen_automation_service.dart - Accessibility service · Privileged UI reader and actuator.
android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt - Accessibility metadata
android/app/src/main/res/xml/accessibility_service_config.xml - Overlay runtime · Persistent UI over other apps.
lib/overlay_main.dart - Overlay foreground service
local_plugins/flutter_overlay_window/android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java - Android build target · Deployable Android target.
android/app/build.gradle.kts
External integrations
- Telegram commands · Polls remote task commands and reports progress.
lib/services/telegram_service.dart - Voice commands
lib/services/voice_service.dart - Device integrations · Notifications, communication, and app launching.
lib/services/communication_service.dart
Other components
- Android release workflow
.github/workflows/android-release.yml
Connections 23
- App entry point → Home command UI: launches
- App entry point → Accessibility onboarding: routes to
- App entry point → Provider settings: routes to
- Feature flags → Home command UI: gates features
- Home command UI → Task executor: submits commands
- Voice commands → Task executor: supplies commands
- Telegram commands → Task executor: supplies remote commands
- Task executor → AI service: requests next action
- Task executor → Action handler: dispatches action
- AI service → Agent actions: returns
- Agent actions → Action handler: defines operation
- Task executor → Conversation and skills: loads context
- Saved skills → Conversation and skills: stored as
- Action handler → Screen automation: executes UI operation
- Screen automation → Accessibility service: uses platform boundary
- Accessibility metadata → Accessibility service: declares capabilities
- Accessibility service → Task executor: returns screen state
- Action handler → Recovery engine: on failure
- Recovery engine → Task executor: retries or adapts
- Action handler → Device integrations: invokes device actions
- Overlay runtime → Overlay foreground service: runs through
- Android build target → Accessibility service: packages
- Android release workflow → Android build target: builds release