Skip to content

Commit 2e78ffc

Browse files
authored
feat(templates): Implement Gemini Computer Use templates for TypeScript and Python (#94)
# feat(templates): Implement Gemini Computer Use templates for TypeScript and Python ## Summary This PR introduces full-fledged Gemini Computer Use templates for both TypeScript and Python. The templates implement Google's [Gemini 2.5 Computer Use](https://ai.google.dev/gemini-api/docs/computer-use) model using Kernel's Computer Controls API for browser automation. ## Changes ### New Templates - **TypeScript**: Complete rewrite of `gemini-computer-use` template with native Kernel integration - **Python**: New `gemini-computer-use` template following the same architecture ### Architecture Both templates follow a modular design based on Google's [computer-use-preview reference](https://github.com/google-gemini/computer-use-preview): | File | Description | |------|-------------| | `index.ts` / `main.py` | Entry point with Kernel app registration and action handler | | `loop.ts` / `loop.py` | Gemini sampling loop - orchestrates model calls and action execution | | `session.ts` / `session.py` | Browser session management with optional replay recording | | `tools/computer.ts` / `tools/computer.py` | Maps Gemini actions to Kernel's Computer Controls API | | `tools/types/` | Type definitions for Gemini function calls | ### Supported Actions | Action | Description | |--------|-------------| | `click_at` | Click at coordinates (x, y) | | `hover_at` | Move mouse to coordinates | | `type_text_at` | Click and type text at coordinates | | `scroll_document` | Scroll page (up/down/left/right) | | `scroll_at` | Scroll at specific coordinates | | `navigate` | Navigate to a URL | | `go_back` / `go_forward` | Browser history navigation | | `key_combination` | Press key combinations (e.g., "ctrl+c") | | `drag_and_drop` | Drag from one point to another | | `wait_5_seconds` | Wait action | ### Key Features - **Native Kernel Integration**: Uses Kernel's Computer Controls API directly instead of third-party browser automation libraries - **Replay Recording**: Optional video replay recording for debugging (paid plans only) - **Context Management**: Intelligently manages screenshot history to stay within context limits - **Coordinate Normalization**: Handles Gemini's normalized coordinates (0-1000) to actual screen dimensions - **Local Development**: Both templates support local execution via `npx tsx index.ts` / direct Python execution ### CLI Updates - Added `TemplateGeminiComputerUse` constant and template metadata in `pkg/create/templates.go` - Templates prioritized in selection list alongside Anthropic and OpenAI computer use templates ## Usage ```bash # Create a new project kernel create my-app --language typescript --template gemini-computer-use # Deploy kernel deploy index.ts --env-file .env # Invoke kernel invoke ts-gemini-cua cua-task --payload '{"query": "Navigate to https://example.com and describe the page"}' # With replay recording kernel invoke ts-gemini-cua cua-task --payload '{"query": "...", "record_replay": true}' ``` ## Requirements - `GOOGLE_API_KEY` - [Google AI Studio](https://aistudio.google.com/apikey) ## Testing Templates have been manually tested with various browser automation tasks. ## Related - Closes KERNEL-870 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds native Gemini Computer Use support across both languages and aligns docs/tests/CLI metadata. > > - **New Python template** `python/gemini-computer-use` with `main.py`, `loop.py`, `session.py`, and `tools/` implementing Kernel Computer Controls and Gemini sampling loop > - **TypeScript template rewrite** `typescript/gemini-computer-use`: replaces Stagehand with native Kernel APIs; adds `loop.ts`, `session.ts`, `tools/`; updates `index.ts`, README, and dependencies > - **CLI templates registry**: marks `GeminiComputerUse` as available for Python and TypeScript; sets concrete invoke commands for both languages > - **QA docs**: adds `py-gemini-cua` to matrix, create/deploy steps, invoke commands; updates totals (18 apps/21 tests) > - **Tests**: removes "gemini-computer-use not available for python" cases and related unavailability checks > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5e859dc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 04b4447 commit 2e78ffc

20 files changed

Lines changed: 2018 additions & 3126 deletions

File tree

.cursor/commands/qa.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Here are all valid language + template combinations:
6363
> **Note:** The `yutori-computer-use` template supports two modes: `computer_use` (default, full VM screenshots) and `playwright` (viewport-only screenshots via CDP). Both modes should be tested.
6464
6565
| python | sample-app | py-sample-app | python-basic | No | - |
66+
| python | gemini-computer-use | py-gemini-cua | python-gemini-cua | Yes | GOOGLE_API_KEY |
6667
| python | captcha-solver | py-captcha-solver | python-captcha-solver | No | - |
6768
| python | browser-use | py-browser-use | python-bu | Yes | OPENAI_API_KEY |
6869
| python | anthropic-computer-use | py-anthropic-cua | python-anthropic-cua | Yes | ANTHROPIC_API_KEY |
@@ -99,6 +100,7 @@ Run each of these (they are non-interactive when all flags are provided):
99100
../bin/kernel create -n py-openai-cua -l python -t openai-computer-use
100101
../bin/kernel create -n py-openagi-cua -l python -t openagi-computer-use
101102
../bin/kernel create -n py-claude-agent-sdk -l python -t claude-agent-sdk
103+
../bin/kernel create -n py-gemini-cua -l python -t gemini-computer-use
102104
../bin/kernel create -n py-yutori-cua -l python -t yutori-computer-use
103105
```
104106

@@ -241,6 +243,15 @@ echo "ANTHROPIC_API_KEY=<value from human>" > .env
241243
cd ..
242244
```
243245

246+
**py-gemini-cua** (needs GOOGLE_API_KEY):
247+
248+
```bash
249+
cd py-gemini-cua
250+
echo "GOOGLE_API_KEY=<value from human>" > .env
251+
../bin/kernel deploy main.py --env-file .env
252+
cd ..
253+
```
254+
244255
**py-yutori-cua** (needs YUTORI_API_KEY):
245256

246257
```bash
@@ -262,7 +273,7 @@ kernel invoke ts-stagehand teamsize-task --payload '{"company": "Kernel"}'
262273
kernel invoke ts-anthropic-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and move the 5 items in the To Do and In Progress items to the Done section of the Kanban board. You are done successfully when the items are moved.", "record_replay": true}'
263274
kernel invoke ts-magnitude mag-url-extract --payload '{"url": "https://en.wikipedia.org/wiki/Special:Random"}'
264275
kernel invoke ts-openai-cua cua-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 5 articles"}'
265-
kernel invoke ts-gemini-cua gemini-cua-task --payload '{"startingUrl": "https://www.magnitasks.com/", "instruction": "Click the Tasks option in the left-side bar, and move the 5 items in the To Do and In Progress items to the Done section of the Kanban board? You are done successfully when the items are moved."}'
276+
kernel invoke ts-gemini-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and move the 5 items in the To Do and In Progress items to the Done section of the Kanban board. You are done successfully when the items are moved.", "record_replay": true}'
266277
kernel invoke ts-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'
267278
kernel invoke ts-yutori-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and drag the 5 items in the To Do and In Progress columns to the Done section of the Kanban board. You are done successfully when the items are dragged to Done. Do not click into the items.", "record_replay": true, "mode": "computer_use"}'
268279
kernel invoke ts-yutori-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and drag the 5 items in the To Do and In Progress columns to the Done section of the Kanban board. You are done successfully when the items are dragged to Done. Do not click into the items.", "record_replay": true, "mode": "playwright"}'
@@ -275,13 +286,14 @@ kernel invoke python-anthropic-cua cua-task --payload '{"query": "Go to http://m
275286
kernel invoke python-openai-cua cua-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 5 articles"}'
276287
kernel invoke python-openagi-cua openagi-default-task -p '{"instruction": "Navigate to https://agiopen.org and click the What is Computer Use? button"}'
277288
kernel invoke py-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'
289+
kernel invoke python-gemini-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and move the 5 items in the To Do and In Progress items to the Done section of the Kanban board. You are done successfully when the items are moved.", "record_replay": true}'
278290
kernel invoke python-yutori-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and drag the 5 items in the To Do and In Progress columns to the Done section of the Kanban board. You are done successfully when the items are dragged to Done. Do not click into the items.", "record_replay": true, "mode": "computer_use"}'
279291
kernel invoke python-yutori-cua cua-task --payload '{"query": "Go to http://magnitasks.com, Click the Tasks option in the left-side bar, and drag the 5 items in the To Do and In Progress columns to the Done section of the Kanban board. You are done successfully when the items are dragged to Done. Do not click into the items.", "record_replay": true, "mode": "playwright"}'
280292
```
281293

282294
## Step 7: Automated Runtime Testing (Optional)
283295

284-
**STOP and ask the human:** "Would you like me to automatically invoke all 19 test cases and report back on their runtime status?"
296+
**STOP and ask the human:** "Would you like me to automatically invoke all 21 test cases and report back on their runtime status?"
285297

286298
If the human agrees, invoke each template use the Kernel CLI and collect results. Present findings in this format:
287299

@@ -310,6 +322,7 @@ If the human agrees, invoke each template use the Kernel CLI and collect results
310322
| py-openai-cua | python-openai-cua | | |
311323
| py-openagi-cua | python-openagi-cua | | |
312324
| py-claude-agent-sdk | py-claude-agent-sdk | | |
325+
| py-gemini-cua | python-gemini-cua | | |
313326
| py-yutori-cua | python-yutori-cua | | mode: computer_use |
314327
| py-yutori-cua | python-yutori-cua | | mode: playwright |
315328

@@ -324,9 +337,9 @@ Notes should include brief error messages for failures or confirmation of succes
324337
- [ ] Built CLI with `make build`
325338
- [ ] Created QA directory
326339
- [ ] Got KERNEL_API_KEY from human
327-
- [ ] Created all 17 template variations
340+
- [ ] Created all 18 template variations
328341
- [ ] Got required API keys from human (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY, OAGI_API_KEY, YUTORI_API_KEY)
329-
- [ ] Deployed all 17 apps
342+
- [ ] Deployed all 18 apps
330343
- [ ] Provided invoke commands to human for manual testing
331344
- [ ] (Optional) Ran automated runtime testing and reviewed results
332345

cmd/create_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,6 @@ func TestCreateCommand_InvalidLanguageTemplateCombinations(t *testing.T) {
439439
template: create.TemplateMagnitude,
440440
errContains: "template not found: python/magnitude",
441441
},
442-
{
443-
name: "gemini-computer-use not available for python",
444-
language: create.LanguagePython,
445-
template: create.TemplateGeminiComputerUse,
446-
errContains: "template not found: python/gemini-computer-use",
447-
},
448442
{
449443
name: "invalid language",
450444
language: "ruby",
@@ -558,7 +552,6 @@ func TestCreateCommand_TemplateNotAvailableForLanguage(t *testing.T) {
558552
create.TemplateBrowserUse: {create.LanguageTypeScript},
559553
create.TemplateStagehand: {create.LanguagePython},
560554
create.TemplateMagnitude: {create.LanguagePython},
561-
create.TemplateGeminiComputerUse: {create.LanguagePython},
562555
}
563556

564557
for template, unavailableLanguages := range unavailableCombinations {

pkg/create/templates.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var Templates = map[string]TemplateInfo{
6363
TemplateGeminiComputerUse: {
6464
Name: "Gemini Computer Use",
6565
Description: "Implements a Gemini computer use agent",
66-
Languages: []string{LanguageTypeScript},
66+
Languages: []string{LanguageTypeScript, LanguagePython},
6767
},
6868
TemplateBrowserUse: {
6969
Name: "Browser Use",
@@ -201,7 +201,7 @@ var Commands = map[string]map[string]DeployConfig{
201201
TemplateGeminiComputerUse: {
202202
EntryPoint: "index.ts",
203203
NeedsEnvFile: true,
204-
InvokeCommand: "kernel invoke ts-gemini-cua gemini-cua-task",
204+
InvokeCommand: `kernel invoke ts-gemini-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`,
205205
},
206206
TemplateClaudeAgentSDK: {
207207
EntryPoint: "index.ts",
@@ -250,6 +250,11 @@ var Commands = map[string]map[string]DeployConfig{
250250
NeedsEnvFile: true,
251251
InvokeCommand: `kernel invoke py-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'`,
252252
},
253+
TemplateGeminiComputerUse: {
254+
EntryPoint: "main.py",
255+
NeedsEnvFile: true,
256+
InvokeCommand: `kernel invoke python-gemini-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`,
257+
},
253258
TemplateYutoriComputerUse: {
254259
EntryPoint: "main.py",
255260
NeedsEnvFile: true,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Kernel Python Sample App - Gemini Computer Use
2+
3+
This is a Kernel application that implements a prompt loop using Google's Gemini Computer Use model with Kernel's Computer Controls API.
4+
5+
## Setup
6+
7+
1. Get your API keys:
8+
- **Kernel**: [dashboard.onkernel.com](https://dashboard.onkernel.com)
9+
- **Google AI**: [aistudio.google.com/api-keys](https://aistudio.google.com/api-keys)
10+
11+
2. Deploy the app:
12+
```bash
13+
kernel login
14+
cp .env.example .env # Add your GOOGLE_API_KEY
15+
kernel deploy main.py --env-file .env
16+
```
17+
18+
## Usage
19+
20+
```bash
21+
kernel invoke python-gemini-cua cua-task --payload '{"query": "Navigate to https://example.com and describe the page"}'
22+
```
23+
24+
## Recording Replays
25+
26+
> **Note:** Replay recording is only available to Kernel users on paid plans.
27+
28+
Add `"record_replay": true` to your payload to capture a video of the browser session:
29+
30+
```bash
31+
kernel invoke python-gemini-cua cua-task --payload '{"query": "Navigate to https://example.com", "record_replay": true}'
32+
```
33+
34+
When enabled, the response will include a `replay_url` field with a link to view the recorded session.
35+
36+
## Gemini Computer Use Actions
37+
38+
The Gemini model can execute the following browser actions:
39+
40+
| Action | Description |
41+
|--------|-------------|
42+
| `open_web_browser` | Returns a screenshot (browser is already running) |
43+
| `click_at` | Click at coordinates (x, y) |
44+
| `hover_at` | Move mouse to coordinates (x, y) |
45+
| `type_text_at` | Click and type text at coordinates |
46+
| `scroll_document` | Scroll the page (up/down/left/right) |
47+
| `scroll_at` | Scroll at specific coordinates |
48+
| `search` | Focus the browser URL bar |
49+
| `navigate` | Navigate to a URL |
50+
| `go_back` | Go back in browser history |
51+
| `go_forward` | Go forward in browser history |
52+
| `key_combination` | Press key combination (e.g., "ctrl+c") |
53+
| `drag_and_drop` | Drag from one point to another |
54+
| `wait_5_seconds` | Wait for 5 seconds |
55+
56+
## Resources
57+
58+
- [Google Gemini Computer Use Documentation](https://ai.google.dev/gemini-api/docs/computer-use)
59+
- [Kernel Computer Controls](https://www.kernel.sh/docs/browsers/computer-controls)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.venv/
2+
__pycache__/
3+
*.pyc
4+
.env
5+
.env.local
6+
uv.lock

0 commit comments

Comments
 (0)