Spaces:
Configuration error
Configuration error
Update agent2.py
Browse files
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 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
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:
|