Use the browser to interact with the internet to complete the task. Args: task (str): The task to complete.
(self, task: str, **kwargs)
| 125 | return ToolResponse(success=False, message=f"Error in browser tool: {str(e)}") |
| 126 | |
| 127 | async def __call__(self, task: str, **kwargs) -> ToolResponse: |
| 128 | """Use the browser to interact with the internet to complete the task. |
| 129 | |
| 130 | Args: |
| 131 | task (str): The task to complete. |
| 132 | """ |
| 133 | try: |
| 134 | logger.info(f"| 🌐 Starting browser task: {task}") |
| 135 | |
| 136 | # Generate unique id for this browser task |
| 137 | id = generate_unique_id(prefix="browser") |
| 138 | |
| 139 | # Create file path for markdown report |
| 140 | md_filename = f"{id}.md" |
| 141 | file_path = os.path.join(self.base_dir, md_filename) if self.base_dir else None |
| 142 | |
| 143 | # Initialize Report instance |
| 144 | report = Report( |
| 145 | title="Browser Task Report", |
| 146 | model_name=self.model_name, |
| 147 | report_file_path=file_path |
| 148 | ) |
| 149 | |
| 150 | # Add initial task information |
| 151 | task_content = f"## Browser Task\n\n{task}\n\n" |
| 152 | await report.add_item(task_content) |
| 153 | |
| 154 | # Execute browser agent with unique id |
| 155 | response = await self._call_agent(task=task, id=id, **kwargs) |
| 156 | |
| 157 | # Extract result message |
| 158 | if isinstance(response, ToolResponse): |
| 159 | result_message = response.message |
| 160 | success = response.success |
| 161 | else: |
| 162 | result_message = str(response) |
| 163 | success = True |
| 164 | |
| 165 | # Add result to report |
| 166 | result_content = f"## Browser Execution Result\n\n{result_message}\n\n" |
| 167 | await report.add_item(result_content) |
| 168 | |
| 169 | # Generate final report |
| 170 | if file_path: |
| 171 | final_report_content = await report.complete() |
| 172 | logger.info(f"✅ Browser report saved to: {file_path}") |
| 173 | |
| 174 | message = f"Browser task completed successfully!\n\nTask: {task}\n\nResult: {result_message}\n\nReport saved to: {file_path}" |
| 175 | |
| 176 | return ToolResponse( |
| 177 | success=success, |
| 178 | message=message, |
| 179 | extra=ToolExtra( |
| 180 | file_path=file_path, |
| 181 | data={ |
| 182 | "task": task, |
| 183 | "file_path": file_path, |
| 184 | "result": result_message |
nothing calls this directly
no test coverage detected