🐫 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: search google supports image search (#2863)
Wendong-Fan89dc68d99bb6
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.ymlindex 8a50f469c..59066ff8f 100644--- a/.github/ISSUE_TEMPLATE/bug_report.yml+++ b/.github/ISSUE_TEMPLATE/bug_report.yml@@ -26,7 +26,7 @@ body:attributes:label: What version of camel are you using?description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.- placeholder: E.g., 0.2.71a12+ placeholder: E.g., 0.2.71a13validations:required: truediff --git a/camel/__init__.py b/camel/__init__.pyindex a5bc0170a..c3b684c97 100644--- a/camel/__init__.py+++ b/camel/__init__.py@@ -14,7 +14,7 @@from camel.logger import disable_logging, enable_logging, set_log_level-__version__ = '0.2.71a12'+__version__ = '0.2.71a13'__all__ = ['__version__',diff --git a/camel/societies/workforce/workforce.py b/camel/societies/workforce/workforce.pyindex e5c082b11..7f2b2da1b 100644--- a/camel/societies/workforce/workforce.py+++ b/camel/societies/workforce/workforce.py@@ -1721,23 +1721,51 @@ class Workforce(BaseNode):def _get_child_nodes_info(self) -> str:r"""Get the information of all the child nodes under this node."""- info = ""- for child in self._children:- if isinstance(child, Workforce):- additional_info = "A Workforce node"- elif isinstance(child, SingleAgentWorker):- additional_info = "tools: " + (- ", ".join(child.worker.tool_dict.keys())- )- elif isinstance(child, RolePlayingWorker):- additional_info = "A Role playing node"+ return "".join(+ f"<{child.node_id}>:<{child.description}>:<{self._get_node_info(child)}>\n"+ for child in self._children+ )++ def _get_node_info(self, node) -> str:+ r"""Get descriptive information for a specific node type."""+ if isinstance(node, Workforce):+ return "A Workforce node"+ elif isinstance(node, SingleAgentWorker):+ return self._get_single_agent_info(node)+ elif isinstance(node, RolePlayingWorker):+ return "A Role playing node"+ else:+ return "Unknown node"++ def _get_single_agent_info(self, worker: 'SingleAgentWorker') -> str:+ r"""Get formatted information for a SingleAgentWorker node."""+ toolkit_tools = self._group_tools_by_toolkit(worker.worker.tool_dict)++ if not toolkit_tools:+ return "no tools available"++ toolkit_info = []+ for toolkit_name, tools in sorted(toolkit_tools.items()):+ tools_str = ', '.join(sorted(tools))+ toolkit_info.append(f"{toolkit_name}({tools_str})")++ return " | ".join(toolkit_info)++ def _group_tools_by_toolkit(self, tool_dict: dict) -> dict[str, list[str]]:+ r"""Group tools by their parent toolkit class names."""+ toolkit_tools: dict[str, list[str]] = {}++ for tool_name, tool in tool_dict.items():+ if hasattr(tool.func, '__self__'):+ toolkit_name = tool.func.__self__.__class__.__name__else:- additional_info = "Unknown node"- info += (- f"<{child.node_id}>:<{child.description}>:<"- f"{additional_info}>\n"- )- return info+ toolkit_name = "Standalone"++ if toolkit_name not in toolkit_tools:+ toolkit_tools[toolkit_name] = []+ toolkit_tools[toolkit_name].append(tool_name)++ return toolkit_toolsdef _get_valid_worker_ids(self) -> set:r"""Get all valid worker IDs from child nodes.diff --git a/camel/toolkits/search_toolkit.py b/camel/toolkits/search_toolkit.pyindex 96e259cb7..7c58916e3 100644--- a/camel/toolkits/search_toolkit.py+++ b/camel/toolkits/search_toolkit.py@@ -434,23 +434,37 @@ class SearchToolkit(BaseToolkit):(None, 'SEARCH_ENGINE_ID'),])- def search_google(self, query: str) -> List[Dict[str, Any]]:+ def search_google(+ self, query: str, search_type: str = "web"+ ) -> List[Dict[str, Any]]:r"""Use Google search engine to search information for the given query.Args:query (str): The query to be searched.+ search_type (str): The type of search to perform. Either "web" for+ web pages or "image" for image search. (default: "web")Returns:List[Dict[str, Any]]: A list of dictionaries where each dictionary- represents a website.- Each dictionary contains the following keys:+ represents a search result.++ For web search, each dictionary contains:- 'result_id': A number in order.- 'title': The title of the website.- 'description': A brief description of the website.- 'long_description': More detail of the website.- 'url': The URL of the website.- Example:+ For image search, each dictionary contains:+ - 'result_id': A number in order.+ - 'title': The title of the image.+ - 'image_url': The URL of the image.+ - 'display_link': The website hosting the image.+ - 'context_url': The URL of the page containing the image.+ - 'width': Image width in pixels (if available).+ - 'height': Image height in pixels (if available).++ Example web result:{'result_id': 1,'title': 'OpenAI',@@ -462,7 +476,17 @@ class SearchToolkit(BaseToolkit):benefit humanity as a whole','url': 'https://www.openai.com'}- title, description, url of a website.++ Example image result:+ {+ 'result_id': 1,+ 'title': 'Beautiful Sunset',+ 'image_url': 'https://example.com/image.jpg',+ 'display_link': 'example.com',+ 'context_url': 'https://example.com/page.html',+ 'width': 800,+ 'height': 600+ }"""import requests@@ -477,12 +501,18 @@ class SearchToolkit(BaseToolkit):search_language = "en"# Constructing the URL# Doc: https://developers.google.com/custom-search/v1/using_rest- url = (+ base_url = (f"https://www.googleapis.com/customsearch/v1?"f"key={GOOGLE_API_KEY}&cx={SEARCH_ENGINE_ID}&q={query}&start="f"{start_page_idx}&lr={search_language}&num={self.number_of_result_pages}")+ # Add searchType parameter for image search+ if search_type == "image":+ url = base_url + "&searchType=image"+ else:+ url = base_url+responses = []# Fetch the results given the URLtry:@@ -494,37 +524,68 @@ class SearchToolkit(BaseToolkit):if "items" in data:search_items = data.get("items")- # Iterate over 10 results found+ # Iterate over results foundfor i, search_item in enumerate(search_items, start=1):- # Check metatags are present- if "pagemap" not in search_item:- continue- if "metatags" not in search_item["pagemap"]:- continue- if (- "og:description"- in search_item["pagemap"]["metatags"][0]- ):- long_description = search_item["pagemap"]["metatags"][- 0- ]["og:description"]+ if search_type == "image":+ # Process image search results+ title = search_item.get("title")+ image_url = search_item.get("link")+ display_link = search_item.get("displayLink")++ # Get context URL (page containing the image)+ image_info = search_item.get("image", {})+ context_url = image_info.get("contextLink", "")++ # Get image dimensions if available+ width = image_info.get("width")+ height = image_info.get("height")++ response = {+ "result_id": i,+ "title": title,+ "image_url": image_url,+ "display_link": display_link,+ "context_url": context_url,+ }++ # Add dimensions if available+ if width:+ response["width"] = int(width)+ if height:+ response["height"] = int(height)++ responses.append(response)else:- long_description = "N/A"- # Get the page title- title = search_item.get("title")- # Page snippet- snippet = search_item.get("snippet")-- # Extract the page url- link = search_item.get("link")- response = {- "result_id": i,- "title": title,- "description": snippet,- "long_description": long_description,- "url": link,- }- responses.append(response)+ # Process web search results (existing logic)+ # Check metatags are present+ if "pagemap" not in search_item:+ continue+ if "metatags" not in search_item["pagemap"]:+ continue+ if (+ "og:description"+ in search_item["pagemap"]["metatags"][0]+ ):+ long_description = search_item["pagemap"][+ "metatags"+ ][0]["og:description"]+ else:+ long_description = "N/A"+ # Get the page title+ title = search_item.get("title")+ # Page snippet+ snippet = search_item.get("snippet")++ # Extract the page url+ link = search_item.get("link")+ response = {+ "result_id": i,+ "title": title,+ "description": snippet,+ "long_description": long_description,+ "url": link,+ }+ responses.append(response)else:error_info = data.get("error", {})logger.error(diff --git a/docs/conf.py b/docs/conf.pyindex e52da3d35..bd1e9e154 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))project = 'CAMEL'copyright = '2024, CAMEL-AI.org'author = 'CAMEL-AI.org'-release = '0.2.71a12'+release = '0.2.71a13'html_favicon = ('https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'diff --git a/pyproject.toml b/pyproject.tomlindex 415c9fc20..2d8339ce9 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "camel-ai"-version = "0.2.71a12"+version = "0.2.71a13"description = "Communicative Agents for AI Society Study"authors = [{ name = "CAMEL-AI.org" }]requires-python = ">=3.10,<3.13"diff --git a/uv.lock b/uv.lockindex ad21517bc..f6ae37be5 100644--- a/uv.lock+++ b/uv.lock@@ -647,7 +647,7 @@ wheels = [[[package]]name = "camel-ai"-version = "0.2.71a12"+version = "0.2.71a13"source = { editable = "." }dependencies = [{ name = "colorama" },@@ -3784,7 +3784,7 @@ wheels = [[[package]]name = "litellm"-version = "1.74.2"+version = "1.74.3"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "aiohttp" },@@ -3799,9 +3799,9 @@ dependencies = [{ name = "tiktoken" },{ name = "tokenizers" },]-sdist = { url = "https://files.pythonhosted.org/packages/38/10/63cdae1b1d581ad1db51153dfd06c4e18394a3ba8de495f73f2d797ece3b/litellm-1.74.2.tar.gz", hash = "sha256:cbacffe93976c60ca674fec0a942c70b900b4ad1c8069395174049a162f255bf", size = 9230641, upload-time = "2025-07-11T03:31:07.925Z" }+sdist = { url = "https://files.pythonhosted.org/packages/cd/e3/3091066f6682016840e9a36111560656b609b95de04b2ec7b19ad2580eaa/litellm-1.74.3.tar.gz", hash = "sha256:a9e87ebe78947ceec67e75f830f1c956cc653b84563574241acea9c84e7e3ca1", size = 9256457, upload-time = "2025-07-12T20:06:06.128Z" }wheels = [- { url = "https://files.pythonhosted.org/packages/2a/f7/67689245f48b9e79bcd2f3a10a3690cb1918fb99fffd5a623ed2496bca66/litellm-1.74.2-py3-none-any.whl", hash = "sha256:29bb555b45128e4cc696e72921a6ec24e97b14e9b69e86eed6f155124ad629b1", size = 8587065, upload-time = "2025-07-11T03:31:05.598Z" },+ { url = "https://files.pythonhosted.org/packages/14/6f/07735b5178f32e28daf8a30ed6ad3e2c8c06ac374dc06aecde007110470f/litellm-1.74.3-py3-none-any.whl", hash = "sha256:638ec73633c6f2cf78a7343723d8f3bc13c192558fcbaa29f3ba6bc7802e8663", size = 8618899, upload-time = "2025-07-12T20:06:03.609Z" },][[package]]