Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8d7085a
docs(adk): align readme and guides with apple and ai sdk 7
grabbou Oct 24, 2026
2fcc0b1
chore(adk): upgrade adk kotlin to 1.4.0 and ml kit genai-prompt to beta4
grabbou Oct 24, 2026
122ccd7
feat(adk): align provider with apple and support ai sdk 7 features
grabbou Oct 24, 2026
68a2844
feat(expo-example): show gemini nano download progress and image input
grabbou Oct 24, 2026
a2f80ed
docs(adk): document model info, errors, reasoning and structured output
grabbou Oct 24, 2026
f2c1363
fix(adk): pass system messages as the agent instruction
grabbou Oct 25, 2026
84967ad
fix(adk): report streamed tool calls without arguments
grabbou Oct 25, 2026
c4e2141
fix(adk): route tool calls by run and fix tool, usage and seed handling
grabbou Oct 25, 2026
4cd07ec
refactor(adk): hide gemini nano tool_code text in one place
grabbou Oct 25, 2026
7b7292c
refactor(adk): drop duplicate native defaults and unused error code
grabbou Oct 25, 2026
f2050af
refactor(adk): align model, availability and prepare apis with apple
grabbou Oct 25, 2026
4c0ca37
refactor(expo-example): use the adk model option and model.prepare
grabbou Oct 25, 2026
59fdd8f
docs(adk): document the model option, prepare progress and availability
grabbou Oct 25, 2026
cfe0f09
fix(adk): send gemini nano the whole prompt as one text part
grabbou Oct 29, 2026
5df3791
fix(adk): tell gemini nano how to call tools and accept positional ar…
grabbou Oct 29, 2026
2e11fb9
fix(adk): strip the role markers gemini nano repeats
grabbou Oct 29, 2026
d521f5e
feat(adk): support ai sdk tool approval
grabbou Oct 25, 2026
5345b9a
docs(adk): document tool approval
grabbou Oct 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions apps/expo-example/src/components/adapters/adkSetupAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { LanguageModelV4 } from '@ai-sdk/provider'
import type { Tool } from '@ai-sdk/provider-utils'
import { type AdkModelType, createAdkProvider } from '@react-native-ai/adk'
import {
type AdkLanguageModelId,
createAdkProvider,
} from '@react-native-ai/adk'

import { getGoogleApiKey } from '../../config/adk'
import type { Availability, SetupAdapter } from '../../config/providers.common'

type AdkAdapterOptions = {
modelType: AdkModelType
modelName: string
model: AdkLanguageModelId
label: string
accentColor: string
icon: string
Expand All @@ -20,8 +22,7 @@ export const createAdkLanguageSetupAdapter = (
tools: Record<string, Tool>
): SetupAdapter<LanguageModelV4> => {
const provider = createAdkProvider({
modelType: options.modelType,
modelName: options.modelName,
model: options.model,
apiKey: options.apiKey,
instruction:
'You are a helpful assistant in the Callstack React Native AI demo app.',
Expand All @@ -31,35 +32,47 @@ export const createAdkLanguageSetupAdapter = (

return {
model,
modelId: `adk-${options.modelName}`,
modelId: `adk-${options.model}`,
display: {
label: options.label,
accentColor: options.accentColor,
icon: options.icon,
},
builtIn: options.builtIn,
imageInput: true,
isAvailable(): Availability {
if (options.modelType === 'gemini' && !options.apiKey) {
if (options.model !== 'gemini-nano' && !options.apiKey) {
return 'no'
}
return 'yes'
},
async download() {},
async download(onProgress) {
let bytesToDownload: number | undefined
await model.prepare({
onProgress: (progress) => {
bytesToDownload = progress.bytesToDownload ?? bytesToDownload
if (progress.phase === 'completed') {
onProgress(100)
} else if (bytesToDownload && progress.bytesDownloaded) {
onProgress(
Math.round((progress.bytesDownloaded / bytesToDownload) * 100)
)
}
},
})
},
async delete() {},
async unload() {},
async prepare() {
if ('prepare' in model && typeof model.prepare === 'function') {
await model.prepare()
}
await model.prepare()
},
}
}

export const createAdkCloudSetupAdapter = (tools: Record<string, Tool>) =>
createAdkLanguageSetupAdapter(
{
modelType: 'gemini',
modelName: 'gemini-2.5-flash',
model: 'gemini-3.8-flash',
label: 'ADK Gemini Flash',
accentColor: '#4285F4',
icon: 'psychology',
Expand All @@ -72,8 +85,7 @@ export const createAdkCloudSetupAdapter = (tools: Record<string, Tool>) =>
export const createAdkNanoSetupAdapter = (tools: Record<string, Tool>) =>
createAdkLanguageSetupAdapter(
{
modelType: 'genai-nano',
modelName: 'gemini-nano',
model: 'gemini-nano',
label: 'ADK Gemini Nano',
accentColor: '#34A853',
icon: 'memory',
Expand Down
2 changes: 1 addition & 1 deletion apps/expo-example/src/screens/ChatScreen/ModelItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function ModelItem({
: 'Downloaded'
: selectedModelAvailability === 'availableForDownload'
? 'Tap to download'
: adapter.modelId === 'adk-gemini-2.5-flash' &&
: adapter.modelId === 'adk-gemini-3.8-flash' &&
!hasGoogleApiKey()
? 'Set EXPO_PUBLIC_GOOGLE_API_KEY'
: adapter.modelId === 'adk-gemini-nano'
Expand Down
27 changes: 13 additions & 14 deletions apps/expo-example/src/store/providerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { adk } from '@react-native-ai/adk'
import { generateId } from 'ai'
import { atom, useAtomValue, useSetAtom } from 'jotai'
import { atomWithRefresh, loadable } from 'jotai/utils'
import { Platform } from 'react-native'

import { createLlamaLanguageSetupAdapter } from '../components/adapters/llamaModelSetupAdapter'
import { languageAdapters } from '../config/providers'
Expand Down Expand Up @@ -43,21 +42,21 @@ const availabilityAtom = atomWithRefresh(async (get) => {
availability.set(adapter.modelId, adapter.isAvailable())
}

if (Platform.OS === 'android') {
const supported = await adk.isNanoSupported()
if (!supported) {
const nano = await adk.getModelInfo()
switch (nano.availability) {
case 'available':
availability.set('adk-gemini-nano', 'yes')
break
case 'downloadable':
availability.set('adk-gemini-nano', 'availableForDownload')
break
case 'downloading':
availability.set('adk-gemini-nano', 'no')
nanoUnavailableReason = 'not-ready'
break
default:
availability.set('adk-gemini-nano', 'no')
nanoUnavailableReason = 'unsupported'
} else {
const ready = await adk.isAvailable('genai-nano')
availability.set('adk-gemini-nano', ready ? 'yes' : 'no')
if (!ready) {
nanoUnavailableReason = 'not-ready'
}
}
} else {
availability.set('adk-gemini-nano', 'no')
nanoUnavailableReason = 'unsupported'
}

return { availability, nanoUnavailableReason } satisfies AvailabilityState
Expand Down
204 changes: 23 additions & 181 deletions packages/adk/README.md
Original file line number Diff line number Diff line change
@@ -1,206 +1,48 @@
# ADK Provider for Vercel AI SDK

A Vercel AI SDK provider for [Google's Agent Development Kit (ADK)](https://developer.android.com/ai/adk) on Android. Use on-device Gemini Nano or cloud Gemini with tool calling and multi-turn sessions.
A Vercel AI SDK provider for [Google's Agent Development Kit (ADK)](https://developer.android.com/ai/adk), enabling on-device Gemini Nano and cloud Gemini in React Native applications on Android.

**Requirements:**

- Android `minSdkVersion` 26 or greater (required by ML Kit GenAI / Gemini Nano; set in your app, not only in this package)
- React Native New Architecture
- Android only, with `minSdkVersion` 26+ set in your app
- A device that supports Gemini Nano through AICore for on-device inference (see [ML Kit GenAI device support](https://developers.google.com/ml-kit/genai#feature-device))
- A Google AI API key for cloud Gemini
- Vercel AI SDK v7
- If using on-device models: a device capable of running Gemini Nano (Android 14+ with AICore); you can consult the [ML Kit GenAI documentation](https://developers.google.com/ml-kit/genai#feature-device) for more details.

Consuming apps must set `minSdkVersion` to at least 26. ADK pulls in Google GenAI libraries that duplicate `META-INF/INDEX.LIST`; exclude it in your app packaging. For Expo:

```json
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 26,
"packagingOptions": {
"exclude": ["META-INF/INDEX.LIST", "META-INF/DEPENDENCIES"]
}
}
}
]
```

For bare React Native, add to `android/app/build.gradle`:

```gradle
android {
packagingOptions {
excludes += ["META-INF/INDEX.LIST", "META-INF/DEPENDENCIES"]
}
}
```
- React Native New Architecture

Then run `npx expo prebuild --clean` so the native Android project picks up the change.
Your app also has to exclude duplicate `META-INF` files from Android packaging. See [Getting Started](https://react-native-ai.com/docs/adk/getting-started) for the Expo and bare React Native setup.

```ts
import { adk } from '@react-native-ai/adk'
import { generateText } from 'ai'

const { text } = await generateText({
model: adk(),
prompt: 'What time is it in New York?',
})
```

## Features

- Cloud Gemini model via ADK `LlmAgent` and `InMemoryRunner`
- On-device Gemini Nano via ML Kit GenAI (`genai-nano` model type)
- Tool calling bridged to JavaScript executors
- Streaming responses with tool-call stream parts
- Post-generation token usage via ADK `UsageMetadata`
- Multimodal user prompts (text + inline images)
- Structured JSON output via `responseMimeType` (schema constraints not yet supported)
- Vercel AI SDK v7 `LanguageModelV4` provider

## Usage metadata

ADK returns token usage in response events (`promptTokenCount`, `candidatesTokenCount`, `totalTokenCount`). The provider maps this into AI SDK `usage` on both `generateText` and streaming `finish` events.

## Multimodal input

Pass file parts in user messages using the standard AI SDK prompt format:

```ts
import { generateText } from 'ai'

const { text } = await generateText({
model: adk(),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'What is in this image?' },
{
type: 'file',
mediaType: 'image/jpeg',
data: base64Image,
},
],
},
],
})
```

## Structured output

Streaming structured JSON is not supported by ADK yet.

## Cloud Gemini

```ts
import { createAdkProvider } from '@react-native-ai/adk'
import { generateText } from 'ai'

const adk = createAdkProvider({
apiKey: process.env.GOOGLE_API_KEY,
modelType: 'gemini',
modelName: 'gemini-2.5-flash',
instruction: 'You are a helpful assistant.',
})

const { text } = await generateText({
model: adk(),
prompt: 'Summarize on-device AI in one sentence.',
})
```

> Do not embed API keys in production client apps. Prefer a backend proxy or secure runtime configuration.

## On-device Gemini Nano

Gemini Nano has two separate availability checks:

| API | Label | Question |
| ------------------------------- | --------------------- | ------------------------------------------ |
| `adk.isNanoSupported()` | **Device capability** | Can this device ever run Nano? |
| `adk.isAvailable('genai-nano')` | **Runtime readiness** | Can I call `prepareNano()` / generate now? |

If `isNanoSupported()` is `false`, `isAvailable('genai-nano')` is also `false`.

### ML Kit status codes

Both checks use ML Kit `Generation.getClient().checkStatus()`:

| Status | `isNanoSupported()` | `isAvailable('genai-nano')` | Suggested UX |
| -------------- | ------------------- | --------------------------- | ---------------------------------------- |
| `0` | `false` | `false` | Hide or disable — not supported |
| `1` | `true` | `true` | Ready — call `prepareNano()` |
| `3` | `true` | `true` | Ready to download — call `prepareNano()` |
| Other non-zero | `true` | `false` | Show disabled — not ready yet |

See [ML Kit GenAI Prompt API](https://developers.google.com/ml-kit/genai) for details.

### Recommended flow

```ts
import { createAdkProvider } from '@react-native-ai/adk'

const adk = createAdkProvider({
modelType: 'genai-nano',
modelName: 'gemini-nano',
})

const supported = await adk.isNanoSupported()
if (!supported) {
// Device lacks Gemini Nano / AICore support — hide from model picker
return
}

const ready = await adk.isAvailable('genai-nano')
if (!ready) {
// Device supports Nano but ML Kit is not ready yet (e.g. downloading)
// Show disabled — do not mark as "Ready"
return
}

await adk.prepareNano()
const model = adk()
```

Both checks are cheap native calls (no model download). Safe to cache at app startup and re-check after resume.

> **Note:** `model.prepare()`, `generateText()`, and `streamText()` auto-call `prepareNano()` for `genai-nano` models, but only gate on `isNanoSupported()`. For UI gating, always use `isAvailable('genai-nano')` and handle prepare/generation errors in your chat flow.

## Tool calling

```ts
import { createAdkProvider } from '@react-native-ai/adk'
import { generateText, tool } from 'ai'
import { z } from 'zod'

const getCurrentTime = tool({
description: 'Get the current time for a city',
inputSchema: z.object({
city: z.string(),
}),
execute: async ({ city }) => ({
city,
time: new Date().toLocaleTimeString(),
}),
})

const adk = createAdkProvider({
apiKey: process.env.GOOGLE_API_KEY,
availableTools: { getCurrentTime },
})
## Features

const { text } = await generateText({
model: adk(),
tools: { getCurrentTime },
prompt: 'What time is it in Warsaw?',
})
```
- ✅ On-device Gemini Nano through ML Kit GenAI, with model selection
- ✅ Cloud Gemini through ADK `LlmAgent`
- ✅ Availability, download progress and token counting for Gemini Nano
- ✅ Streaming
- ✅ Tool calling, with the agent loop run natively by ADK
- ✅ Structured outputs
- ✅ Reasoning
- ✅ Image prompts
- ✅ Token usage
- ✅ Error codes

During streaming, the provider emits AI SDK `tool-input-*` and `tool-call` stream parts when ADK surfaces function calls from the model.
## Documentation

Pass tools through the AI SDK `tools` option as usual; the provider bridges execution to JavaScript while ADK orchestrates the agent loop natively.
For complete installation instructions and API documentation, visit our [documentation site](https://react-native-ai.com/docs/adk).

## License

MIT

---

Made with ❤️ and [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
7 changes: 4 additions & 3 deletions packages/adk/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2"
implementation "com.google.adk:google-adk-kotlin-core-android:0.2.0"
implementation "com.google.mlkit:genai-prompt:1.0.0-beta2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0"
implementation "com.google.adk:google-adk-kotlin-core:1.4.0"
implementation "com.google.adk:google-adk-kotlin-mlkit-android:1.4.0-beta"
implementation "com.google.mlkit:genai-prompt:1.0.0-beta4"
}

react {
Expand Down
4 changes: 2 additions & 2 deletions packages/adk/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADK_kotlinVersion=2.1.20
ADK_minSdkVersion=26
ADK_targetSdkVersion=34
ADK_compileSdkVersion=34
ADK_targetSdkVersion=36
ADK_compileSdkVersion=36
Loading