-
Notifications
You must be signed in to change notification settings - Fork 82
fix cua example, remove root model #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2c2580b
fix cua example, remove root model
derekmeegan a258f9f
formatting
derekmeegan 2f7a41e
so formatted
derekmeegan 744b78f
add changeset
derekmeegan 690a801
fix anthropic cua and add self heal back to agent exmaples
derekmeegan a76eefe
formatting
derekmeegan 3d9d7dd
add back point and function argument types
derekmeegan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "stagehand": patch | ||
| --- | ||
|
|
||
| add local cua example, remove root model from types |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import asyncio | ||
| import logging | ||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
| from rich.console import Console | ||
| from rich.panel import Panel | ||
| from rich.theme import Theme | ||
|
|
||
| from stagehand import Stagehand, StagehandConfig, configure_logging | ||
|
|
||
| # Create a custom theme for consistent styling | ||
| custom_theme = Theme( | ||
| { | ||
| "info": "cyan", | ||
| "success": "green", | ||
| "warning": "yellow", | ||
| "error": "red bold", | ||
| "highlight": "magenta", | ||
| "url": "blue underline", | ||
| } | ||
| ) | ||
|
|
||
| # Create a Rich console instance with our theme | ||
| console = Console(theme=custom_theme) | ||
|
|
||
| load_dotenv() | ||
|
|
||
| # Configure logging with the utility function | ||
| configure_logging( | ||
| level=logging.INFO, # Set to INFO for regular logs, DEBUG for detailed | ||
| quiet_dependencies=True, # Reduce noise from dependencies | ||
| ) | ||
|
|
||
| async def main(): | ||
| # Build a unified configuration object for Stagehand | ||
| config = StagehandConfig( | ||
| env="LOCAL", | ||
| system_prompt="You are a browser automation assistant that helps users navigate websites effectively.", | ||
| model_client_options={"apiKey": os.getenv("MODEL_API_KEY")}, | ||
| self_heal=True, | ||
| verbose=2, | ||
| ) | ||
|
|
||
| # Create a Stagehand client using the configuration object. | ||
| stagehand = Stagehand(config) | ||
|
|
||
| # Initialize - this creates a new session automatically. | ||
| console.print("\n🚀 [info]Initializing Stagehand...[/]") | ||
| await stagehand.init() | ||
|
|
||
| console.print("\n▶️ [highlight] Navigating[/] to Google") | ||
| await stagehand.page.goto("https://google.com/") | ||
| console.print("✅ [success]Navigated to Google[/]") | ||
|
|
||
| console.print("\n▶️ [highlight] Using Agent to perform a task[/]: playing a game of 2048") | ||
| agent = stagehand.agent( | ||
| model="gemini-2.5-computer-use-preview-10-2025", | ||
| 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.", | ||
| options={"apiKey": os.getenv("GEMINI_API_KEY")} | ||
| ) | ||
| agent_result = await agent.execute( | ||
| instruction="Play a game of 2048", | ||
| max_steps=20, | ||
| auto_screenshot=True, | ||
| ) | ||
|
|
||
| console.print(agent_result) | ||
|
|
||
| console.print("📊 [info]Agent execution result:[/]") | ||
| console.print(f"🎯 Completed: [bold]{'Yes' if agent_result.completed else 'No'}[/]") | ||
| if agent_result.message: | ||
| console.print(f"💬 Message: [italic]{agent_result.message}[/]") | ||
|
|
||
| if agent_result.actions: | ||
| console.print(f"🔄 Actions performed: [bold]{len(agent_result.actions)}[/]") | ||
| for i, action in enumerate(agent_result.actions): | ||
| action_type = action.type | ||
|
|
||
| console.print(f" Action {i+1}: {action_type if action_type else 'Unknown'}") | ||
|
|
||
| # For debugging, you can also print the full JSON | ||
| console.print("[dim]Full response JSON:[/]") | ||
| console.print_json(f"{agent_result.model_dump_json()}") | ||
|
|
||
| # Close the session | ||
| console.print("\n⏹️ [warning]Closing session...[/]") | ||
| await stagehand.close() | ||
| console.print("✅ [success]Session closed successfully![/]") | ||
| console.rule("[bold]End of Example[/]") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| # Add a fancy header | ||
| console.print( | ||
| "\n", | ||
| Panel( | ||
| "[light_gray]Stagehand 🤘 Agent Example[/]", | ||
| border_style="green", | ||
| padding=(1, 10), | ||
| ), | ||
| ) | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.