Message Cookbook
You can also check this cookbook in colab here.
⭐ Star us on GitHub, join our Discord, or follow us on X
This notebook demonstrates how to set up and leverage CAMEL’s ability to use BaseMessage
class.
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.
-
BaseMessage: The base class for message objects used in the CAMEL chat system. It is designed to provide a consistent structure for the messages in the system and allow for easy conversion between different message types.
In this tutorial, we will explore the BaseMessage
class. The topics covered include:
- Introduction to the
BaseMessage
class. - Creating a
BaseMessage
instance. - Understanding the properties of the
BaseMessage
class. - Using the methods of the
BaseMessage
class. - Give message to
ChatAgent
📦 Installation
First, install the CAMEL package with all its dependencies:
🔑 Setting Up API Keys
You’ll need to set up your API keys for OpenAI. This ensures that the tools can interact with external services securely.
You can go to here to get free API Key from AgentOps
Your can go to here to get API Key from Mistral AI with free credits.
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.
Give message to ChatAgent
directly
You can simply pass text message to ChatAgent
Give message to ChatAgent
via BaseMessage
For more complex message usage like multi-modal message, we suggest using BaseMessage
Creating a BaseMessage
Instance
To create a BaseMessage
instance, you need to provide the following arguments:
role_name
: The name of the user or assistant role.role_type
: The type of role, eitherRoleType.ASSISTANT
orRoleType.USER
.content
: The content of the message.meta_dict
: An metadata dictionary for the message.
Below are optional arguments you can pass:
video_bytes
: Optional bytes of a video associated with the message.image_list
: Optional list of PIL Image objects associated with the message.image_detail
: Detail level of the images associated with the message. Default is “auto”.video_detail
: Detail level of the videos associated with the message. Default is “low”.
Here’s an example of creating a BaseMessage
instance:
Additionally, the BaseMessage class provides class methods to easily create user and assistant agent messages:
- Creating a user agent message:
- Creating an assistant agent message:
Using the Methods of the BaseMessage
Class
The BaseMessage
class offers several methods:
- Creating a new instance with updated content:
- Converting to an
OpenAIMessage
object:
- Converting to an
OpenAISystemMessage
object:
- Converting to an
OpenAIUserMessage
object:
- Converting to an
OpenAIAssistantMessage
object:
- Converting to a dictionary:
These methods allow you to convert a BaseMessage
instance into different message types depending on your needs.
Give BaseMessage
to ChatAgent
🌟 Highlights
This notebook has guided you through setting up and converting BaseMessage
to different types of messages. These components play essential roles in the CAMEL chat system, facilitating the creation, management, and interpretation of messages with clarity.
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.
- BaseMessage: The base class for message objects used in the CAMEL chat system. It is designed to provide a consistent structure for the messages in the system and allow for easy conversion between different message types.
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:
-
🐫 Creating Your First CAMEL Agent free Colab
-
Graph RAG Cookbook free Colab
-
🧑⚖️ Create A Hackathon Judge Committee with Workforce free Colab
-
🔥 3 ways to ingest data from websites with Firecrawl & CAMEL free Colab
-
🦥 Agentic SFT Data Generation with CAMEL and Mistral Models, Fine-Tuned with Unsloth free Colab
Thanks from everyone at 🐫 CAMEL-AI
⭐ Star us on GitHub, join our Discord, or follow us on X