⭐ Star us on GitHub, join our Discord, or follow us on XThis notebook demonstrates how to set up and leverage CAMEL’s ability to interact with user (for approval or comments) during the execution of the tasks.In this notebook, you’ll explore:
CAMEL: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.
HumanLayer: HumanLayer is an API and SDK that enables AI Agents to contact humans for feedback, input, and approvals.
Human-in-loop: The ability for agent to consult human during the execution of the task.
Human approval: The ability for agent ask approval to execute some tasks.
This cookbook demonstrates how to use HumanLayer functionality within CAMEL framework.
# Prompt for the API key securelyimport osfrom getpass import getpassqwen_api_key = getpass('Enter your API key: ')os.environ["QWEN_API_KEY"] = qwen_api_key
Your can go to here to get API Key from HumanLayer.
Copy
humanlayer_api_key = getpass('Enter your HumanLayer API key: ')os.environ["HUMANLAYER_API_KEY"] = humanlayer_api_key
Alternatively, if running on Colab, you could save your API keys and tokens as Colab Secrets, and use them across notebooks.To do so, comment out the above manual API key prompt code block(s), and uncomment the following codeblock.⚠️ Don’t forget granting access to the API key you would be using to the current notebook.
In this section, we’ll demonstrate how to define tools for Camel agent to use, and use HumanLayer to make some tools require human approval. First define two functions for agent to use, one of them requires human approval.
Copy
from humanlayer.core.approval import HumanLayerhl = HumanLayer(api_key=humanlayer_api_key, verbose=True)# add can be called without approvaldef add(x: int, y: int) -> int: """Add two numbers together.""" return x + y# but multiply must be approved by a human@hl.require_approval()def multiply(x: int, y: int) -> int: """multiply two numbers""" return x * y
Next we define the CAMEL agents, then run the computation commands. Here we will need to login HumanLayer cloud platform to approve for the agent to use the multiply function.
Copy
from camel.toolkits import FunctionToolfrom camel.agents import ChatAgentfrom camel.models import ModelFactoryfrom camel.types import ModelPlatformType, ModelTypemodel = ModelFactory.create( model_platform=ModelPlatformType.QWEN, model_type=ModelType.QWEN_QWQ_32B,)tools = [FunctionTool(add), FunctionTool(multiply)]agent_with_tools = ChatAgent( model = model, tools=tools)# Interact with the agentresponse = agent_with_tools.step("multiply 2 and 5, then add 32 to the result")print("\n\n----------Result----------\n\n")print(response.msgs[0].content)
Sometimes we want the agent to ask user during the working process, in this case, we can equip agent with human toolkits, and be able to ask human via console. This example demonstrates the human-in-loop function:
Copy
from camel.toolkits import HumanToolkithuman_toolkit = HumanToolkit()model = ModelFactory.create( model_platform=ModelPlatformType.QWEN, model_type=ModelType.QWEN_MAX,)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)
This notebook has guided you through setting up chat agents with the ability of Human-in-loop and Human approval.Key tools utilized in this notebook include:
CAMEL: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.
HumanLayer: HumanLayer is an API and SDK that enables AI Agents to contact humans for feedback, input, and approvals.
Human-in-loop: The ability for agent to consult human during the execution of the task.
Human approval: The ability for agent ask approval to execute some tasks.
That’s everything: Got questions about 🐫 CAMEL-AI? Join us on Discord! Whether you want to share feedback, explore the latest in multi-agent systems, get support, or connect with others on exciting projects, we’d love to have you in the community! 🤝Check out some of our other work: