Skip to content

Commit da47b71

Browse files
Add sync and async CUA task examples
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 3ba5bcc commit da47b71

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ Ready-to-run examples are available in `examples/`:
260260
- `examples/async_batch_fetch.py`
261261
- `examples/async_browser_use_task.py`
262262
- `examples/async_crawl.py`
263+
- `examples/async_cua_task.py`
263264
- `examples/async_extension_create.py`
264265
- `examples/async_extension_list.py`
265266
- `examples/async_extract.py`
@@ -274,6 +275,7 @@ Ready-to-run examples are available in `examples/`:
274275
- `examples/sync_batch_fetch.py`
275276
- `examples/sync_browser_use_task.py`
276277
- `examples/sync_crawl.py`
278+
- `examples/sync_cua_task.py`
277279
- `examples/sync_extension_create.py`
278280
- `examples/sync_extension_list.py`
279281
- `examples/sync_extract.py`

examples/async_cua_task.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Asynchronous CUA task example.
3+
4+
Run:
5+
export HYPERBROWSER_API_KEY="your_api_key"
6+
python3 examples/async_cua_task.py
7+
"""
8+
9+
import asyncio
10+
11+
from hyperbrowser import AsyncHyperbrowser
12+
from hyperbrowser.models.agents.cua import StartCuaTaskParams
13+
14+
15+
async def main() -> None:
16+
async with AsyncHyperbrowser() as client:
17+
result = await client.agents.cua.start_and_wait(
18+
StartCuaTaskParams(
19+
task="Open https://example.com and summarize the page.",
20+
max_steps=4,
21+
)
22+
)
23+
print(f"Job status: {result.status}")
24+
print(f"Steps collected: {len(result.steps)}")
25+
26+
27+
if __name__ == "__main__":
28+
asyncio.run(main())

examples/sync_cua_task.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Synchronous CUA task example.
3+
4+
Run:
5+
export HYPERBROWSER_API_KEY="your_api_key"
6+
python3 examples/sync_cua_task.py
7+
"""
8+
9+
from hyperbrowser import Hyperbrowser
10+
from hyperbrowser.models.agents.cua import StartCuaTaskParams
11+
12+
13+
def main() -> None:
14+
with Hyperbrowser() as client:
15+
result = client.agents.cua.start_and_wait(
16+
StartCuaTaskParams(
17+
task="Open https://example.com and summarize the page.",
18+
max_steps=4,
19+
)
20+
)
21+
print(f"Job status: {result.status}")
22+
print(f"Steps collected: {len(result.steps)}")
23+
24+
25+
if __name__ == "__main__":
26+
main()

0 commit comments

Comments
 (0)