-
Notifications
You must be signed in to change notification settings - Fork 1.2k
update the browser-use agent example #705
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the browser-use agent example with significant improvements to functionality and structure. The changes enhance the agent's task decomposition capabilities, add structured output support, and improve the overall architecture.
- Replaces hardcoded prompts with external markdown files for better maintainability
- Adds task decomposition functionality to break complex tasks into manageable subtasks
- Introduces structured output support using Pydantic models
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/agent_browser/main.py | Updates agent configuration, adds structured output model, and fixes grammar in documentation |
| examples/agent_browser/build_in_prompt/browser_agent_task_decomposition_prompt.md | New prompt template for decomposing browser automation tasks into subtasks |
| examples/agent_browser/build_in_prompt/browser_agent_sys_prompt.md | New system prompt defining the browser agent's behavior and guidelines |
| examples/agent_browser/build_in_prompt/browser_agent_summarize_task.md | New prompt template for generating comprehensive task summary reports |
| examples/agent_browser/build_in_prompt/browser_agent_reasoning_prompt.md | New reasoning prompt for chunk-based webpage analysis |
| examples/agent_browser/browser_agent.py | Major refactor adding task decomposition, chunk-based observation, structured output, and multimodal support |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| with open( | ||
| "examples/agent_browser/build_in_prompt/browser_agent_sys_prompt.md", | ||
| "r", | ||
| encoding="utf-8", | ||
| ) as f: | ||
| _BROWSER_AGENT_DEFAULT_SYS_PROMPT = f.read() |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded file paths make the code fragile and dependent on the current working directory. Consider using os.path.dirname(__file__) or pathlib.Path(__file__).parent to construct relative paths from the current module's location.
| ) as f: | ||
| _BROWSER_AGENT_DEFAULT_REASONING_PROMPT = f.read() | ||
| with open( | ||
| "examples/agent_browser/build_in_prompt/browser_agent_task_decomposition_prompt.md", # noqa: E501 pylint: disable=C0301 |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using both noqa and pylint disable comments for the same line length issue is redundant. Choose one consistent approach throughout the codebase.
| "examples/agent_browser/build_in_prompt/browser_agent_task_decomposition_prompt.md", # noqa: E501 pylint: disable=C0301 | |
| "examples/agent_browser/build_in_prompt/browser_agent_task_decomposition_prompt.md", # pylint: disable=C0301 |
| self.iter_n = 0 | ||
| self.finish_function_name = "browser_generate_final_response" | ||
| self.init_query = "" | ||
| self._required_structured_model: Type[BaseModel] | None = None |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Optional[Type[BaseModel]] instead of Type[BaseModel] | None for better compatibility with older Python versions and consistency with other type hints in the codebase.
| self._required_structured_model: Type[BaseModel] | None = None | |
| self._required_structured_model: Optional[Type[BaseModel]] = None |
| text = re.sub(r"```yaml.*?```", "", text, flags=re.DOTALL) | ||
| # Remove JavaScript code blocks | ||
| text = re.sub(r"```js.*?```", "", text, flags=re.DOTALL) | ||
| # # Remove JavaScript code blocks |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commented-out code should be removed entirely rather than left as a comment. If the functionality might be needed later, consider documenting the reason for removal or create a proper TODO comment.
| # # Remove JavaScript code blocks |
| for i in range(0, len(snapshot_str), max_length) | ||
| ] | ||
|
|
||
| def observe_by_chunk(self, image_path: str | None = "") -> Msg: |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Optional[str] instead of str | None for consistency with other type hints in the codebase, and consider using None as the default value instead of an empty string for an optional parameter.
| def observe_by_chunk(self, image_path: str | None = "") -> Msg: | |
| def observe_by_chunk(self, image_path: Optional[str] = None) -> Msg: |
Add a dfs search example in Browser Agent
|
This PR is marked as stale because there has been no activity for 30 days. Remove stale label or add new comments or this PR will be closed in 5 day. |
|
|
AgentScope Version
[The version of AgentScope you are working on, e.g.
import agentscope; print(agentscope.__version__)]Description
[Please describe the background, purpose, changes made, and how to test this PR]
Checklist
Please check the following items before code is ready to be reviewed.
pre-commit run --all-filescommand