|
23 | 23 |
|
24 | 24 | async def main():
|
25 | 25 | async with LocalPlaywrightComputer() as computer:
|
| 26 | + input_items = [ |
| 27 | + { |
| 28 | + "role": "user", |
| 29 | + "content": "Browse wikipedia, and keep clicking on the first link you see until you find the page about Stephen Hawking. Don't search, just click.", |
| 30 | + } |
| 31 | + ] |
26 | 32 | with trace("Computer use example"):
|
27 |
| - agent = Agent( |
28 |
| - name="Browser user", |
29 |
| - instructions="You are a helpful agent.", |
30 |
| - tools=[ComputerTool(computer)], |
31 |
| - # Use the computer using model, and set truncation to auto because its required |
32 |
| - model="computer-use-preview", |
33 |
| - model_settings=ModelSettings(truncation="auto"), |
34 |
| - ) |
35 |
| - result = await Runner.run(agent, "Search for SF sports news and summarize.") |
36 |
| - print(result.final_output) |
| 33 | + while True: |
| 34 | + print("Turn ") |
| 35 | + agent = Agent( |
| 36 | + name="Browser user", |
| 37 | + instructions="You are a helpful agent.", |
| 38 | + tools=[ComputerTool(computer)], |
| 39 | + # Use the computer using model, and set truncation to auto because its required |
| 40 | + model="computer-use-preview", |
| 41 | + model_settings=ModelSettings(truncation="auto"), |
| 42 | + ) |
| 43 | + result = await Runner.run( |
| 44 | + agent, |
| 45 | + input_items, |
| 46 | + max_turns=10000, |
| 47 | + ) |
| 48 | + input_items = result.to_input_list() |
37 | 49 |
|
38 | 50 |
|
39 | 51 | CUA_KEY_TO_PLAYWRIGHT_KEY = {
|
@@ -79,7 +91,7 @@ async def _get_browser_and_page(self) -> tuple[Browser, Page]:
|
79 | 91 | browser = await self.playwright.chromium.launch(headless=False, args=launch_args)
|
80 | 92 | page = await browser.new_page()
|
81 | 93 | await page.set_viewport_size({"width": width, "height": height})
|
82 |
| - await page.goto("https://www.bing.com") |
| 94 | + await page.goto("https://en.wikipedia.org/wiki/Main_Page") |
83 | 95 | return browser, page
|
84 | 96 |
|
85 | 97 | async def __aenter__(self):
|
|
0 commit comments