-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path21_computer_use.py
More file actions
51 lines (40 loc) · 1.72 KB
/
21_computer_use.py
File metadata and controls
51 lines (40 loc) · 1.72 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
"""Drive Anthropic Computer-Use against the live screen.
Requires:
* ``pip install je_auto_control[agent]`` (or just ``anthropic``);
* ``ANTHROPIC_API_KEY`` in the environment.
The single :func:`run_computer_use` call wires together:
* :class:`ComputerUseAgentBackend` — Anthropic's official
``computer_20250124`` tool with proper system prompt and screenshot
attachment, so the model uses its trained behaviour;
* :class:`AgentLoop` — observe → decide → execute → loop, with budget
guards so a runaway call can't drain the API;
* the standard AC_* tool dispatch — every action the model issues is
translated to the matching wrapper call and executed locally.
For programmatic use the same wrapper is also exposed as the
``AC_computer_use`` executor command (JSON action files / scheduler /
triggers / REST) and the ``ac_computer_use`` MCP tool (Claude Desktop
/ Claude Code).
"""
import os
from je_auto_control import run_computer_use
def main() -> None:
if not os.environ.get("ANTHROPIC_API_KEY"):
print("ANTHROPIC_API_KEY not set — skipping live run.")
return
result = run_computer_use(
"open the Calculator app, compute 12 * 7, then take a screenshot",
max_steps=15,
wall_seconds=120.0,
)
print(f"succeeded={result.succeeded} steps={len(result.steps)}"
f" elapsed={result.elapsed_s:.2f}s")
print("final message:", result.final_message)
for step in result.steps:
head = f" [{step.index}]"
if step.tool:
print(f"{head} {step.tool}({step.arguments})"
f"{' ! ' + step.error if step.error else ''}")
else:
print(f"{head} stop: {step.stop_reason}")
if __name__ == "__main__":
main()