Repository: cpacker/MemGPT
File: letta/schemas/letta_message.py (Python)

Code before:
        date (datetime): The date the message was created in ISO format
    """

    message_type: Literal["user_message"] = "user_message"
    message: str


class InternalMonologue(LettaMessage):
    """
    Representation of an agent's internal monologue.

    Attributes:
        internal_monologue (str): The internal monologue of the agent
        id (str): The ID of the message
        date (datetime): The date the message was created in ISO format
    """

    message_type: Literal["internal_monologue"] = "internal_monologue"
    internal_monologue: str


class FunctionCall(BaseModel):

    name: str
    arguments: str


class FunctionCallDelta(BaseModel):

    name: Optional[str]
    arguments: Optional[str]

    # NOTE: this is a workaround to exclude None values from the JSON dump,
    # since the OpenAI style of returning chunks doesn't include keys with null values
    def model_dump(self, *args, **kwargs):
        kwargs["exclude_none"] = True
        return super().model_dump(*args, **kwargs)

    def json(self, *args, **kwargs):
        return json.dumps(self.model_dump(exclude_none=True), *args, **kwargs)


class FunctionCallMessage(LettaMessage):
    """
    A message representing a request to call a function (generated by the LLM to trigger function execution).

    Attributes:
        function_call (Union[FunctionCall, FunctionCallDelta]): The function call
        id (str): The ID of the message
        date (datetime): The date the message was created in ISO format
    """

Review comment (suggestion):
note to @sarahwooders @4shub we have new (required) field here for the pydantic model `LettaMessage.FunctionCallMessage`

Code after:
        date (datetime): The date the message was created in ISO format
    """

    message_type: Literal["user_message"] = "user_message"
    message: str


class InternalMonologue(LettaMessage):
    """
    Representation of an agent's internal monologue.

    Attributes:
        internal_monologue (str): The internal monologue of the agent
        id (str): The ID of the message
        date (datetime): The date the message was created in ISO format
    """

    message_type: Literal["internal_monologue"] = "internal_monologue"
    internal_monologue: str


class FunctionCall(BaseModel):

    name: str
    arguments: str
    function_call_id: str


class FunctionCallDelta(BaseModel):

    name: Optional[str]
    arguments: Optional[str]
    function_call_id: Optional[str]

    # NOTE: this is a workaround to exclude None values from the JSON dump,
    # since the OpenAI style of returning chunks doesn't include keys with null values
    def model_dump(self, *args, **kwargs):
        kwargs["exclude_none"] = True
        return super().model_dump(*args, **kwargs)

    def json(self, *args, **kwargs):
        return json.dumps(self.model_dump(exclude_none=True), *args, **kwargs)


class FunctionCallMessage(LettaMessage):
    """
    A message representing a request to call a function (generated by the LLM to trigger function execution).

    Attributes:
        function_call (Union[FunctionCall, FunctionCallDelta]): The function call
        id (str): The ID of the message