Computer use with Gemini
Use Gemini 4 Argon with Cua Driver through Antigravity, or from your own agent loop on the Gemini API.
Two ways to use Gemini 4 Argon (gemini-4-argon) with Cua Driver: add Cua Driver
to Antigravity and write no code, or call the Gemini API from your own agent
loop. Both need Cua Driver 0.35.2 or later on a Mac (check with
cua-driver --version) with the permissions from the
Quickstart granted. Windows and Linux use the same MCP
server and SDKs: change "macOS apps" in the system instruction below to your
platform.
In each recording, Gemini works in the Mac apps on the left while a person types a long message into a chat app on the right with a real keyboard. The bar at the bottom counts the keystrokes the chat app received against the ones that were typed. The middle of each clip is sped up.
Whiteboard photo to Keynote. Gemini read a photo of a hand-drawn product plan in Preview and built a three-slide deck in Keynote: a title slide, the three phases (skipping the crossed-out items), and a diagram of the system flow. The run took about 8 minutes and 173 tool calls. All 2,541 of the person's keystrokes reached the chat app.
Dashboard to Notes. Gemini read a dense metrics dashboard in Preview, picked the three largest changes from the previous period, and wrote them into a new note with the old value, the new value, and the change. The run took about a minute. All 503 keystrokes reached the chat app.
Expenses into Ledger, a small native app with no scripting interface. Gemini entered eight expenses through the app's form fields, and the app's total matched the expected $3,271.29. The run took under two minutes. All 722 keystrokes reached the chat app.
With Antigravity, no code#
Antigravity runs agents on Gemini and
supports local MCP servers. Gemini 4 Argon in Antigravity is available to Google
AI Ultra subscribers. These steps use the Antigravity CLI, agy; the desktop
app and IDE read the same MCP configuration.
curl -fsSL https://antigravity.google/cli/install.sh | bashAdd Cua Driver as an MCP server. This writes it to
~/.gemini/config/mcp_config.json.
agy mcp add cua-driver "$(command -v cua-driver)" mcp
agy mcp listNAME TYPE STATUS COMMAND/URL
cua-driver stdio enabled /Users/you/.local/bin/cua-driver mcpTo approve Cua Driver's tools once instead of on every call, add an allow rule
to ~/.gemini/antigravity-cli/settings.json:
{
"permissions": {
"allow": ["mcp(cua-driver/*)"]
}
}Start agy, choose Gemini 4 Argon, and give it a task. Name the tools you want
and say that someone is using the computer:
Use only the cua-driver tools. In Contacts, open Daniel Reyes and add this note
to his card: "Met at the Design Systems Meetup booth." Save the card. Work in
the background; I'm using the computer.To run without the interactive interface, use print mode. Antigravity cannot ask you to approve a tool in print mode, so it denies any tool your allow list does not cover, such as shell commands.
agy -p "Use only the cua-driver tools. List the windows that are open right now."From your own agent loop#
To control the prompt, the tool set, and the loop, call the Gemini Interactions API from your own process and run each tool call through Cua Driver. You need a Gemini API key from Google AI Studio on a paid tier (Gemini 4 Argon is not on the free tier), and Python 3.10+ or Node.js 20+.
The loop has three parts:
- Tool declarations.
list_tools_json()returns each tool with a JSON Schema, which Gemini accepts as a function declaration unchanged. - Tool calls.
call_tool(name, arguments_json)runs one tool and returns a summary, structured details such as window IDs and element tokens, and screenshots. - Results. Send each result back as a
function_resultwith text and image parts. Include the structured details: the window IDs and element tokens the model needs next are there, not in the summary.
CuaDriver.connect(None) attaches to the Cua Driver service you started. That
service holds the macOS permissions, so the terminal that runs the script does
not need them, and it draws the agent's own cursor on screen. This Python
version uses pip install google-genai "cua-driver>=0.35.2" and
GEMINI_API_KEY. The TypeScript SDK has the same calls (listToolsJson,
callTool) with @google/genai and @trycua/cua-driver.
import asyncio, json, os, time
from cua_driver import CuaDriver
from google import genai
MODEL = os.environ.get("GEMINI_MODEL", "gemini-4-argon")
# launch_app and invoke_menu are left out because both can bring an app to the front.
TOOLS = {"list_apps", "list_windows", "get_window_state", "click", "type_text",
"set_value", "press_key", "hotkey", "scroll", "verify_state",
"run_steps", "run_script"}
SYSTEM_INSTRUCTION = """\
You operate macOS apps through Cua Driver tools while the user keeps working on
the same computer. Stay in the background: do not bring windows to the front.
Before acting on a window, call get_window_state(pid, window_id) and use the
element_token values from that snapshot; take a fresh snapshot after any change.
Prefer accessibility actions over pixel coordinates. When the task is done,
reply with a short summary and call no more tools."""
TIMEOUT_S = 20 * 60 # One Gemini call can take several minutes.
async def run(task: str, max_turns: int = 200) -> str:
client = genai.Client()
driver = CuaDriver.connect(None) # the Cua Driver service started earlier
session = f"gemini-{int(time.time())}"
async def call_tool(name: str, args: dict):
return await driver.call_tool(name, json.dumps(args))
try:
await call_tool("start_session", {"session": session})
await call_tool("set_agent_cursor_enabled", {"session": session, "enabled": True})
catalog = json.loads(await driver.list_tools_json())["tools"]
tools = [
{"type": "function", "name": t["name"], "description": t["description"],
"parameters": t["inputSchema"]}
for t in catalog if t["name"] in TOOLS
]
takes_session = {
t["name"] for t in catalog if "session" in t["inputSchema"].get("properties", {})
}
request = dict(
model=MODEL, tools=tools, system_instruction=SYSTEM_INSTRUCTION,
generation_config={"thinking_level": "low", "max_output_tokens": 65536},
timeout=TIMEOUT_S,
)
interaction = await client.aio.interactions.create(input=task, **request)
for _ in range(max_turns):
calls = [s for s in interaction.steps or [] if s.type == "function_call"]
if not calls:
return interaction.output_text or ""
results = []
for call in calls:
args = dict(call.arguments)
if call.name in takes_session:
args["session"] = session
result = await call_tool(call.name, args)
content = [{"type": "text", "text": result.text or "ok"}]
if result.structured_json: # window IDs, element tokens and other details
content.append({"type": "text", "text": result.structured_json})
content += [
{"type": "image", "mime_type": i.mime_type, "data": i.data_base64}
for i in result.images
]
results.append({"type": "function_result", "name": call.name,
"call_id": call.id, "result": content,
"is_error": result.is_error})
interaction = await client.aio.interactions.create(
input=results, previous_interaction_id=interaction.id, **request
)
return f"Stopped after {max_turns} turns."
finally:
await call_tool("end_session", {"session": session})
await driver.shutdown()
print(asyncio.run(run("Add each person in signups.pdf (open in Preview) to Contacts")))Open the apps the task needs before you run it. Keep working in another app while it runs.
Settings that follow Google's Gemini 4 Argon guidance:
- Use
thinking_level, notthinking_budget. Argon acceptslow,medium, andhigh. Most UI steps are routine, solowkeeps the loop responsive. Raise it when a task needs real planning. - Set
max_output_tokensto 65,536. A low limit can stop the model before it finishes thinking. - Allow long HTTP timeouts. Google recommends at least 15 minutes per request. Give the whole task its own wall-clock budget instead of a short per-call limit.
- Leave out sampling parameters. Argon ignores
temperature,top_p, andtop_k. - Pass thought signatures back unchanged. With
previous_interaction_id, the server keeps them. If you keep history yourself (store=False), resend every model step exactly as you received it.
Tips for long tasks:
- With
previous_interaction_id, every snapshot stays in the conversation, and a large window can return tens of thousands of tokens per snapshot. For long tasks, keep history yourself and drop old snapshots and screenshots. - Call
get_window_statewithinclude_screenshot: falsewhen the agent only needs fresh element tokens. - Offer about a dozen tools, not all 50. Add the
browser_*tools when the task is in a web page. - Run unattended agents in a separate macOS user account or a VM, and keep purchases, messages, deletions, and credentials out of unattended tasks.
For Google's built-in computer use tool, see the computer use reference.