r/reactnative • • 1d ago

Tutorial I couldn't find a way to expose React Native app features to Android AI agents (AppFunctions), so I built one

Android added AppFunctions. It's basically MCP tools, but on the device. Your app declares functions like "create note" or "add expense", Android indexes them, and AI agents on the phone can call them without tapping through your UI.

The problem: it's all Kotlin, Jetpack, KSP and an XML schema. Nothing existed for React Native or Expo.

So I built expo-app-functions, an Expo module that lets you declare AppFunctions from TypeScript:

export const createNote = defineAppFunction({
  id: 'createNote',
  description: "Creates a note in the user's notes app with a title and an optional body.",
  params: {
    title: t.string('Short title of the note'),
    body: t.string('Full text of the note').optional(),
  },
  returns: { id: t.string('ID of the created note') },
});

// appfunctions.handlers.ts
implementAppFunction(createNote, async ({ title, body }) => {
  const note = await db.notes.add(title, body ?? '');
  return { id: note.id };
});

What works today (tested end to end on an Android 17 emulator):

  • A TS schema with fully typed handlers and runtime validation. Codegen produces the Kotlin, KSP builds it, and Android registers the functions.
  • Calls work when the app is open (about 30 ms) and when it's force-stopped. In the force-stopped case it starts React Native headless in the background and runs your JS handler.
  • Typed errors: throw AppFunctionError('INVALID_ARGUMENT', …) in JS and the agent gets a proper Android exception back.

What doesn't work yet:

  • It's Android only. iOS has nothing equivalent wired up (App Intents is the closest thing, and it's out of scope for now).
  • It needs Android 16+, Expo SDK 58, the New Architecture and a dev build. Expo Go won't work.
  • Cold start from a killed app takes about 6 s on an emulator debug build. That's the biggest open risk, because agents may not wait that long.
  • Only flat params for now (string, int, number, boolean, string list). No nested objects or enums yet.
  • I haven't tested a real Gemini request yet. That needs Google's Connected Apps developer preview.

It's v0.1 and experimental, MIT-licensed, and on npm: npx expo install expo-app-function

I'd really like feedback from anyone building AI features into React Native apps. Is the API shape right? What would you want an agent to be able to do in your app?

#ReactNative #Expo #Android #AI #OpenSource

1 Upvotes

1 comment sorted by

1

u/Successful_Web_6585 1d ago

I don't have a use right now but still this looks promising. Left a star on GitHub