@@ -50,21 +50,33 @@ def __init__(
50
50
config : Optional [AgentConfig ] = None ,
51
51
logger : Optional [Any ] = None ,
52
52
handler : Optional [CUAHandler ] = None ,
53
+ viewport : Optional [dict [str , int ]] = None ,
53
54
** kwargs ,
54
55
):
55
56
super ().__init__ (model , instructions , config , logger , handler )
56
57
self .anthropic_sdk_client = Anthropic (api_key = os .getenv ("ANTHROPIC_API_KEY" ))
57
58
58
- dimensions = [1024 , 768 ] # Default dimensions
59
+ dimensions = (
60
+ (viewport ["width" ], viewport ["height" ]) if viewport else (1024 , 768 )
61
+ ) # Default dimensions
59
62
if self .config :
60
63
if hasattr (self .config , "display_width" ) and self .config .display_width is not None : # type: ignore
61
64
dimensions [0 ] = self .config .display_width # type: ignore
62
65
if hasattr (self .config , "display_height" ) and self .config .display_height is not None : # type: ignore
63
66
dimensions [1 ] = self .config .display_height # type: ignore
64
-
67
+ computer_tool_type = (
68
+ "computer_20250124"
69
+ if model == "claude-3-7-sonnet-latest"
70
+ else "computer_20241022"
71
+ )
72
+ self .beta_flag = (
73
+ ["computer-use-2025-01-24" ]
74
+ if model == "claude-3-7-sonnet-latest"
75
+ else ["computer-use-2024-10-22" ]
76
+ )
65
77
self .tools = [
66
78
{
67
- "type" : "computer_20250124" ,
79
+ "type" : computer_tool_type ,
68
80
"name" : "computer" ,
69
81
"display_width_px" : dimensions [0 ],
70
82
"display_height_px" : dimensions [1 ],
@@ -155,7 +167,7 @@ async def run_task(
155
167
+ "Remember to call the computer tools, and only goto or navigate_back if you need to. Screenshots, clicks, etc, will be parsed from computer tool calls" , # System prompt
156
168
messages = current_messages ,
157
169
tools = self .tools ,
158
- betas = [ "computer-use-2025-01-24" ] ,
170
+ betas = self . beta_flag ,
159
171
)
160
172
end_time = asyncio .get_event_loop ().time ()
161
173
total_inference_time_ms += int ((end_time - start_time ) * 1000 )
0 commit comments