-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_tab.py
More file actions
47 lines (34 loc) · 1.18 KB
/
Copy pathmulti_tab.py
File metadata and controls
47 lines (34 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Multi-tab recipe — the agent opens several tabs to compare data.
Uses Browser Use's built-in multi-tab support. Witness captures the active
page at each step, so you see the context switch reflected in the URL
column and screenshot diff.
python examples/multi_tab.py
witness view
"""
from __future__ import annotations
import asyncio
import os
import sys
from dotenv import load_dotenv
import witness
load_dotenv(override=True)
async def main() -> None:
if not os.environ.get("ANTHROPIC_API_KEY"):
print("ANTHROPIC_API_KEY not set (add to .env)", file=sys.stderr)
sys.exit(1)
from browser_use import Agent
from browser_use.llm import ChatAnthropic
agent = Agent(
task=(
"Open three tabs: https://news.ycombinator.com, "
"https://lobste.rs, and https://old.reddit.com/r/programming. "
"From each, extract the single top story's title and points. "
"Return a comparison table."
),
llm=ChatAnthropic(model="claude-sonnet-4-5"),
)
witness.instrument(agent)
await agent.run()
print(f"\nTrace: {agent._witness_trace_id}")
if __name__ == "__main__":
asyncio.run(main())