# Bring your own model or agent loop

Run your own phone agent on the Claude API, any OpenAI Responses model or a local model server, with Silan's tools exactly as its MCP server lists them.

Some developers want their own loop: their model, their prompt, their budget, and a phone at the end of it. Silan's `Examples/agent-loops` folder has three small, complete phone agents that do exactly that. Each one starts `silan mcp`, the same MCP server the plugins use, hands the model Silan's tools as MCP lists them, and uses Silan's public skills as the system prompt. Every call goes through the engine's safety rules, so your loop asks before it pays or sends and never sees a password, like any other client.

## A worked example

You run a local model server on your Mac and want it to drive your phone. From a copy of the repository:

```sh
cd Examples/agent-loops
python3 open_model_loop.py "Open the Clock app and start the stopwatch" --model <local model> --device ios:<device id>
```

The loop finds the `silan` command inside Silan.app, starts `silan mcp`, reads the `silan` and `silan-safety` skills into the system prompt and sends the model the 16 tools of the core profile. On the first tool call Silan asks you whether this program may use your devices. You press **Allow**. The model calls `observe`, gets the element list of the Home Screen, calls `launch_app` for Clock, then `tap` on the words **Start**. Your terminal prints each tool call and its result, and the live picture in Silan shows the stopwatch running. Without `--vision` the model works from element lists only, which suits small models best with one short task.

With a Claude API key, `claude_loop.py` does the same on the Claude API and keeps only the newest three screenshots in the conversation to save tokens. With an OpenAI key, `openai_loop.py` runs any Responses API model with function calling and lets the API keep the conversation between turns.

## Steps

1. Install Silan and set up a device ([Install and quickstart](/quickstart/)). Get its id with `/Applications/Silan.app/Contents/Helpers/silan devices`.
2. Get a copy of the repository and open `Examples/agent-loops`.
3. Pick a loop. `claude_loop.py` needs `pip install anthropic` and `ANTHROPIC_API_KEY`. `openai_loop.py` needs `pip install openai`, `OPENAI_API_KEY` and `--model`. `open_model_loop.py` needs nothing beyond Python and a running OpenAI-compatible server such as Ollama, LM Studio, llama.cpp or vLLM.
4. Run it with the task in quotes and `--device`. Without `--device`, the model calls `list_devices` and picks one.
5. Give the model more tools with `--profile testing` (27 tools) or `--profile full` (45 tools on the current release) when the task needs recordings, installs or the built-in agent ([Use Silan from your agent](/agents/)).
6. Press **Allow** when Silan asks about the program, answer ask cards in Silan, and press Control Option Command Period to stop everything.

The offline tests in `Examples/agent-loops/tests` check how the loops find `silan` and read the skills, with no key and no network. The last test drives the real `silan mcp` against a running engine and a real device when you set `SILAN_CLI`, `SILAN_URL`, `SILAN_API_KEY` and `SILAN_TEST_DEVICE`.

For a program that is not Python, the same tools are on the engine's REST API at `http://127.0.0.1:47800/v1` with a key from **Settings › Connections**, and any MCP client can use **The setup text for other apps** from the same page ([Connections](/features/connections/), [API](/features/api/)).

## What is supported today

| What | Status |
|---|---|
| A phone agent on the Claude API from `claude_loop.py` | Supported |
| A phone agent on any OpenAI Responses model from `openai_loop.py` | Supported |
| A phone agent on a local OpenAI-compatible server from `open_model_loop.py` | Supported |
| Silan's safety rules and the Vault for every loop | Supported |
| The loops run against a real phone | Not yet proved. Their proof was on a Mac with no phone attached |
| A published Python library | Coming soon. It lives in the repository at `SDKs/python` and is not published |
| Headless use on a CI machine with no Silan window | Coming soon |

:::note[Proof]
Proved on a Mac with no phone attached by a Silan worker: the three loops start `silan mcp`, read the skills and get Silan's tools as MCP lists them. The date of that run is not recorded in the use-case facts of 4 Nov 2026, which carry this status. A run against a real phone is owed. Source: use-case facts of 4 Nov 2026 and the Examples README.
:::