Coool2 commited on
Commit
2d8a87a
·
1 Parent(s): f39446f

Update agent2.py

Browse files
Files changed (1) hide show
  1. agent2.py +23 -23
agent2.py CHANGED
@@ -144,29 +144,29 @@ class BM25RetrieverTool(Tool):
144
  return f"Error getting page text: {e}"
145
 
146
 
147
- def save_screenshot_callback(memory_step: ActionStep, agent: CodeAgent) -> None:
148
- """Save screenshots for web browser automation"""
149
- try:
150
- sleep(1.0)
151
- driver = helium.get_driver()
152
- if driver is not None:
153
- # Clean up old screenshots
154
- for previous_memory_step in agent.memory.steps:
155
- if isinstance(previous_memory_step, ActionStep) and previous_memory_step.step_number <= memory_step.step_number - 2:
156
- previous_memory_step.observations_images = None
157
-
158
- png_bytes = driver.get_screenshot_as_png()
159
- image = Image.open(BytesIO(png_bytes))
160
- memory_step.observations_images = [image.copy()]
161
-
162
- # Update observations with current URL
163
- url_info = f"Current url: {driver.current_url}"
164
- memory_step.observations = (
165
- url_info if memory_step.observations is None
166
- else memory_step.observations + "\n" + url_info
167
- )
168
- except Exception as e:
169
- print(f"Error in screenshot callback: {e}")
170
 
171
 
172
  class GAIAAgent:
 
144
  return f"Error getting page text: {e}"
145
 
146
 
147
+ def save_screenshot_callback(memory_step: ActionStep, agent: CodeAgent) -> None:
148
+ """Save screenshots for web browser automation"""
149
+ try:
150
+ sleep(1.0)
151
+ driver = helium.get_driver()
152
+ if driver is not None:
153
+ # Clean up old screenshots
154
+ for previous_memory_step in agent.memory.steps:
155
+ if isinstance(previous_memory_step, ActionStep) and previous_memory_step.step_number <= memory_step.step_number - 2:
156
+ previous_memory_step.observations_images = None
157
+
158
+ png_bytes = driver.get_screenshot_as_png()
159
+ image = Image.open(BytesIO(png_bytes))
160
+ memory_step.observations_images = [image.copy()]
161
+
162
+ # Update observations with current URL
163
+ url_info = f"Current url: {driver.current_url}"
164
+ memory_step.observations = (
165
+ url_info if memory_step.observations is None
166
+ else memory_step.observations + "\n" + url_info
167
+ )
168
+ except Exception as e:
169
+ print(f"Error in screenshot callback: {e}")
170
 
171
 
172
  class GAIAAgent: