You can also check this cookbook in colab here⭐ Star us on Github, join our Discord or follow our XGoal: Track and analysis the running of CAMEL Single Agent and Multiple Agents including LLMs and Tools usage
# Prompt for the OpenAI API key securelyopenai_api_key = getpass('Enter your API key: ')os.environ["OPENAI_API_KEY"] = openai_api_key
You can go to here to get free API Key from AgentOps
Copy
# Prompt for the AgentOps API key securelyagentops_api_key = getpass('Enter your API key:')os.environ["AGENTOPS_API_KEY"] = agentops_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.
Initialize AgentOps, you need to import toolkits after init of agentops so that the tool usage would be tracked.
Copy
AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY")agentops.init(AGENTOPS_API_KEY, default_tags=["CAMEL X AgentOps Single Agent with Tool Example"])from camel.toolkits import SearchToolkit
Set one Agent with Search Tools
Copy
# Define system messagesys_msg = BaseMessage.make_assistant_message( role_name='Tools calling opertor', content='You are a helpful assistant.')# Set model configtools = [*SearchToolkit().get_tools()]model = ModelFactory.create( model_platform=ModelPlatformType.OPENAI, model_type=ModelType.GPT_4O_MINI,)# Set agentcamel_agent = ChatAgent( system_message=sys_msg, model=model, tools=tools,)
Set user query and run the agent
Copy
# Define a user messageusr_msg = 'What is CAMEL-AI.org?'# Get response informationresponse = camel_agent.step(usr_msg)print(response)agentops.end_session("Success")
Initialize AgentOps, you need to import toolkits after init of agentops so that the tool usage would be tracked.
Copy
agentops.start_session(tags=["CAMEL X AgentOps Multi-agent with Tools."])from camel.toolkits import ( SearchToolkit, MathToolkit,)
Set your task prompt
Copy
task_prompt = ( "Assume now is 2024 in the Gregorian calendar, " "estimate the current age of University of Oxford " "and then add 10 more years to this age, " "and get the current weather of the city where " "the University is located.")
Set tools for the assistant agent, we wish the agent would be able to do mathmatic calculation and search information from websites
n = 0input_msg = role_play_session.init_chat()while n < 50: n += 1 assistant_response, user_response = role_play_session.step(input_msg) if assistant_response.terminated: print( Fore.GREEN + ( "AI Assistant terminated. Reason: " f"{assistant_response.info['termination_reasons']}." ) ) break if user_response.terminated: print( Fore.GREEN + ( "AI User terminated. " f"Reason: {user_response.info['termination_reasons']}." ) ) break # Print output from the user print_text_animated( Fore.BLUE + f"AI User:\n\n{user_response.msg.content}\n" ) # Print output from the assistant, including any function # execution information print_text_animated(Fore.GREEN + "AI Assistant:") tool_calls: List[FunctionCallingRecord] = assistant_response.info[ 'tool_calls' ] for func_record in tool_calls: print_text_animated(f"{func_record}") print_text_animated(f"{assistant_response.msg.content}\n") if "CAMEL_TASK_DONE" in user_response.msg.content: break input_msg = assistant_response.msg