MCPcopy Index your code
hub / github.com/microsoft/Webwright / run

Method run

src/webwright/agents/default.py:341–381  ·  view source on GitHub ↗
(self, task: str = "", **kwargs)

Source from the content-addressed store, hash-verified

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())

Callers 6

executeMethod · 0.45
run_self_reflectionFunction · 0.45
run_asyncFunction · 0.45
_validate_bash_commandFunction · 0.45
run_oneFunction · 0.45
check_chromiumFunction · 0.45

Calls 6

add_messagesMethod · 0.95
_render_templateMethod · 0.95
stepMethod · 0.95
saveMethod · 0.95
_compact_historyMethod · 0.95
format_messageMethod · 0.45

Tested by

no test coverage detected