Android shell for agent-owned UI
🔵 A reusable native core for agents that ship their own web UI. The app stays
thin: the page lives on the server (/ext/<agent>/), while Android provides an
authenticated API bridge, the chat surface, settings and a safe WebView.
This is not a separate channel: the page uses ordinary agent
http_route / static_route, and the native parts reuse
the existing AgentOsApi, ChatViewModel and ChatScreen.
53.1 What the core provides
| Component | File | Purpose |
|---|---|---|
AgentUiConfig |
android/app/src/main/java/com/agentos/app/ui/web/AgentUiConfig.kt |
page/API paths, template ui, per-agent build |
AgentWebScreen |
.../ui/web/AgentWebScreen.kt |
WebView, same-origin, retry, settings, chat slot |
AgentWebBridge |
.../ui/web/AgentWebBridge.kt |
window.AgentOS bridge (allowlisted methods) |
AgentOsApi.agentUi |
.../data/AgentOsApi.kt |
POST <path>/api with x-user-id / x-user-token |
AppRoot |
.../ui/AppRoot.kt |
chooses agent web UI or the native chat |
The core does not know a specific agent: it only needs an AgentUiConfig
(agent, path) and an execute(action, argsJson) lambda.
53.2 Server contract
The agent owns its page and API:
config/agents/<agent>/
├── agent.yaml
└── routes/
├── page.yaml # static_route /ext/<agent>/*rest -> ui/
├── api.yaml # http_route /ext/<agent>/api, auth: user
└── ui/
├── index.html
├── app.js
└── style.css
# routes/page.yaml
kind: static_route
name: notes_ui
path: /ext/notes/*rest
dir: ../ui/
index: index.html
auth: public
cache_ttl_secs: 0
# routes/api.yaml
kind: http_route
name: notes_api
method: "*"
path: /ext/notes/api
script: api.js
auth: user
api.js is a thin proxy: it takes the verified identity from
request.user / request.user_id, binds it to the tool arguments (for example
owner_id) and calls the agent's tool endpoint. The client must never choose
the owner.
53.3 window.AgentOS
The bridge is installed before the page loads:
| Method | Behaviour |
|---|---|
AgentOS.api(action, argsJson) |
synchronously returns the JSON string from <path>/api; networking and auth stay native |
AgentOS.openChat() |
opens the native chat (an explicit action, not a fallback) |
AgentOS.openSettings() |
opens app/server settings |
AgentOS.agentName() |
the agent name from AgentUiConfig |
AgentOS.toast(message) |
short native toast |
In a browser there is no window.AgentOS; the page should fall back to fetch
(the notes example does).
53.4 Enabling
Per-agent APK
The universal build is unchanged: agentName and agentUiPath are empty, so
the app shows the normal agent picker and native chat.
$env:JAVA_HOME = 'C:\Users\User\AppData\Local\Programs\Temurin\jdk-21'
cd android
.\gradlew.bat assembleDebug `
"-PagentName=secretary" `
"-PagentUiPath=/ext/secretary/" `
"-PappName=Notes" `
"-PapplicationId=com.agentos.notes"
APK: android/app/build/outputs/apk/debug/app-debug.apk.
| Property | Default | Effect |
|---|---|---|
agentName |
empty | BuildConfig.AGENT_NAME; agent used by chat |
agentUiPath |
empty | BuildConfig.AGENT_UI_PATH; enables the agent UI |
appName |
Agent OS |
generated app_name resource |
applicationId |
com.agentos.app |
package id, so the APK can be installed alongside |
Universal app
If the server returns an optional ui field in /v1/templates, the app enables
the web UI automatically:
{
"name": "secretary",
"ui": { "path": "/ext/secretary/", "enabled": true }
}
The short form "ui": "/ext/secretary/" also works. enabled: false disables
the web UI for that agent. Without ui (or server support) the native chat is
used.
53.5 Auth and security
- The page may be
auth: public— it contains no data. The API is alwaysauth: user. AgentOsApi.agentUiaddsx-user-idandx-user-token(or obtains a ticket fromPOST /v1/user-ticket), so the token never reaches JavaScript.- The data owner is bound server-side from the verified identity; a client
owner_idis ignored/overwritten. - WebView: JavaScript and DOM storage on; file/content access off; mixed content blocked; navigation limited to the configured server host; external links open in the browser.
- The bridge exposes only the methods above; page JS gets no camera/files/token access.
53.6 Errors and chat
- If the page fails to load, an error screen offers Retry and server settings. There is no automatic fallback to the native chat.
- Chat is explicit: the web UI calls
AgentOS.openChat(); the app opensChatScreenand returns to the web UI. - The chat model is selected with
ChatViewModel.ensureModelSelected(agent).
53.7 Limitations
- For agents with
login.required, the web UI uses an already obtained token. An OIDC gate before the WebView is not wired yet; add it inAppRootbeforeAgentWebScreenif needed. uiin/v1/templatesis an optional contract; per-agent builds work without it.- The page is not bundled into the APK: the server must be reachable. Offline bundling is a separate step.
53.8 Verification
$env:JAVA_HOME = 'C:\Users\User\AppData\Local\Programs\Temurin\jdk-21'
cd android
.\gradlew.bat assembleDebug testDebugUnitTest
AgentUiConfig tests cover path normalization, apiPath, template ui and
enabled: false.
A complete example is the notes agent (routes/page.yaml, routes/api.yaml,
ui/, and the notes tool). The page works both in a browser
(http://127.0.0.1:3000/ext/secretary/) and in the Android shell.