Skip to content

Latest commit

 

History

History

android_assistant

README.md

Android assistant

The Android half of swift_assistant: Juno, the same agent, talked to by an Android app. The agent, its instructions, and the two Go programs that store it and sign the phone's Stream token are all swift_assistant's. Only the app is here. The web app is react_assistant.

settings.gradle.kts   builds the app against sdks/kotlin as it is in this checkout
app/                  the phone half: Compose over stream-agents-android-core and Stream's AI components

Run it

Start the router in proxy mode, as in the Swift demo, so it trusts the customer and user ids the phone sends. Then store the agent and leave its backend running, both from swift_assistant, as its README says:

cd examples/voice_agents/swift_assistant
STREAM_ACCELERATION_URL=http://localhost:8080 \
STREAM_ACCELERATION_CUSTOMER_ID=examples \
go run ./configure

STREAM_API_SECRET=<the router's STREAM_API_SECRET> \
STREAM_ACCELERATION_URL=http://localhost:8080 \
STREAM_ACCELERATION_CUSTOMER_ID=examples \
go run ./backend

The backend listens on :8098. Tell the app the Stream key, in local.properties here, which git ignores:

sdk.dir=/path/to/Android/sdk
assistant.streamApiKey=<the router's STREAM_API_KEY>

The app reaches the router on http://localhost:8080 and the backend on http://localhost:8098, the phone's own localhost, which adb reverse hands on to the Mac's. That works the same on a device and an emulator:

adb reverse tcp:8080 tcp:8080
adb reverse tcp:8098 tcp:8098
ANDROID_HOME=/path/to/Android/sdk ./gradlew :app:installDebug

ANDROID_HOME is for sdks/kotlin, which the app builds through an included build, so a change to the SDK shows up in the app without publishing it; that build does not read this directory's local.properties. Run adb reverse again whenever the phone reconnects.

To reach the Mac over the network instead, add assistant.routerUrl and assistant.backendUrl with its address, for example http://192.168.1.20:8080 and http://192.168.1.20:8098. From Android 17 that is the local network, which the app then asks for when it opens.

The chat runs on the agent's own model, as a call does: which model a session runs on is the backend's to choose, and the router refuses a device that names one. Web search needs one of EXA_API_KEY, TAVILY_API_KEY or PERPLEXITY_API_KEY. Stream Chat is on https://stream-io-repo.com rather than Maven Central, which settings.gradle.kts adds. The sign-in card and AIConversation's contentPadding need 7.17.0 or newer, generated UI replies 7.18.0, and AIConversationState 7.19.0: stream-chat-android-ai-compose, stream-chat-android-ai-a2ui and stream-chat-android-ai-openui all take streamChatAi in gradle/libs.versions.toml.

What the app shows

  • Conversations are the router's, in the drawer the menu button opens: sessions.query() lists this user's, sessions.search finds them by title, and the router titles each one as it goes. They are under Today, Yesterday, This week and then their month, by when they started. Pull the list down to read it again; hold one to delete it. A new chat has no session until its first message is written, and one opened but never sent is deleted again on leaving it. One that ended carries on when it is next asked something.
  • Chat is Stream's AI components (stream-chat-android-ai-compose) over the session's channel. AIConversation lays it out in turns: a question moves to the top and shows at once, and its reply writes itself out below it, with the model's reasoning as it thinks (reassembled from the live updates by LiveReasoning), each tool call as it runs, and the answer streaming in. Older messages load as you scroll up. Under a finished reply you can copy, share and rate it; ratings stay on the phone, as the router takes none yet. The composer floats over the bottom of the conversation, which fades away under it.
  • Incognito chat is the eye at the top right of a new chat. Its session is created with incognito = true, so it has no channel, isn't listed, and Juno learns nothing from it; AgentTransport shows it from the session's turnMessages, reasoning, tool calls and approval cards included. Leaving it, or picking another conversation, ends it for good. The photos sent with a question go to the agent but don't show on the question once it is sent.
  • Interactive replies: the gear at the top right of the drawer, beside New chat, opens Settings, where Reply format chooses how Juno answers: in Markdown, or with interactive UI in A2UI or OpenUI. It is the agent's instructions, kept by swift_assistant's backend (GET/PUT /reply-format), so every app answers the same way, from the next new conversation on. The app reads it on opening and keeps the last choice on the phone. With A2UI or OpenUI, "Plan a weekend in Ohrid" answers with UI in place of the reply's words, which AIConversation draws with stream-chat-android-ai-a2ui's A2UIRenderer or stream-chat-android-ai-openui's OpenUIRenderer. One AIUIHost holds both for the screen's life, whatever the format, so earlier replies keep their UI and its state when the format changes, Markdown included; a Markdown reply simply has no UI. Tapping in the UI or sending its form is the person's next question, the action's label as their words and the action as Responses.create's uiAction, so the agent answers again.
  • The trip's own components: the map, the place cards and the calendar, trip_map, place_card and calendar_check, are the app's own views (components/TripComponents.kt), described once in swift_assistant's app/SwiftAssistant/UIComponents.json, which the build copies into the app's assets, so "Plan a weekend in Ohrid" places them in either format as on iOS. They load what they show on the phone: a place's photo and summary from Wikipedia (PlaceCard.kt), and the person's own calendar for the plan's days (CalendarCheck.kt), which the agent never sees, read through CalendarContract once READ_CALENDAR is granted, asked for when the card first appears. The map (TripMap.kt) is MapLibre's OpenGL ES build (android-sdk-opengl, since the default android-sdk requires Vulkan) with OpenFreeMap's liberty style, or its dark one in dark mode, on OpenStreetMap's data, which needs no API key; its pins drop one after another while the reply streams in. Tapping a place card or a pin asks about the place. Ask "Where should we eat in Ohrid tonight?" for the other kind of card (Booking.kt): restaurant_card per venue, which asks for its menu when tapped, availability_gauge of how full the first one is and seat_selector of its tables. Tapping a free table asks to reserve it. Each reads the brand from OpenUITheme.current.
  • The UI streams in over the socket. The router sends a reply's UI on the session's socket as the model writes it (ui_delta, then ui_completed), apart from the words people read or hear, and writes it on the reply's message in Chat later, on a slower tick. AgentTransport gives each change of the session's conversation to the SDK's LiveUI (observe), which reads each turn's UI (Turn.ui), and draws each reply with the custom data overlay answers for it, until the message's own ai_ui is complete. While OpenUI streams, a card grows a statement at a time.
  • A change to the last card is a patch. Asked to change the card it just wrote, such as the party size, the agent writes only the statements that change, in an ```openui-patch block. The router merges them into that card before it writes the message, and the SDK does the same with what streams in, so the reply shows the whole card, changed.
  • The UI shows on a call too. In voice mode the agent says a sentence or two and writes the same UI, which the router keeps out of what is spoken. Voice mode shows the newest of it under the glow, from the call's session, with a host of its own (callUiHost), in a card that scrolls past 300dp. Tapping it asks the agent as in the chat.
  • Settings › Brand chooses the accent and corners the UI wears: Stream Default, Ember Hospitality or Nordic Mobility (Brand.kt). The chat and the call show it at once, in ProvideOpenUITheme with the brand's OpenUITheme, which OpenUI's parts and the app's components read, and the phone keeps the choice. The agent writes the same UI whichever is chosen.
  • Photos from the composer's button, which opens the system photo picker, go with the question, shrunk to 1280 pixels across and inline as JPEG data URIs (Photos.kt). The question shows them at once; the router uploads them to the conversation's channel and writes them on the person's message, where the chat shows them, and the model sees them with that question's reply. From Android 9 a photo is turned the way the camera held it; before, it goes as stored.
  • Voice mode is the waveform beside the composer. It starts voice on the open conversation, so the agent joins its call with the chat so far, and everything said on the call lands back in the chat. The chat's socket stays open and runs the tools, and a tool that asks first asks on a card over the call; the call is followed by a second session with none. The agent is Stream's voice glow (AIVoiceGlow), moving with its voice in Stream's colors and with yours in red, with a word for what it is doing and captions two lines at a time, as in the Android demo, whose Captions.kt and VoiceMeter.kt these are. The microphone is asked for as voice mode opens. Hang up, the close button or Back take the agent off the call and go back to the chat.
  • The camera button in voice mode shows Juno what the phone is pointing at, through the back lens, with a preview of it: this phone's own video on the call, drawn with Stream Video's renderer. Ask "what's this?" and the agent's vision skill asks for what the camera showed at that moment, which the call's session answers with the last few frames. The camera is asked for the first time it is turned on. Try it on a phone: the emulator's camera is a test scene.
  • Tools on the phone, in DeviceTools.kt: get_local_context (date, time, timezone), get_location (asks first; the platform's LocationManager and Geocoder), list_events (the calendar, through CalendarContract), add_reminder (asks first) and send_email (asks first, showing who it goes to). A tool that asks first asks on its step in the reply. The calendar and the location are each asked for the first time a tool needs them, and a tool the person refused tells the agent so. Android has no Reminders an app can add to, so a reminder is an event in the calendar new events go in, at the time it is due, with an alert then; it takes a due time, which iOS's may leave out. send_email has swift_assistant's backend send it through the router's proxy for the person's Gmail (POST /gmail/send).
  • Sign-ins go back to the app. Every new conversation names io.getstream.visionagents.androidassistant:/connected as its session's return_url, the app's own scheme in the reverse domain form the router asks for. SignIn.kt is the browser half of a connector's sign-in: authenticate(url) opens launch_url#handoff_token=<token> in an Auth Tab (androidx.browser 1.10.0) and returns the …:/connected URL the router sent it back to, with connection_id and status, or null when the person closed it. Where the browser has no Auth Tab, it is a Custom Tab, and the redirect comes back through SignInCallbackActivity, which the app's scheme opens. MainActivity provides it as LocalSignIn.
  • Connect Gmail and Linear in the chat. A call that waits for the person's account shows Stream's sign-in card on its step. Connect hands the card's page to SignIn.authenticate, and the account is connected when the page comes back with status=connected; the call then carries on at the router. Not now is AgentSession.declineLogin, which ends the call there. The router needs connectors on (ROUTER_CONNECTORS_ENABLED=true and a ROUTER_PUBLIC_URL). Linear registers its own OAuth client; Gmail needs a Google OAuth client (GOOGLE_MCP_CLIENT_ID and its secret) in a project enrolled in Google's Workspace Developer Preview, without which a Gmail call has no sign-in to offer. The composer floats over the conversation, which contentPadding keeps clear of it, so the latest message and the scroll-to-latest button are never under it.

The app is the user juno-owner, Alex, as the iOS app is, so both phones list the same conversations. Assistant.kt holds the whole configuration: the router's and the backend's URLs, the customer id, the Stream key, the agent's name and the user.

What is not here yet

  • The brand on A2UI's own parts: an A2UI reply's components from the app wear it, but its other parts keep the Material look, since the A2UI renderer reads Material's theme, not OpenUI's.
  • An animation as the card appears on a call: it shows at once.
  • Think harder, which iOS offers in the composer's options: Stream's Android composer has no options sheet.
  • A seat selector that brings its own reserve_table tool while it is shown, as iOS's does: the Kotlin SDK has AgentSession.addTools and removeTool (#2050), but this sample doesn't use them yet.