-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcomputer_use_loop_example.py
More file actions
65 lines (54 loc) · 2.2 KB
/
computer_use_loop_example.py
File metadata and controls
65 lines (54 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Custom computer-use agent loop demo with no browser, network, or API key.
Run:
python examples/computer_use_loop_example.py
browsertrace
Then open http://127.0.0.1:3000 and click
"demo: custom computer-use checkout".
"""
from __future__ import annotations
import os
from browsertrace import Tracer
def main() -> None:
tracer = Tracer(home=os.environ.get("BROWSERTRACE_HOME"))
try:
with tracer.run("demo: custom computer-use checkout") as run:
run.step(
action="open checkout page",
url="https://shop.example.test/checkout",
model_input={"task": "complete checkout", "state": "start"},
model_output={"next_action": "observe page"},
)
run.step(
action="observe checkout form",
url="https://shop.example.test/checkout",
model_input={
"task": "complete checkout",
"observation": "checkout form is visible; submit button looks primary",
},
model_output={
"thought": "The primary checkout button should submit the form.",
"selector": "button.checkout.primary",
"next_action": "click",
},
agent_loop="observe-decide-act",
)
run.step(
action="click model-selected submit button",
url="https://shop.example.test/checkout",
model_input={
"task": "complete checkout",
"target_selector": "button.checkout.primary",
},
model_output={
"thought": "Click the primary checkout button to finish.",
"selector": "button.checkout.primary",
"action": "click",
},
agent_loop="observe-decide-act",
)
raise RuntimeError("disabled submit button blocked checkout")
except RuntimeError as exc:
print(f"Run failed as expected: {type(exc).__name__}: {exc}")
print("Done. Run `browsertrace` and open http://127.0.0.1:3000")
if __name__ == "__main__":
main()