Commit a3de2ca
Replace Playwright with Kernel native API in OpenAI CUA templates (#124)
## Summary
- Replace Playwright (over CDP) with Kernel's native computer control
API in both TypeScript and Python OpenAI CUA templates
- Add `batch_computer_actions` function tool that executes multiple
browser actions in a single API call, reducing latency
- Add local test scripts (`test.local.ts` / `test_local.py`) that create
remote Kernel browsers for testing without deploying a Kernel app
## Details
**New `KernelComputer` class** (TS + Python) wraps the Kernel SDK for
all computer actions:
- `captureScreenshot`, `clickMouse`, `typeText`, `pressKey`, `scroll`,
`moveMouse`, `dragMouse`
- `batch` endpoint for batched actions
- `playwright.execute` for navigation (`goto`, `back`, `forward`,
`getCurrentUrl`)
- CUA key name to X11 keysym translation map (ported from Go reference
implementation)
- Button normalization (CUA model sends numeric button values
`1`/`2`/`3` in batch calls)
**Batch tool**: System instructions guide the model to prefer
`batch_computer_actions` for predictable sequences (e.g., click + type +
enter).
**Removed dependencies**: `playwright-core`, `sharp` (TS), `playwright`
(Python). Bumped `@onkernel/sdk` to `^0.38.0` and `kernel` to
`>=0.38.0`.
## Test plan
- [x] TypeScript `test.local.ts` E2E: created remote Kernel browser, ran
CUA agent (eBay search task), batch tool used successfully, browser
cleaned up
- [x] Python `test_local.py` E2E: same test, batch tool used on first
action (type + enter), agent completed successfully
- [x] TypeScript compiles cleanly (`tsc --noEmit`)
Made with [Cursor](https://cursor.com)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Moderate risk because it replaces the core browser automation layer
(Playwright/CDP) with new Kernel API wrappers and batching semantics,
which could change runtime behavior and failure modes. No auth/data
model changes beyond new optional replay recording and improved OpenAI
request retry handling.
>
> **Overview**
> These templates now use **Kernel’s native computer control API**
(screenshot/click/type/scroll/batch) instead of Playwright-over-CDP, via
new `KernelComputer` wrappers in both Python and TypeScript.
>
> The agent loop is updated to support a new `batch_computer_actions`
function tool (plus `computer_use_extra` for `goto`/`back`/`url`) with
explicit model instructions, post-action screenshot settling, and
structured `on_event` streaming for prompts, reasoning, actions,
screenshots, and errors.
>
> Adds local runners (`run_local.py`, `run_local.ts`) to test against a
remote Kernel browser without deployment, optional browser replay
recording (`replay.py` / `lib/replay.ts`) surfaced as `replay_url`, and
updates dependencies/config/docs (Kernel SDK bump,
Playwright/sharp/Pillow removals, `.env.example` includes
`KERNEL_API_KEY`, `.gitignore` adds caches).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9f0f9b5. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 0bb2afc commit a3de2ca
File tree
38 files changed
+3736
-1447
lines changed- pkg/templates
- python/openai-computer-use
- agent
- computers
- default
- typescript/openai-computer-use
- lib
- playwright
38 files changed
+3736
-1447
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
0 commit comments