chat-miniagent APK Architecture

Thin Android client over mini-agent /message SSE, with local scrollback and narrow REST tabs

Android APK mini-agent backend thin-client boundary User Android phone Compose UI AuthGateScreen / ChatScreen Material 3 ChatViewModel stream state machine ack / typing / delta / end TasksViewModel todo + schedule state refresh after writes ChatRepository message + local history TasksRepository server REST facade MiniAgentApi OkHttp + callbackFlow readTimeout = 0 SseParser incremental frame parser AuthManager TokenHolder + interceptor 401 / 444 invalidate EncryptedPrefs token + password Room Android-only scrollback not /history WebChannel aiohttp routes Bearer token Session Store 24h in-memory tokens /auth /auth/status MessageHandler shared chat pipeline IntentRouter server-side routing no client intents HttpResponder SSE frames ack typing delta end error Todo Store /todo REST Schedule Manager /schedule REST Executor / Tools pi, shell, blog actors type / tap / stop send text todo / schedule tabs Flow<SseEvent> load / add / done / remove persist user + final end POST /message REST calls chunk -> event restore / persist Bearer header HTTPS + SSE validate token _handle_chat(text, chat_id) intent routing execute agent work ack / delta / end data: {json}\n\n todo REST schedule REST Stop cancels collector -> Call.cancel() 401 / 444 -> AuthGate Legend External Frontend Backend Security Database Message bus

Client boundary

  • • APK sends natural language and renders streamed replies
  • • Intent routing, tool execution and agent policy remain behind /message
  • • Room stores only Android scrollback, not server history

Streaming contract

  • • SSE frames are ack, typing, delta, end and error
  • • end carries the full final answer, so Android can replace the accumulated buffer
  • • Stop is coroutine cancellation propagated to OkHttp Call.cancel()

Operational choices

  • • Bearer tokens are restored through EncryptedSharedPreferences
  • • 401 and silent 444 both mean session invalid
  • • Todo and schedule tabs are narrow REST exceptions with no local mirror