Skip to content

Commit 7068412

Browse files
authored
Consolidate Agent (#91)
* Consolidate Agent * parametrize model * kwargs agent execute * address comments
1 parent 14f85b2 commit 7068412

File tree

7 files changed

+173
-227
lines changed

7 files changed

+173
-227
lines changed

examples/agent_example.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,71 +33,48 @@
3333
quiet_dependencies=True, # Reduce noise from dependencies
3434
)
3535

36-
console.print(
37-
Panel.fit(
38-
"[yellow]Logging Levels:[/]\n"
39-
"[white]- Set [bold]verbose=0[/] for errors (ERROR)[/]\n"
40-
"[white]- Set [bold]verbose=1[/] for minimal logs (INFO)[/]\n"
41-
"[white]- Set [bold]verbose=2[/] for medium logs (WARNING)[/]\n"
42-
"[white]- Set [bold]verbose=3[/] for detailed logs (DEBUG)[/]",
43-
title="Verbosity Options",
44-
border_style="blue",
45-
)
46-
)
47-
4836
async def main():
4937
# Build a unified configuration object for Stagehand
5038
config = StagehandConfig(
5139
env="BROWSERBASE",
40+
# env="LOCAL",
5241
api_key=os.getenv("BROWSERBASE_API_KEY"),
5342
project_id=os.getenv("BROWSERBASE_PROJECT_ID"),
54-
headless=False,
55-
dom_settle_timeout_ms=3000,
5643
model_name="gpt-4o",
5744
self_heal=True,
58-
wait_for_captcha_solves=True,
5945
system_prompt="You are a browser automation assistant that helps users navigate websites effectively.",
6046
model_client_options={"apiKey": os.getenv("MODEL_API_KEY")},
61-
verbose=2,
47+
verbose=1,
6248
)
6349

6450
# Create a Stagehand client using the configuration object.
65-
stagehand = Stagehand(
66-
config=config,
67-
api_url=os.getenv("STAGEHAND_API_URL"),
68-
)
51+
stagehand = Stagehand(config)
6952

7053
# Initialize - this creates a new session automatically.
7154
console.print("\n🚀 [info]Initializing Stagehand...[/]")
7255
await stagehand.init()
73-
console.print(f"\n[yellow]Created new session:[/] {stagehand.session_id}")
74-
console.print(
75-
f"🌐 [white]View your live browser:[/] [url]https://www.browserbase.com/sessions/{stagehand.session_id}[/]"
76-
)
56+
if stagehand.env == "BROWSERBASE":
57+
console.print(f"\n[yellow]Created new session:[/] {stagehand.session_id}")
58+
console.print(
59+
f"🌐 [white]View your live browser:[/] [url]https://www.browserbase.com/sessions/{stagehand.session_id}[/]"
60+
)
61+
62+
console.print("\n▶️ [highlight] Navigating[/] to Google")
63+
await stagehand.page.goto("https://google.com/")
64+
console.print("✅ [success]Navigated to Google[/]")
7765

78-
# Configure the agent
79-
agent_config = AgentConfig(
80-
provider=AgentProvider.OPENAI,
66+
console.print("\n▶️ [highlight] Using Agent to perform a task[/]: playing a game of 2048")
67+
agent = stagehand.agent(
8168
model="computer-use-preview",
8269
instructions="You are a helpful web navigation assistant that helps users find information. You are currently on the following page: google.com. Do not ask follow up questions, the user will trust your judgement.",
8370
options={"apiKey": os.getenv("MODEL_API_KEY")}
8471
)
85-
86-
# Define the task for the agent
87-
execute_options = AgentExecuteOptions(
72+
agent_result = await agent.execute(
8873
instruction="Play a game of 2048",
8974
max_steps=20,
9075
auto_screenshot=True,
9176
)
9277

93-
console.print("\n▶️ [highlight] Navigating[/] to Google")
94-
await stagehand.page.goto("https://google.com/")
95-
console.print("✅ [success]Navigated to Google[/]")
96-
97-
console.print("\n▶️ [highlight] Using Agent to perform a task[/]: playing a game of 2048")
98-
agent = stagehand.agent(agent_config)
99-
agent_result = await agent.execute(execute_options)
100-
10178
console.print("📊 [info]Agent execution result:[/]")
10279
console.print(f"✅ Success: [bold]{'Yes' if agent_result.success else 'No'}[/]")
10380
console.print(f"🎯 Completed: [bold]{'Yes' if agent_result.completed else 'No'}[/]")
@@ -125,7 +102,7 @@ async def main():
125102
console.print(
126103
"\n",
127104
Panel.fit(
128-
"[light_gray]Stagehand 🤘 Async Agent Example[/]",
105+
"[light_gray]Stagehand 🤘 Agent Example[/]",
129106
border_style="green",
130107
padding=(1, 10),
131108
),

stagehand/agent.py

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)