Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Each creates a phone, checks one outcome and deletes the phone, also when the ch
| [github-actions/](examples/github-actions) | APK smoke test in a workflow | a repo secret with your key |
| [proof-demo-calculator](https://github.com/mobilebox-dev/proof-demo-calculator/pulls?q=is%3Apr) | a real app (a Fossify Calculator fork) where every PR gets a proof comment: last screen, steps, time, cost | nothing: open its pull requests |
| [packages/python/](packages/python) | `mobilebox` Python client and `langchain-mobilebox` LangChain tools | Python 3.10+ |
| [integrations/](examples/integrations) | OpenAI Agents SDK, LangGraph, CrewAI, browser-use, Mastra, Vercel AI SDK, Claude Agent SDK | the framework and a model key |
| [integrations/](examples/integrations) | OpenAI Agents SDK, LangGraph, CrewAI, browser-use, Mastra, Vercel AI SDK, Claude Agent SDK, OpenHands, Haystack | the framework and a model key |

## Guides

Expand Down
3 changes: 2 additions & 1 deletion examples/integrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ One runnable file per agent framework. Each one creates a Mobilebox phone, gives
| Vercel AI SDK | [vercel-ai-sdk/agent.ts](vercel-ai-sdk/agent.ts) | `npm i ai @ai-sdk/mcp @ai-sdk/openai` | MCP, `createMCPClient` |
| Claude Agent SDK | [claude-agent-sdk/agent.ts](claude-agent-sdk/agent.ts) | `npm i @anthropic-ai/claude-agent-sdk` | MCP, `mcpServers` |
| OpenHands | [openhands/agent.py](openhands/agent.py) | `pip install openhands-sdk openhands-tools` | MCP, `mcp_config`; uploads its builds over REST |
| Haystack | [haystack/agent.py](haystack/agent.py) | `pip install haystack-ai mcp-haystack` | MCP, `MCPToolset` |

Run one:

Expand All @@ -23,6 +24,6 @@ python openai-agents/agent.py # Node 24 runs the .ts files directly: node m

OpenHands runs a different task: from your app's repo it builds the app (`BUILD`, default `./gradlew assembleDebug`; `APK`, its output), runs it on the phone, reads the crash log, fixes the code, checks the fix and pushes. Its model comes from `LLM_MODEL` and `LLM_API_KEY` (LiteLLM ids, `LLM_BASE_URL` for OpenAI-compatible endpoints).

`MODEL` picks another model where the framework takes a model id (LangGraph `provider:model`, CrewAI and Mastra `provider/model`). The OpenAI SDKs also read `OPENAI_BASE_URL`, so any OpenAI-compatible endpoint works.
`MODEL` picks another model where the framework takes a model id (LangGraph `provider:model`, CrewAI and Mastra `provider/model`, Haystack an OpenAI model id). The OpenAI SDKs also read `OPENAI_BASE_URL`, so any OpenAI-compatible endpoint works.

**The pattern.** Your code owns the phone's lifecycle: it creates the phone over REST, passes the id to the agent and deletes the phone in `finally`. The agent only drives it: `observe`, `act`, `screenshot`, `install_app`. One phone per task keeps runs independent and the bill bounded. Guides for each framework: https://mobilebox.dev/integrations
41 changes: 41 additions & 0 deletions examples/integrations/haystack/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Haystack + Mobilebox: a Haystack Agent drives a cloud Android phone over MCP.
# pip install haystack-ai mcp-haystack
# MOBILESANDBOX_API_KEY=... OPENAI_API_KEY=... python agent.py
import json, os, urllib.request

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret
from haystack_integrations.tools.mcp import MCPToolset, StreamableHttpServerInfo

API = "https://mobilebox.dev"
AUTH = {"Authorization": f"Bearer {os.environ['MOBILESANDBOX_API_KEY']}"}


def phones(method, path=""): # your code owns the phone: create it, and always delete it
req = urllib.request.Request(f"{API}/v1/phones{path}", method=method, headers=AUTH)
with urllib.request.urlopen(req) as res:
return json.loads(res.read() or "null")


phone = phones("POST", "?wait=ready")["id"]
toolset = MCPToolset(
server_info=StreamableHttpServerInfo(url=f"{API}/mcp", token=Secret.from_env_var("MOBILESANDBOX_API_KEY")),
tool_names=["observe", "act", "screenshot", "install_app"], # the agent drives; it can't create or delete phones
invocation_timeout=60,
eager_connect=True,
)
try:
agent = Agent(
chat_generator=OpenAIChatGenerator(model=os.environ.get("MODEL", "gpt-5.4-mini")),
tools=toolset,
system_prompt=f"You operate the Android phone {phone} with the Mobilebox tools. "
"Observe, act, and check each result on the returned screen.",
max_agent_steps=20,
)
result = agent.run(messages=[ChatMessage.from_user("Open Settings > Display and tell me the brightness level.")])
print(result["last_message"].text)
finally:
toolset.close()
phones("DELETE", f"/{phone}")