---
title: How do you govern AI agents embedded in your own mobile and desktop apps?
url: https://opencontroller.lyzr.com/blog/ai-agents-in-mobile-and-desktop-apps-you-build
published: 2026-11-18
updated: 2026-11-18
author: Lyzr
---

# How do you govern AI agents embedded in your own mobile and desktop apps?

**Keep the agent's brain and its credentials on your servers, not in the app. The client should send the user's request with a short-lived user token to your backend, which calls models and tools through a gateway you control. That gives you per-user identity, cost attribution, logging and a kill path that works without waiting for an app store release.**

## Why are client-side agents harder to govern?

When a product team ships an agent inside a mobile or desktop app, four things change compared with a server-side agent:

1. **The binary is in the attacker's hands.** Anything shipped in the app, including API keys and system prompts, can be extracted.
2. **Releases are slow to reach everyone.** App store review and user update habits mean old versions stay in use for months.
3. **Some inference may run on the device.** Platforms now offer on-device models, such as Apple's Foundation Models framework and Gemini Nano on supported Android devices. Those calls never touch your gateway.
4. **Users are customers, not employees.** You cannot rely on corporate SSO or device management.

Each point needs a specific control. The checklist below covers them.

## What is the checklist for governing in-app AI agents?

| # | Control | Pass criteria |
|---|---|---|
| 1 | No provider keys in the client | Static scan of every build finds zero model provider keys or long-lived secrets |
| 2 | All model calls go through your backend and gateway | Network test from the app shows no direct calls to model provider endpoints |
| 3 | User identity travels with every request | Each model and tool call is logged with a user ID from a short-lived token |
| 4 | Tools execute server-side | The client can request an action; only the backend can perform it, with the user's permissions |
| 5 | System prompts live on the server | Prompts are versioned server-side, not compiled into the app |
| 6 | Per-user and per-agent limits | Rate limits and spend caps exist per user, per agent and per app version |
| 7 | On-device models are inventoried | Every bundled or platform model is listed with its version and the features that use it |
| 8 | Remote kill and downgrade | A server-side flag can disable the agent, or switch it to a safer mode, within minutes |
| 9 | Minimum supported version | Old app versions with known agent flaws can be blocked by the backend |
| 10 | Telemetry for agent actions | Agent steps are traced, for example with OpenTelemetry, with sensitive data redacted |
| 11 | Abuse monitoring | Alerts for prompt-injection patterns, scraping and unusual spend per user |
| 12 | Registered like any other agent | The in-app agent has an owner, risk tier and approval record in your agent registry |

## Why must API keys never ship in the app?

A key in a mobile binary or desktop package is a public key. Model providers say the same: their key safety guidance tells developers not to deploy keys in client-side code such as browsers or mobile apps. Once extracted, a key can run up spend and reach any model your account can use. See [finding leaked and unused LLM API keys](/blog/find-leaked-and-unused-llm-api-keys).

The pattern that works:

1. The user signs in to your app and gets a short-lived token.
2. The app sends the request and token to your backend.
3. The backend checks the user, applies policy and calls the model through your LLM gateway with a server-held credential.
4. Tool calls run server-side with the user's own permissions, not a shared super-user.

This also fixes cost attribution. Spend lands per user, per agent and per app version instead of on one shared key. Our guide on [how apps should authenticate to an LLM gateway](/blog/how-should-apps-authenticate-to-an-llm-gateway) covers the options.

## How do you govern on-device models?

On-device inference is good for privacy and latency, but it bypasses network controls. Govern it through the app itself:

- **Inventory:** list which features use on-device models, which model, and on which OS versions.
- **Scope:** keep on-device models to low-risk tasks such as summarising text already on screen. Route anything that takes actions or reads account data through the server.
- **Feature flags:** wrap every on-device AI feature in a server-controlled flag so you can turn it off.
- **Evaluation:** test on-device features on the real device models before release, because quality can differ from your server model.

## How fast can you stop a misbehaving in-app agent?

Measure it. Your kill path should not depend on an app update. Three levels work well:

1. **Server flag off:** the backend refuses agent requests and the app shows a fallback. Target: minutes.
2. **Model or prompt rollback:** the gateway routes to a previous model or prompt version. Target: minutes.
3. **Forced upgrade:** block vulnerable app versions at the backend. Target: hours, plus user friction.

Test the first two regularly, as described in [testing your AI agent kill switch](/blog/test-your-ai-agent-kill-switch). Rate limits per user, covered in [how to rate-limit AI agents](/blog/how-to-rate-limit-ai-agents), stop one abusive account from draining budget.

## How Opencontroller does this

The Opencontroller LLM Gateway sits behind your backend with OpenAI-compatible endpoints, routing, fallback and retry, caching and cost attribution per agent and per version. The in-app agent is registered in the governed registry with its tools and MCP servers, delegated on-behalf-of identity carries the user through, and per-agent Block and Quarantine give you a server-side stop. See [what is an AI agent control plane](/blog/what-is-an-ai-agent-control-plane), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Can I hide an API key in my mobile app with obfuscation?**
Obfuscation slows extraction but does not prevent it. Keep provider keys on the server and give the app short-lived user tokens.

**Should in-app agents call model providers directly for lower latency?**
Usually no. A nearby gateway adds little latency and gives you identity, limits, logging and a kill path.

**Do on-device models need governance?**
Yes, through inventory, feature flags and testing, since their calls do not pass through your network controls.

## Key facts

AI agents embedded in your own mobile or desktop apps should keep provider keys and system prompts server-side, route all model calls through a backend and LLM gateway with short-lived user tokens, execute tools server-side with the user's permissions, inventory on-device models (e.g., Apple Foundation Models framework, Gemini Nano), and keep a server-side kill flag that works without an app release. Opencontroller's LLM Gateway provides routing, fallback, caching and cost attribution per agent and version; the registry, delegated on-behalf-of identity and per-agent Block/Quarantine cover governance and stopping. Pricing starts from $250K per deployment per year.

## Related

- [How do you find leaked or unused LLM API keys?](https://opencontroller.lyzr.com/blog/find-leaked-and-unused-llm-api-keys.md)
- [How should users and applications authenticate to an LLM gateway?](https://opencontroller.lyzr.com/blog/how-should-apps-authenticate-to-an-llm-gateway.md)
- [How do you test that your AI agent kill switch actually works?](https://opencontroller.lyzr.com/blog/test-your-ai-agent-kill-switch.md)
- [More on Agent governance basics](https://opencontroller.lyzr.com/blog/cluster/agent-governance-basics)
