feat: add rotating User-Agent headers & pre-tool-call guardrail authorization layer#1337
Open
programming-pupil wants to merge 4 commits into
Open
feat: add rotating User-Agent headers & pre-tool-call guardrail authorization layer#1337programming-pupil wants to merge 4 commits into
programming-pupil wants to merge 4 commits into
Conversation
Author
|
Hi @appleboy @zhoupeng @Shellmode @cnJasonZ , just a gentle ping on this PR when you have some free cycles. All checks have passed. Please let me know if you need any additional context or changes from my end. Thanks! |
Author
|
@appleboy @zhoupeng @Shellmode @cnJasonZ Hi, I’m a big fan of OpenManus and would love to see it keep evolving. Since it’s been a while since the last update, I wanted to offer my help. Beyond this PR, I’m very much open to helping with issue triaging or ongoing maintenance if you’re looking for a co-maintainer. Let me know your thoughts! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR combines two improvements to OpenManus's tool infrastructure:
Rotating User-Agent for WebSearch —
WebContentFetchernow randomly selects from a pool of 5 realistic User-Agent strings (Chrome/Firefox/Safari across Windows/macOS/Linux) on each request, preventing web servers from detecting and blocking automated scraping based on a fixed header.Pre-tool-call Guardrail Authorization — Adds a pluggable authorization layer to
BaseTool, implementing the OAPbefore_tool_callpattern. AGuardrailProviderprotocol is evaluated inBaseTool.__call__()beforeexecute(), returning allow/deny with reasons. Denied calls return aToolResult(error=...)without executing the underlying tool logic. Fully backward compatible — if no guardrail provider is set, all calls are allowed by default.Changes
app/tool/web_search.py: Addedrandomimport and_USER_AGENTSpool;WebContentFetchernow rotates User-Agent per requestapp/tool/base.py: AddedGuardrailCheckResultmodel,GuardrailProviderProtocol,AllowlistGuardrailbuilt-in implementation, and_run_with_guardrail()hook inBaseToolapp/tool/__init__.py: Updated exports to includeGuardrailCheckResult,AllowlistGuardrail,CLIResult,ToolFailure,ToolResultWhy this matters
Backward compatibility
BaseToolsubclassguardrail_providercontinue to work as beforeWebContentFetcherAPI unchanged, only internal header selection logic updated