sdk-kotlin
Skill8.2k starsChanged 58 days agoApache-2.0View on GitHub
How to build and extend the Kotlin/Android SDK in sdks/kotlin. Read this before changing stream-agents-android-core, or before adding a Kotlin client for a new endpoint.
Adopted by
Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data
Who's talking about GetStream/Agents
- sudosubin/agents.nix“agent-skills.github.getstream.agents: 0.6.404 → 0.6.405”GitHub · Nov 30, 2026
- sudosubin/agents.nix“agent-skills.github.getstream.agents: 0.6.403 → 0.6.404”GitHub · Nov 30, 2026
- sudosubin/agents.nix“agent-skills.github.getstream.agents: 0.6.402 → 0.6.403”GitHub · Nov 29, 2026
- sudosubin/agents.nix“agent-skills.github.getstream.agents: 0.6.399 → 0.6.402”GitHub · Nov 27, 2026
- sudosubin/agents.nix“agent-skills.github.getstream.agents: 0.7.1 → 0.6.399”GitHub · Nov 27, 2026
The biggest 5 of 8 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 8
Talked about on GitHub (8 times).
On GitHub · 8
- Nov 30, 2026agent-skills.github.getstream.agents: 0.6.404 → 0.6.405 — sudosubin/agents.nix0 reactions
- Nov 30, 2026agent-skills.github.getstream.agents: 0.6.403 → 0.6.404 — sudosubin/agents.nix0 reactions
- Nov 29, 2026agent-skills.github.getstream.agents: 0.6.402 → 0.6.403 — sudosubin/agents.nix0 reactions
- Nov 27, 2026agent-skills.github.getstream.agents: 0.6.399 → 0.6.402 — sudosubin/agents.nix0 reactions
- Nov 27, 2026agent-skills.github.getstream.agents: 0.7.1 → 0.6.399 — sudosubin/agents.nix0 reactions
3 more on GitHub
- Nov 25, 2026fix: retain 7 reviewed references that left discovery (Nov 25) — tekvisions/voice-index0 reactions
- Nov 24, 2026agent-skills.github.getstream.agents: 0.7.0 → 0.7.1 — sudosubin/agents.nix0 reactions
- Nov 17, 2026agent-skills.github.getstream.agents: init at 0.7.0 — sudosubin/agents.nix0 reactions
In this repository55 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/python.mdcCursor rule
- pr-reviewSkill
- typesafe-aiSkill
- vgpuSkill
- accelerate-sales-engineerSkill
- add-connectorSkill
- check_pricesSkill
- cliSkill
- commitSkill
- connectorsSkill
- dashboardSkill
- decision_modelSkill
- deploySkill
- docsSkill
- generative-uiSkill
- good_morningSkill
- goSkill
- go-testingSkill
- integrate_new_modelsSkill
- llm-interfaceSkill
- loop_performance_benchSkill
- migrate-to-accelerateSkill
- new_modelsSkill
- paginationSkill
- parallel-agentsSkill
- performance_benchmarkSkill
- phonecheckSkill
- pricingSkill
- prospect-competitor-researchSkill
- provider_auditSkill
- prSkill
- querySkill
- refresh_model_statsSkill
- router-detectionSkill
- router-interfaceSkill
- router-llmSkill
- router-searchSkill
- router-stsSkill
- router-sttSkill
- router-ttsSkill
- scheduled-tasksSkill
- sdk-dartSkill
- sdk-dotnetSkill
- sdk-goSkill
- sdk-jsSkill
- sdk-phpSkill
- sdk-rubySkill
- sdk-rustSkill
- sdkSkill
- sdk-swiftSkill
- securitySkill
- sttSkill
- telnyxSkill
- ttsSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 178
Wait on a condition with a deadline (until { ...
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Kotlin SDK conventions
The per-language half of sdk. It records the decisions the modules in
sdks/kotlin already follow, so a change lands consistently rather than
re-litigating them. It mirrors sdk-swift: the two SDKs are the same
API in two languages, and a feature added to one belongs in the other.
Assume Kotlin 2.4, JVM 17 bytecode, AGP 9, Gradle with the version catalogue in
gradle/libs.versions.toml. Client side only: no folder sync, no dispatch, no config writing.
The module, and what it is called
core io.getstream:stream-agents-android-core io.getstream.agents.android.core Android library: HTTP, socket, state, Stream Chat, Stream VideoOne module, as Swift is one package (StreamAgents). The artifact follows Stream's Android names,
written the way Maven writes names: the group is Stream's io.getstream, the artifact is
kebab-case, and the package is the reverse-DNS lower case Kotlin requires. stream-agents-android-core
sits beside Stream's own stream-video-android-* and stream-chat-android-* in a dependency list
and says which product it is.
coreis acom.android.library. It holds the conversation,session.chat(context),session.channelState(context, scope)andVoiceSession, and depends onstream-chat-android-clientandstream-video-android-core.- It ships no views. Apps compose Stream Chat's AI components
(
stream-chat-android-ai-compose), the way Swift apps composeStreamChatAI. - Stream Chat 7.15.0+ comes from
https://stream-io-repo.com, not Maven Central;settings.gradle.ktslists it forio.getstreamonly. - AGP 9 compiles Kotlin itself: apply
com.android.library, neverorg.jetbrains.kotlin.android. - compileSdk 37 is Stream Video 1.34's floor; minSdk 24 is Stream's.
HTTP and the socket
Ktor's client on the OkHttp engine. OkHttp because it is what Android apps already carry and
what Stream's SDKs use, so a host can hand in its own OkHttpClient (interceptors, pinning, a
proxy) and have it apply to requests and the socket alike. Ktor on top because its WebSocket
session and its request builders are coroutine-native; bare OkHttp is callbacks.
expectSuccess = false: a status is read and mapped, never thrown by Ktor.- Path segments go through
appendPathSegments(..., encodeSlash = true). A session id is data, and a/in it must not become a path. - One read loop per socket. Answering a tool call happens in that loop, never in a collector of
events(), so nobody collecting cannot stall a tool. - No automatic reconnection, on purpose.
respondandtool_resultare not idempotent and the protocol has no cursor to resume from. The socket reportsSocketClosedand the caller decides. Adding reconnection means adding resume semantics to the router first. - Credentials go in handshake headers, never the query string, where they end up in logs.
interruptis a socket command. The RESTinterruptSessionis not client-accessible.
State
AgentSession exposes StateFlows: conversation, isConnected, failure. One immutable
Conversation holds the turns and what the agent is doing, so a screen never sees a transcript
and a state that disagree. It is a value with reduce(event), tested on verbatim router
frames with no network; most new event handling belongs there.
events()is aSharedFlowwith no replay and a bounded buffer that drops the oldest. A collector that falls behind loses events; the socket never waits for it.- The session owns a
CoroutineScope(SupervisorJob())andclose()cancels it. It is not tied to a screen; aViewModelholding it is the usual home. CancellationExceptionis never caught and mapped. A screen going away is not a failure.- A reply's interactive UI (
ai_ui) reaches the session's socket first, asui_deltaandui_completed, whichConversationfolds onto the turn asTurn.ui(TurnUI), merging anopenuipatch onto the turn before's card. While OpenUI streams,TurnUI.contentholds only its finished statements, so a card grows a part at a time, and a turn has noTurn.uiuntil one is finished. A turn that ends with noui_completed(an interrupted reply) settles onrespondedorinterrupted: its UI is complete, with the last statement shown when it closed.LiveUIshows it on the reply while Chat is writing it and its ownai_uiisn't complete, by the rules in thegenerative-uiskill:observeeach conversation (it says whether what shows changed), and read each message's custom data fromoverlay(messages), by message id, intoAIUIDocument.from. A call screen shows no channel; show the newestTurn.uithere through itscustomData, with anAIUIHostof its own. - A written reply's thinking and tool calls reach the socket as
reasoning_delta,tool_started,tool_updated(notverbatim) andtool_ran, whichConversationfolds intoTurn.stepsin order: a round of thinkingr1,r2... opens on a delta after anything else and completes when the turn writes text or UI, calls a tool, answers or is cut off, and is timed from when the turn was asked or went on (a privateresumedAt, counted in equality asuiWrittenis); a call runs untiltool_ran, failed when it carries anerror. A turn isisDoneonrespondedwith nopending_work, orinterrupted. An incognito session has no channel, sochat()throws:AgentSession.turnMessages(TurnMessage.messages) is the conversation in the channel's shape, one reply per question, steps astype to fieldsforAIMessagePart.parts, rounds numbered across the reply, a call inapprovalsasawaiting_approvalfor the usersetUsernamed.android_assistant'sAgentTransportshows one from it.
The generated models
generate.py prunes the spec to the allowlisted operations and the components they reach,
then runs openapitools/openapi-generator-cli in Docker for models only, with
kotlinx.serialization. The request layer is hand-written: twelve calls do not need a generated
client, and a generated one would be public API we did not design.
- Generated code is
internal(nonPublicApi). Every public type is hand-written incoreand mapped withof(schema)/.schema. Never return a generated type. generate.pyfails if an allowlisted operation is notx-client-accessible. Adding an endpoint means adding it toOPERATIONSand rerunning.- Schema defaults are stripped before generating. A default is the router's to apply; in
the model it is the value a field starts as, and a caller's
falseequal to it would be dropped while the config it was overriding kept itstrue. Every field starts null, the JSON isexplicitNulls = false, and null means "omit and let the config decide". - Open-ended objects are
JsonElement/JsonObject, neverMap<String, Any>. - Enums map to ours with an
Unknowncase, or fold to the nearest meaning the way Swift does (Session.StateisLiveorEnded). A value the server adds is never an exception. - Dates are
kotlin.time.Instant. A date that does not parse isUnreadable, not a crash.
Errors
One sealed AgentsException: Http (status, the router's reason, Retry-After), Transport,
SocketClosed (code, reason), Unreadable, Configuration. Keep transport failure, an HTTP
status, a decoded body and a close code distinct; never classify by parsing a message. A 401
with a TokenProvider refreshes once and retries once, single-flighted behind a Mutex.
Http is read by one function, refusal in Requests.kt, for a request and a refused socket
handshake alike: reason is the envelope's message, beside type, code and docUrl as
strings (the router adds values), and requestId is X-Request-Id, what a 500 is quoted by. A
body that is not the envelope (a proxy's page, an empty one, an older {"error": "..."}) keeps
its trimmed text, or the status phrase, as reason with those three null. Ktor drops a refused
upgrade's response, so Backend opens sockets through Handshakes, which reads it in OkHttp's
onFailure.
Stream clients: chat and video
Stream is set up once: the key, and the user and token setUser is given, are the one identity
for the router, Stream Chat and Stream Video. There is no call token and no credentials object.
Backend.shared(kind, open, disconnect)builds one client per kind, key and user however many sessions ask, keyed before any token is asked for, and forgets one that failed to open.give(kind, client)records the app's own, handed over withagents.use(...). Both areinternal.agents.disconnect()closes only what was built. Leaving a call or closing a session disconnects nothing; the next session reuses the client.ChatClientandStreamVideoare one per process, and building another replaces the app's. One the app built without handing it over is adopted if it is connected as the same user and refused withConfigurationotherwise.Chat.ktandVoiceSession.kteach remember the last client they built, so they can tell their own instance from the app's.- A token provider that asks
backend.streamCredentials(refresh = true)again, never one fixed token: a token expires an hour in, and two clients refreshing at once fetch one. - Camera direction and state are set before joining, so no front-facing frame is published. Speakerphone on after joining, since a hands-free agent wants the speaker.
- The camera is sampled for the agent through
call.videoFilter, the call's one filter slot. Whatever filter is there stays underneath and runs first (moderation's blur is aBitmapVideoFilter, so the one over it is too), andCameraFilterputs itself back on top when something replaces it. Never clear the slot or replace a filter you did not set. RECORD_AUDIOandCAMERAare the host's to request. The emulator does not test echo cancellation, Bluetooth or routing; release RTC changes after device testing.
Tests
JUnit 5 through kotlin-test. Never mock; assert on state and outputs, never on a call.
- The state machine and the wire.
ConversationTestandWireTestrun real frames throughreduceand the codecs, in milliseconds. - A real loopback router.
TestRouteris a Ktor CIO server on127.0.0.1:0that records what arrived and answers what the test scripted, sockets included. That is how headers, bodies, error statuses, close codes and tool round trips are tested without a mock. - Sharing and posture.
StreamClientsTestproves a second Stream client is never built: sessions asking at once share one, the app's own is used and left connected,disconnectcloses only what was built.PostureTestdrives every operation the SDK has againstTestRouterand fails if one is notx-client-accessiblein the spec. Add to both when a new operation or a new Stream client appears. - Live.
LiveTestis gated onVISION_AGENTS_URL(@EnabledIfEnvironmentVariable), the Kotlin answer to@pytest.mark.integration.KeyedRouterPostureTestis gated onINTEGRATION_ROUTER_KEYand checks a device token's 403s against a router inapi_keymode.
The tests are plain JVM unit tests run by AGP (:core:testDebugUnitTest), with no emulator.
CI is client-sdks.yml, on any change under
sdks/kotlin or to the spec: :core:testDebugUnitTest and :core:assembleRelease, then
generate.py again, failing if the generated models differ from what is committed.
Wait on a condition with a deadline (until { ... }), never a fixed delay. A collector that
must see an event has to be subscribed before the frame is sent: start it with
CoroutineStart.UNDISPATCHED, or it races the socket.
Docker only; the commands are in the README. Build output stays under build/ and .gradle/,
which sdks/kotlin/.gitignore covers.
Reviewing a change
Reject it if it:
- exposes a generated type, or a Stream type anywhere but
chat(),channelState()andVoiceSession; - sends a schema default the caller did not set;
- answers tools from a collector, starts a second read loop, or replays
respond/tool_result; - treats an unknown frame or enum value as fatal;
- catches
CancellationException, or reports an HTTP status as a transport failure; - hand-edits generated code, or adds a method for an operation that is not client-accessible;
- adds views: they belong to Stream Chat's AI components and the apps;
- builds a second Stream client, replaces the app's process-wide one, or disconnects one the app gave;
- mocks, or asserts that a method was called.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

