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: add send_message_to_user method to human_toolkit for direct user messaging (#2087)

CaelumF43e50820cba3
diff --git a/camel/toolkits/human_toolkit.py b/camel/toolkits/human_toolkit.py
index 2c2a93e40..8c12d9968 100644
--- a/camel/toolkits/human_toolkit.py
+++ b/camel/toolkits/human_toolkit.py
@@ -39,6 +39,19 @@ class HumanToolkit(BaseToolkit):
logger.info(f"User reply: {reply}")
return reply
+ def send_message_to_user(self, message: str) -> None:
+ r"""Send a message to the user, without waiting for
+ a response. This will send to stdout in a noticeable way.
+
+ This is guaranteed to reach the user regardless of
+ actual user interface.
+
+ Args:
+ message (str): The message to send to the user.
+ """
+ print(f"\nAgent Message:\n{message}")
+ logger.info(f"\nAgent Message:\n{message}")
+
def get_tools(self) -> List[FunctionTool]:
r"""Returns a list of FunctionTool objects representing the
functions in the toolkit.
@@ -47,4 +60,7 @@ class HumanToolkit(BaseToolkit):
List[FunctionTool]: A list of FunctionTool objects
representing the functions in the toolkit.
"""
- return [FunctionTool(self.ask_human_via_console)]
+ return [
+ FunctionTool(self.ask_human_via_console),
+ FunctionTool(self.send_message_to_user),
+ ]
diff --git a/examples/toolkits/human_toolkit.py b/examples/toolkits/human_toolkit.py
index 020754d40..3d524ee70 100644
--- a/examples/toolkits/human_toolkit.py
+++ b/examples/toolkits/human_toolkit.py
@@ -29,7 +29,8 @@ model = ModelFactory.create(
).as_dict(),
)
-# Test Agent with the human toolkit
+# Example 1: Test Agent with the human toolkit (ask_human_via_console)
+print("\nExample 1: Using ask_human_via_console through an agent")
agent = ChatAgent(
system_message="You are a helpful assistant.",
model=model,
@@ -41,6 +42,7 @@ response = agent.step(
)
print(response.msgs[0].content)
+
"""
==========================================================================
What is the capital of France?
@@ -58,3 +60,28 @@ another question?
Your reply: no
==========================================================================
"""
+
+# Example 2: Agent using send_message_to_user through tools
+print("\nExample 2: Agent using send_message_to_user through tools")
+agent_with_message = ChatAgent(
+ system_message="You are an assistant that can send messages to the user.",
+ model=model,
+ tools=[*human_toolkit.get_tools()],
+)
+
+response = agent_with_message.step(
+ "Send me a notification about an upcoming meeting."
+)
+
+print(response.msgs[0].content)
+
+"""
+==========================================================================
+Agent Message:
+🔔 Reminder: You have an upcoming meeting scheduled. Please check your
+calendar for details!
+
+I've sent you a notification about your upcoming meeting. Please check your
+calendar for details!
+==========================================================================
+"""