Using Tools from Composio#
You can also check this cookbook in colab here
Goal: Star a repository on GitHub with natural language & CAMEL Agent
Install Packages & Connect a Tool#
Integrate Composio with CAMEL agents to let them seamlessly interact with external apps
Ensure you have the necessary packages installed and connect your GitHub account to allow your CAMEL-AI agents to utilize GitHub functionalities.
[ ]:
%pip install "camel-ai[all]==0.1.6.5"
%pip install "composio-camel -U"
import composio
[ ]:
# Login to Composio
!composio login
[ ]:
# Connect your Github account (this is a shell command, so it should be run in your terminal or with '!' prefix in a Jupyter Notebook)
!composio add github
# Check all different apps which you can connect with
!composio apps
Warning: An existing connection for github was found.
> Do you want to replace the existing connection? (y, n): y
> Adding integration: Github...
Please authenticate github in the browser and come back here. URL: https://github.com/login/oauth/authorize?client_id=37beeaa7020925b04e40&redirect_uri=https%3A%2F%2Fbackend.composio.dev%2Fapi%2Fv1%2Fauth-apps%2Fadd&scope=repo%2Cadmin%3Aorg%2Cgist%2Cuser&state=production_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25uZWN0aW9uSWQiOiIwMWIyMTlmOC1kZTk5LTQ5ZWMtOTMwOS1mMzg3ZWFhMzRmNTgiLCJpbnRlZ3JhdGlvbklkIjoiMjdmNzM0YzAtZTIyMS00OTI1LTgxMjAtN2I1ZDNlYjAxOTA5IiwiYXBwTmFtZSI6ImdpdGh1YiIsImNsaWVudEluZm8iOnsiY2xpZW50SWQiOiJjZmE4NWM0ZC1jMWI0LTRjNmQtODE4Ni1kNmNiNmRmYmZlM2UifSwiaWF0IjoxNzIyMjE0NzUwfQ.w9QHilHJcHk8eIQa7vFCrGskC-VRFzgJIu1dQf4e7Jk&code_challenge=FnINCywVMtW7jH3DOGw6ddbmTf5vAJw5NvpojJkB2hs&code_challenge_method=S256
⚠ Waiting for github authentication...
✔ github added successfully!
Showing all apps
• multionai
• typeform
• dropbox
• slack
• yousearch
• hackernews
• scheduler
• apify
• googlecalendar
• gmail
• slackbot
• attio
• composio
• okta
• spotify
• pagerduty
• whatsapp
• nasa
• googledrive
• googlesheets
• googlemeet
• inducedai
• twilio
• codeinterpreter
• tavily
• serpapi
• snowflake
• exa
• zoom
• listennotes
• elevenlabs
• brevo
• weathermap
• discord
• soundcloud
• perplexityai
• splitwise
• googledocs
• firecrawl
• strava
• youtube
• heroku
• workable
• taskade
• googletasks
• figma
• clickup
• linear
• asana
• trello
• notion
• zendesk
• github
[ ]:
# Update Composio apps
! composio apps update
⚠️ Apps does not require update
⚠️ Tags does not require update
⚠️ Actions does not require update
⚠️ Triggers does not require update
Prepare your environment by initializing necessary imports from CAMEL & Composio.#
[ ]:
from typing import List
from colorama import Fore
from composio_camel import Action, ComposioToolSet
from camel.agents.chat_agent import FunctionCallingRecord
from camel.configs import ChatGPTConfig
from camel.models import ModelFactory
from camel.societies import RolePlaying
from camel.types import ModelPlatformType, ModelType
from camel.utils import print_text_animated
import os
from getpass import getpass
# Prompt for the API key securely
openai_api_key = getpass('Enter your API key: ')
os.environ["OPENAI_API_KEY"] = openai_api_key
Enter your API key: ··········
Let’s run CAMEL agents with tools from Composio!#
[ ]:
# Set your task
task_prompt = (
"I have created a new Github Repo,"
"Please star my github repository: camel-ai/camel"
)
[ ]:
# Set Toolset
composio_toolset = ComposioToolSet()
tools = composio_toolset.get_actions(
actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]
)
[ ]:
# Set models for user agent and assistant agent, give tool to the assistant
assistant_agent_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
model_config_dict=ChatGPTConfig(tools=tools).as_dict(),
)
user_agent_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
model_config_dict=ChatGPTConfig().as_dict(),
)
[ ]:
# Set RolePlaying session
role_play_session = RolePlaying(
assistant_role_name="Developer",
user_role_name="CAMEL User",
assistant_agent_kwargs=dict(
model=assistant_agent_model,
tools=tools,
),
user_agent_kwargs=dict(
model=user_agent_model,
),
task_prompt=task_prompt,
with_task_specify=False,
)
[ ]:
# Print the system message and task prompt
print(
Fore.GREEN
+ f"AI Assistant sys message:\n{role_play_session.assistant_sys_msg}\n"
)
print(Fore.BLUE + f"AI User sys message:\n{role_play_session.user_sys_msg}\n")
print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n")
print(
Fore.CYAN
+ "Specified task prompt:"
+ f"\n{role_play_session.specified_task_prompt}\n"
)
print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n")
AI Assistant sys message:
BaseMessage(role_name='Developer', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'I have created a new Github Repo,Please star my github repository: camel-ai/camel', 'assistant_role': 'Developer', 'user_role': 'CAMEL User'}, content='===== RULES OF ASSISTANT =====\nNever forget you are a Developer and I am a CAMEL User. Never flip roles! Never instruct me!\nWe share a common interest in collaborating to successfully complete a task.\nYou must help me to complete the task.\nHere is the task: I have created a new Github Repo,Please star my github repository: camel-ai/camel. Never forget our task!\nI must instruct you based on your expertise and my needs to complete the task.\n\nI must give you one instruction at a time.\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\nUnless I say the task is completed, you should always start with:\n\nSolution: <YOUR_SOLUTION>\n\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')
AI User sys message:
BaseMessage(role_name='CAMEL User', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'I have created a new Github Repo,Please star my github repository: camel-ai/camel', 'assistant_role': 'Developer', 'user_role': 'CAMEL User'}, content='===== RULES OF USER =====\nNever forget you are a CAMEL User and I am a Developer. Never flip roles! You will always instruct me.\nWe share a common interest in collaborating to successfully complete a task.\nI must help you to complete the task.\nHere is the task: I have created a new Github Repo,Please star my github repository: camel-ai/camel. Never forget our task!\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\n\n1. Instruct with a necessary input:\nInstruction: <YOUR_INSTRUCTION>\nInput: <YOUR_INPUT>\n\n2. Instruct without any input:\nInstruction: <YOUR_INSTRUCTION>\nInput: None\n\nThe "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".\n\nYou must give me one instruction at a time.\nI must write a response that appropriately solves the requested instruction.\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\nYou should instruct me not ask me questions.\nNow you must start to instruct me using the two ways described above.\nDo not add anything else other than your instruction and the optional corresponding input!\nKeep giving me instructions and necessary inputs until you think the task is completed.\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')
Original task prompt:
I have created a new Github Repo,Please star my github repository: camel-ai/camel
Specified task prompt:
None
Final task prompt:
I have created a new Github Repo,Please star my github repository: camel-ai/camel
[ ]:
# Set terminate rule and print the chat message
n = 0
input_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
AI User:
Instruction: Visit the Github repository I created.
Input: None
AI Assistant:
Solution: To visit the Github repository you created, you can simply open a web browser and go to the following URL: https://github.com/camel-ai/camel
Next request.
AI User:
Instruction: Click on the "Star" button on the Github repository page.
Input: None
AI Assistant:
Function Execution: github_activity_star_repo_for_authenticated_user
Args: {'owner': 'camel-ai', 'repo': 'camel'}
Result: {'execution_details': {'executed': True}, 'response_data': ''}
Solution: I have successfully starred your Github repository "camel-ai/camel".
Next request.
AI User:
<CAMEL_TASK_DONE>
AI Assistant:
Great! The task is completed. If you have any more tasks or need further assistance in the future, feel free to ask. Have a wonderful day!