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.BaseMessage
instance, supply these arguments:RoleType.ASSISTANT
or RoleType.USER
from camel.messages import BaseMessage
from camel.types import RoleType
message = BaseMessage(
role_name="test_user",
role_type=RoleType.USER,
content="test content"
)
user_message = BaseMessage.make_user_message(
role_name="user_name",
content="test content for user",
)
assistant_message = BaseMessage.make_assistant_message(
role_name="assistant_name",
content="test content for assistant",
)
BaseMessage
ClassBaseMessage
class lets you:new_message = message.create_new_instance(“new test content”)
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()
message_dict = message.to_dict()
BaseMessage
into the
right format for different LLM APIs and agent flows.BaseMessage
with ChatAgent
from io import BytesIO
import requests
from PIL import Image
from camel.agents import ChatAgent
from camel.messages import BaseMessage
# Download an image
url = "https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png"
img = Image.open(BytesIO(requests.get(url).content))
# Build system and user messages
sys_msg = BaseMessage.make_assistant_message(
role_name="Assistant",
content="You are a helpful assistant.",
)
user_msg = BaseMessage.make_user_message(
role_name="User", content="what's in the image?", image_list=[img]
)
# Create agent and send message
camel_agent = ChatAgent(system_message=sys_msg)
response = camel_agent.step(user_msg)
print(response.msgs[0].content)
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.