What is BaseMessage?
The
BaseMessage
class is the backbone for all message objects in
the CAMEL chat system. It offers a consistent structure for agent
communication and easy conversion between message types.Get Started
Creating a `BaseMessage`
To create a
BaseMessage
instance, supply these arguments:- role_name: Name of the user or assistant
- role_type:
RoleType.ASSISTANT
orRoleType.USER
- content: The actual message text
- meta_dict (optional): Additional metadata
- video_bytes (optional): Attach video bytes
- image_list (optional): List of PIL Image objects
- image_detail (optional): Level of image detail (default: “auto”)
- video_detail (optional): Level of video detail (default: “low”)
Convenient Constructors
Easily create messages for user or assistant agents:
Methods in the BaseMessage
Class
Flexible Message Manipulation
The
BaseMessage
class lets you:- Create a new instance with updated content:
new_message = message.create_new_instance(“new test content”)
- Convert to OpenAI message formats:
openai_message = message.to_openai_message(role_at_backend=OpenAIBackendRole.USER)
openai_system_message = message.to_openai_system_message()
openai_user_message = message.to_openai_user_message()
openai_assistant_message = message.to_openai_assistant_message()
- Convert to a Python dictionary:
message_dict = message.to_dict()
These methods allow you to transform a
BaseMessage
into the
right format for different LLM APIs and agent flows.Using BaseMessage
with ChatAgent
Rich Message Example
You can send multimodal messages (including images) to your agents:
The image features a logo for “CAMEL-AI.” It includes a stylized purple camel
graphic alongside the text “CAMEL-AI,” which is also in purple. The design
appears modern and is likely related to artificial intelligence.
Conclusion
Summary
The
BaseMessage
class is essential for structured, clear, and
flexible communication in the CAMEL-AI ecosystem—making it simple to create,
convert, and handle messages across any workflow.