import os
import anthropic
from orgo import Computer
# Set up API keys
os.environ["ORGO_API_KEY"] = "your_orgo_api_key"
api_key = "your_anthropic_api_key"
# Initialize components
computer = Computer()
client = anthropic.Anthropic(api_key=api_key)
try:
# Initial request
messages = [{"role": "user", "content": "Open Firefox and go to anthropic.com"}]
# Define the computer tool
tools = [
{
"type": "computer_20250124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768,
"display_number": 1
}
]
# Start the conversation
response = client.beta.messages.create(
model="claude-3-7-sonnet-20250219",
messages=messages,
tools=tools,
betas=["computer-use-2025-01-24"],
max_tokens=4096
)
# Add Claude's response to the conversation
messages.append({"role": "assistant", "content": response.content})
# Loop until Claude doesn't request any more tools
while True:
# Check if Claude used any tools
tool_results = []
for block in response.content:
if block.type == "tool_use":
# Get the tool parameters
action = block.input.get("action")
# Execute the tool action
result = None
if action == "screenshot":
response_data = computer.screenshot_base64()
result = {
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": response_data
}
}
elif action == "left_click":
x, y = block.input.get("coordinate", [0, 0])
computer.left_click(x, y)
result = {"type": "text", "text": f"Left click at ({x}, {y}) successful"}
elif action == "type":
text = block.input.get("text", "")
computer.type(text)
result = {"type": "text", "text": f"Typed: {text}"}
# Format the result for Claude
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": [result] if result else [{"type": "text", "text": "Action completed"}]
})
# If no tools were used, Claude is done
if not tool_results:
break
# Send tool results back to Claude
messages.append({"role": "user", "content": tool_results})
# Get Claude's next response
response = client.beta.messages.create(
model="claude-3-7-sonnet-20250219",
messages=messages,
tools=tools,
betas=["computer-use-2025-01-24"],
max_tokens=4096
)
# Add Claude's response to the conversation
messages.append({"role": "assistant", "content": response.content})
print("Task complete!")
finally:
# Always clean up
computer.shutdown()