🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat: Add playwright mcp toolkit (#2353)
Wendong-Fand7805705efe1
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.pyindex 080e527e7..377c450c2 100644--- a/camel/toolkits/__init__.py+++ b/camel/toolkits/__init__.py@@ -71,6 +71,7 @@ from .jina_reranker_toolkit import JinaRerankerToolkitfrom .pulse_mcp_search_toolkit import PulseMCPSearchToolkitfrom .klavis_toolkit import KlavisToolkitfrom .aci_toolkit import ACIToolkit+from .playwright_mcp_toolkit import PlaywrightMCPToolkit__all__ = [@@ -130,4 +131,5 @@ __all__ = ['PulseMCPSearchToolkit','KlavisToolkit','ACIToolkit',+ 'PlaywrightMCPToolkit',]diff --git a/camel/toolkits/playwright_mcp_toolkit.py b/camel/toolkits/playwright_mcp_toolkit.pynew file mode 100644index 000000000..d193bbff1--- /dev/null+++ b/camel/toolkits/playwright_mcp_toolkit.py@@ -0,0 +1,69 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++from typing import List, Optional++from camel.toolkits import BaseToolkit, FunctionTool++from .mcp_toolkit import MCPToolkit+++class PlaywrightMCPToolkit(BaseToolkit):+ r"""PlaywrightMCPToolkit provides an interface for interacting with web+ browsers using the Playwright automation library through the Model Context+ Protocol (MCP).++ Attributes:+ timeout (Optional[float]): Connection timeout in seconds.+ (default: :obj:`None`)++ Note:+ Currently only supports asynchronous operation mode.+ """++ def __init__(self, timeout: Optional[float] = None) -> None:+ r"""Initializes the PlaywrightMCPToolkit with the specified timeout.++ Args:+ timeout (Optional[float]): Connection timeout in seconds.+ (default: :obj:`None`)+ """+ super().__init__(timeout=timeout)++ self._mcp_toolkit = MCPToolkit(+ config_dict={+ "mcpServers": {+ "playwright": {+ "command": "npx",+ "args": ["@playwright/mcp@latest"],+ }+ }+ }+ )++ async def connect(self):+ r"""Explicitly connect to the Playwright MCP server."""+ await self._mcp_toolkit.connect()++ async def disconnect(self):+ r"""Explicitly disconnect from the Playwright MCP server."""+ await self._mcp_toolkit.disconnect()++ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of tools provided by the PlaywrightMCPToolkit.++ Returns:+ List[FunctionTool]: List of available tools.+ """+ return self._mcp_toolkit.get_tools()diff --git a/examples/toolkits/openai_agent_toolkit_example.py b/examples/toolkits/openai_agent_toolkit.pysimilarity index 100%rename from examples/toolkits/openai_agent_toolkit_example.pyrename to examples/toolkits/openai_agent_toolkit.pydiff --git a/examples/toolkits/playwright_mcp_toolkit.py b/examples/toolkits/playwright_mcp_toolkit.pynew file mode 100644index 000000000..f9581e566--- /dev/null+++ b/examples/toolkits/playwright_mcp_toolkit.py@@ -0,0 +1,56 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+import asyncio++from camel.agents import ChatAgent+from camel.models import ModelFactory+from camel.toolkits import PlaywrightMCPToolkit+from camel.types import ModelPlatformType, ModelType+++async def main():+ playwright_mcp_toolkit = PlaywrightMCPToolkit()++ # connect to playwright mcp+ await playwright_mcp_toolkit.connect()++ model = ModelFactory.create(+ model_platform=ModelPlatformType.DEFAULT,+ model_type=ModelType.DEFAULT,+ )++ chat_agent = ChatAgent(+ model=model,+ tools=playwright_mcp_toolkit.get_tools(),+ )++ response = await chat_agent.astep(+ "search for camel-ai using google search, how many stars does it have?"+ )+ print(response.msg.content)++ # disconnect from playwright mcp+ await playwright_mcp_toolkit.disconnect()+++# Run the async main function+if __name__ == "__main__":+ asyncio.run(main())++"""+==============================================================================+The GitHub repository for **camel-ai** has **12,338 stars**. If you need more+information or details about the project, feel free to ask!+==============================================================================+"""diff --git a/examples/toolkits/searxng_toolkit_example.py b/examples/toolkits/searxng_toolkit.pysimilarity index 100%rename from examples/toolkits/searxng_toolkit_example.pyrename to examples/toolkits/searxng_toolkit.py