(self, task: str = "", **kwargs)
| 339 | self.messages = [system_message, summary_message] |
| 340 | |
| 341 | def run(self, task: str = "", **kwargs) -> dict[str, Any]: |
| 342 | self.extra_template_vars |= {"task": task, **kwargs} |
| 343 | self.messages = [] |
| 344 | self.n_calls = 0 |
| 345 | self.n_format_errors = 0 |
| 346 | self.add_messages( |
| 347 | self.model.format_message(role="system", content=self._render_template(self.config.system_template)), |
| 348 | self.model.format_message(role="user", content=self._render_template(self.config.instance_template)), |
| 349 | ) |
| 350 | if self.extra_template_vars.get("explore_history"): |
| 351 | self.add_messages( |
| 352 | self.model.format_message( |
| 353 | role="user", |
| 354 | content="## Previous Explore History\n" |
| 355 | "Below is the message log from a prior live-browser exploration of this exact task.\n" |
| 356 | "Use it to understand the site layout, available controls, aria snapshots, and pitfalls.\n" |
| 357 | "Do NOT repeat failed approaches. Build on what was learned.\n\n" |
| 358 | + self.extra_template_vars["explore_history"] |
| 359 | + "\n\n## End of Explore History", |
| 360 | ), |
| 361 | ) |
| 362 | |
| 363 | while True: |
| 364 | try: |
| 365 | self.step() |
| 366 | except InterruptAgentFlow as exc: |
| 367 | if isinstance(exc, FormatError): |
| 368 | self.n_format_errors += 1 |
| 369 | self.add_messages(*exc.messages) |
| 370 | finally: |
| 371 | self.save(self.config.output_path) |
| 372 | if self.messages[-1].get("role") == "exit": |
| 373 | break |
| 374 | if ( |
| 375 | self.config.summary_every_n_steps > 0 |
| 376 | and self.n_calls > 0 |
| 377 | and self.n_calls % self.config.summary_every_n_steps == 0 |
| 378 | ): |
| 379 | self._compact_history() |
| 380 | self.save(self.config.output_path) |
| 381 | return self.messages[-1].get("extra", {}) |
| 382 | |
| 383 | def step(self) -> list[dict[str, Any]]: |
| 384 | return self.execute_actions(self.query()) |
no test coverage detected