Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat:origene toolkit (#2763)

Yifeng Wang(正经人王同学)1931ad972e80
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.py
index cce3ef51c..65ba1f74f 100644
--- a/camel/toolkits/__init__.py
+++ b/camel/toolkits/__init__.py
@@ -74,6 +74,7 @@ from .jina_reranker_toolkit import JinaRerankerToolkit
from .pulse_mcp_search_toolkit import PulseMCPSearchToolkit
from .klavis_toolkit import KlavisToolkit
from .aci_toolkit import ACIToolkit
+from .origene_mcp_toolkit import OrigeneToolkit
from .playwright_mcp_toolkit import PlaywrightMCPToolkit
from .wolfram_alpha_toolkit import WolframAlphaToolkit
from .task_planning_toolkit import TaskPlanningToolkit
@@ -141,6 +142,7 @@ __all__ = [
'OpenAIAgentToolkit',
'SearxNGToolkit',
'JinaRerankerToolkit',
+ 'OrigeneToolkit',
'PulseMCPSearchToolkit',
'KlavisToolkit',
'ACIToolkit',
diff --git a/camel/toolkits/origene_mcp_toolkit.py b/camel/toolkits/origene_mcp_toolkit.py
new file mode 100644
index 000000000..67d0db1aa
--- /dev/null
+++ b/camel/toolkits/origene_mcp_toolkit.py
@@ -0,0 +1,95 @@
+# ========= 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, MCPToolkit
+
+
+class OrigeneToolkit(BaseToolkit):
+ r"""OrigeneToolkit provides an interface for interacting with
+ Origene MCP server.
+
+ This toolkit can be used as an async context manager for automatic
+ connection management:
+
+ async with OrigeneToolkit() as toolkit:
+ tools = toolkit.get_tools()
+ # Toolkit is automatically disconnected when exiting
+
+ Attributes:
+ timeout (Optional[float]): Connection timeout in seconds.
+ (default: :obj:`None`)
+ """
+
+ def __init__(
+ self,
+ timeout: Optional[float] = None,
+ ) -> None:
+ r"""Initializes the OrigeneToolkit.
+
+ Args:
+ timeout (Optional[float]): Connection timeout in seconds.
+ (default: :obj:`None`)
+ """
+ super().__init__(timeout=timeout)
+
+ self._mcp_toolkit = MCPToolkit(
+ config_dict={
+ "mcpServers": {
+ "pubchem_mcp": {
+ "url": "http://127.0.0.1:8791/mcp/",
+ "mode": "streamable-http",
+ }
+ }
+ },
+ timeout=timeout,
+ )
+
+ async def connect(self):
+ r"""Explicitly connect to the Origene MCP server."""
+ await self._mcp_toolkit.connect()
+
+ async def disconnect(self):
+ r"""Explicitly disconnect from the Origene MCP server."""
+ await self._mcp_toolkit.disconnect()
+
+ async def __aenter__(self) -> "OrigeneToolkit":
+ r"""Async context manager entry point.
+
+ Returns:
+ OrigeneToolkit: The connected toolkit instance.
+
+ Example:
+ async with OrigeneToolkit() as toolkit:
+ tools = toolkit.get_tools()
+ """
+ await self.connect()
+ return self
+
+ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
+ r"""Async context manager exit point.
+
+ Automatically disconnects from the Origene MCP server.
+ """
+ await self.disconnect()
+ return None
+
+ def get_tools(self) -> List[FunctionTool]:
+ r"""Returns a list of tools provided by the Origene MCP server.
+
+ Returns:
+ List[FunctionTool]: List of available tools.
+ """
+ return self._mcp_toolkit.get_tools()
diff --git a/examples/toolkits/mcp/mcp_origene_toolkit/client.py b/examples/toolkits/mcp/mcp_origene_toolkit/client.py
new file mode 100644
index 000000000..d4843791a
--- /dev/null
+++ b/examples/toolkits/mcp/mcp_origene_toolkit/client.py
@@ -0,0 +1,70 @@
+# ========= 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.toolkits import OrigeneToolkit
+
+
+async def main():
+ # Use async context manager for automatic connection management
+ async with OrigeneToolkit() as origene_toolkit:
+ user_msg = "what can you do?"
+ agent = ChatAgent(
+ "You are named origene assistant.",
+ model="gpt-4o",
+ tools=[*origene_toolkit.get_tools()],
+ )
+ response = agent.step(user_msg)
+ print(response.msgs[0].content)
+ # Toolkit is automatically disconnected when exiting the context
+
+
+'''
+===============================================================================
+I can assist you with a variety of tasks related to chemical compounds
+and substances using the PubChem database.
+Here are some of the things I can do:
+
+1. **Search for Compounds and Substances**:
+ - Search by chemical name, SMILES string, or molecular formula.
+ - Perform advanced searches using complex queries.
+
+2. **Retrieve Detailed Information**:
+ - Get detailed compound and substance information by PubChem CID or SID.
+ - Retrieve compound properties like molecular weight, formula, XLogP, etc.
+ - Get descriptions and related data for compounds, substances, and assays.
+
+3. **Synonyms and Identifiers**:
+ - Find synonyms for compounds and substances.
+ - Get CAS Registry Numbers, CIDs, and SIDs.
+
+4. **3D Structure and Conformers**:
+ - Access 3D structures and conformer identifiers.
+
+5. **Bioassay Activities**:
+ - Summarize bioassay activities for compounds and substances.
+
+6. **Download Data**:
+ - Download images of chemical structures in PNG format.
+ - Export compound properties to a CSV file.
+
+If you have any specific requests or need information on a particular compound,
+feel free to ask!
+===============================================================================
+'''
+
+if __name__ == "__main__":
+ asyncio.run(main())