The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: Fix Playwright Tools bug with Pydantic schemas (#27050)
Sergey Ryabov8180637345da
diff --git a/libs/community/extended_testing_deps.txt b/libs/community/extended_testing_deps.txtindex 1214645947..5be8760687 100644--- a/libs/community/extended_testing_deps.txt+++ b/libs/community/extended_testing_deps.txt@@ -58,6 +58,7 @@ oracledb>=2.2.0,<3pandas>=2.0.1,<3pdfminer-six>=20221105,<20240706pgvector>=0.1.6,<0.2+playwright>=1.48.0,<2praw>=7.7.1,<8premai>=0.3.25,<0.4psychicapi>=0.8.0,<0.9diff --git a/libs/community/langchain_community/tools/playwright/current_page.py b/libs/community/langchain_community/tools/playwright/current_page.pyindex 50033d7f37..861b2eca53 100644--- a/libs/community/langchain_community/tools/playwright/current_page.py+++ b/libs/community/langchain_community/tools/playwright/current_page.py@@ -15,12 +15,16 @@ from langchain_community.tools.playwright.utils import ()+class CurrentWebPageToolInput(BaseModel):+ """Explicit no-args input for CurrentWebPageTool."""++class CurrentWebPageTool(BaseBrowserTool): # type: ignore[override, override]"""Tool for getting the URL of the current webpage."""name: str = "current_webpage"description: str = "Returns the URL of the current page"- args_schema: Type[BaseModel] = BaseModel+ args_schema: Type[BaseModel] = CurrentWebPageToolInputdef _run(self,diff --git a/libs/community/langchain_community/tools/playwright/extract_text.py b/libs/community/langchain_community/tools/playwright/extract_text.pyindex dc77f1297f..98774f7355 100644--- a/libs/community/langchain_community/tools/playwright/extract_text.py+++ b/libs/community/langchain_community/tools/playwright/extract_text.py@@ -15,12 +15,16 @@ from langchain_community.tools.playwright.utils import ()+class ExtractTextToolInput(BaseModel):+ """Explicit no-args input for ExtractTextTool."""++class ExtractTextTool(BaseBrowserTool): # type: ignore[override, override]"""Tool for extracting all the text on the current webpage."""name: str = "extract_text"description: str = "Extract all the text on the current webpage"- args_schema: Type[BaseModel] = BaseModel+ args_schema: Type[BaseModel] = ExtractTextToolInput@model_validator(mode="before")@classmethoddiff --git a/libs/community/langchain_community/tools/playwright/navigate_back.py b/libs/community/langchain_community/tools/playwright/navigate_back.pyindex 688b135a23..2a2eff3890 100644--- a/libs/community/langchain_community/tools/playwright/navigate_back.py+++ b/libs/community/langchain_community/tools/playwright/navigate_back.py@@ -15,12 +15,16 @@ from langchain_community.tools.playwright.utils import ()+class NavigateBackToolInput(BaseModel):+ """Explicit no-args input for NavigateBackTool."""++class NavigateBackTool(BaseBrowserTool): # type: ignore[override, override]"""Navigate back to the previous page in the browser history."""name: str = "previous_webpage"description: str = "Navigate back to the previous page in the browser history"- args_schema: Type[BaseModel] = BaseModel+ args_schema: Type[BaseModel] = NavigateBackToolInputdef _run(self, run_manager: Optional[CallbackManagerForToolRun] = None) -> str:"""Use the tool."""diff --git a/libs/community/tests/unit_tests/tools/playwright/__init__.py b/libs/community/tests/unit_tests/tools/playwright/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/libs/community/tests/unit_tests/tools/playwright/test_all.py b/libs/community/tests/unit_tests/tools/playwright/test_all.pynew file mode 100644index 0000000000..8d0c9b98f5--- /dev/null+++ b/libs/community/tests/unit_tests/tools/playwright/test_all.py@@ -0,0 +1,26 @@+"""Test Playwright's Tools."""++from unittest.mock import Mock++import pytest++from langchain_community.agent_toolkits import PlayWrightBrowserToolkit++[email protected]("playwright")[email protected]("bs4")+def test_playwright_tools_schemas() -> None:+ """Test calling 'tool_call_schema' for every tool to check to init issues."""++ from playwright.sync_api import Browser++ sync_browser = Mock(spec=Browser)+ tools = PlayWrightBrowserToolkit.from_browser(sync_browser=sync_browser).get_tools()++ for tool in tools:+ try:+ tool.tool_call_schema+ except Exception as e:+ raise AssertionError(+ f"Error for '{tool.name}' tool: {type(e).__name__}: {e}"+ ) from e