🐫 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 human toolkit for human interaction with the agent (#1158) (#1200)
Xiaotian Jinabfa406582da
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.pyindex 451d94760..256bbf7e5 100644--- a/camel/toolkits/__init__.py+++ b/camel/toolkits/__init__.py@@ -38,6 +38,7 @@ from .twitter_toolkit import TwitterToolkitfrom .open_api_toolkit import OpenAPIToolkitfrom .retrieval_toolkit import RetrievalToolkitfrom .notion_toolkit import NotionToolkit+from .human_toolkit import HumanToolkit__all__ = ['BaseToolkit',@@ -64,4 +65,5 @@ __all__ = ['GoogleScholarToolkit','NotionToolkit','ArxivToolkit',+ 'HumanToolkit',]diff --git a/camel/toolkits/human_toolkit.py b/camel/toolkits/human_toolkit.pynew file mode 100644index 000000000..ba50f8c2c--- /dev/null+++ b/camel/toolkits/human_toolkit.py@@ -0,0 +1,48 @@+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========++from typing import List++from camel.toolkits.base import BaseToolkit+from camel.toolkits.function_tool import FunctionTool+++class HumanToolkit(BaseToolkit):+ r"""A class representing a toolkit for human interaction."""++ def __init__(self):+ pass++ def ask_human(self, question: str) -> str:+ r"""Ask a question to the human via the console.++ Args:+ question (str): The question to ask the human.++ Returns:+ str: The answer from the human.+ """+ print(f"\n{question}")+ print("Your reply: ", end="")+ return input()++ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing the+ functions in the toolkit.++ Returns:+ List[FunctionTool]: A list of FunctionTool objects+ representing the functions in the toolkit.+ """+ return [FunctionTool(self.ask_human)]diff --git a/examples/toolkits/human_toolkit.py b/examples/toolkits/human_toolkit.pynew file mode 100644index 000000000..1baa885bc--- /dev/null+++ b/examples/toolkits/human_toolkit.py@@ -0,0 +1,59 @@+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========+++from camel.agents import ChatAgent+from camel.configs import ChatGPTConfig+from camel.models import ModelFactory+from camel.toolkits import HumanToolkit+from camel.types import ModelPlatformType, ModelType++human_toolkit = HumanToolkit()++model = ModelFactory.create(+ model_platform=ModelPlatformType.OPENAI,+ model_type=ModelType.GPT_4O_MINI,+ model_config_dict=ChatGPTConfig(+ temperature=0.0,+ ).as_dict(),+)++# Test Agent with the human toolkit+agent = ChatAgent(+ system_message="You are a helpful assistant.",+ model=model,+ tools=[*human_toolkit.get_tools()],+)++response = agent.step(+ "Test me on the capital of some country, and comment on my answer."+)++print(response.msgs[0].content)++'''+What is the capital of France?+Your reply: Paris++That's correct! Paris is indeed the capital of France. Would you like to try+another one?+Your reply: yes++What is the capital of Japan?+Your reply: Tokyo++That's correct! Tokyo is the capital of Japan. Would you like to continue with+another question?+Your reply: no+'''