Message

class Message(BaseMessage)

Letta’s internal representation of a message. Includes methods to convert to/from LLM provider formats.

Attributes:

  • id str - The unique identifier of the message.
  • role MessageRole - The role of the participant.
  • text str - The text of the message.
  • user_id str - The unique identifier of the user.
  • agent_id str - The unique identifier of the agent.
  • model str - The model used to make the function call.
  • name str - The name of the participant.
  • created_at datetime - The time the message was created.
  • tool_calls List[ToolCall] - The list of tool calls requested.
  • tool_call_id str - The id of the tool call.

to_letta_message

def to_letta_message() -> List[LettaMessage]

Convert message object (in DB format) to the style used by the original Letta API

dict_to_message

@staticmethod
def dict_to_message(user_id: str,
                    agent_id: str,
                    openai_message_dict: dict,
                    model: Optional[str] = None,
                    allow_functions_style: bool = False,
                    created_at: Optional[datetime] = None,
                    id: Optional[str] = None)

Convert a ChatCompletion message object into a Message object (synced to DB)

to_openai_dict

def to_openai_dict(max_tool_id_length: int = TOOL_CALL_ID_MAX_LEN,
                   put_inner_thoughts_in_kwargs: bool = False) -> dict

Go from Message class to ChatCompletion message object

to_anthropic_dict

def to_anthropic_dict(inner_thoughts_xml_tag="thinking") -> dict

Convert to an Anthropic message dictionary

Arguments:

  • inner_thoughts_xml_tag str - The XML tag to wrap around inner thoughts

to_google_ai_dict

def to_google_ai_dict(put_inner_thoughts_in_kwargs: bool = True) -> dict

Go from Message class to Google AI REST message object

to_cohere_dict

def to_cohere_dict(
        function_call_role: Optional[str] = "SYSTEM",
        function_call_prefix: Optional[str] = "[CHATBOT called function]",
        function_response_role: Optional[str] = "SYSTEM",
        function_response_prefix: Optional[
            str] = "[CHATBOT function returned]",
        inner_thoughts_as_kwarg: Optional[bool] = False) -> List[dict]

Cohere chat_history dicts only have ‘role’ and ‘message’ fields