Interact with your agents via messages

Sending messages

You can send message to agents from both the REST API and Python client:

1# message an agent as a user
2response = client.send_message(
3 agent_id=agent_state.id,
4 role="user",
5 message="hello"
6)
7print("Usage", response.usage)
8print("Agent messages", response.messages)

You can also send messages with different roles, such as system, assistant, or user:

1# message a system message (non-user)
2response = client.send_message(
3 agent_id=agent_state.id,
4 role="system",
5 message="[system] user has logged in. send a friendly message."
6)
7print("Usage", response.usage)
8print("Agent messages", response.messages)

The response object contains the following attributes:

  • usage: The usage of the agent after the message was sent (the prompt tokens, completition tokens, and total tokens)
  • message: A list of either Message or LettaMessage objects, generated by the agent

Message Types

LettaMessage

The LettaMessage object is a simplified version of the Message object. Since a Message can include multiple events like an inner monologue and function return, LettaMessage simplifies messages to have the following types:

  • inner_monologue: The inner monologue of the agent
  • function_call: An agent function call
  • function_response: The response to an agent function call
  • system_message: A system message
  • user_message: A user message

Message

The Message object is the raw MemGPT message representation that is persisted in the database. To have the full Message data returns, you can set include_full_message=True:

1response = client.user_message(
2 agent_id=agent_state.id,
3 message="hello!",
4 include_full_message=True
5)

You can convert a raw Message object to a list of LettaMessage objects:

1# Convert a `Message` object to a `LettaMessage` object
2letta_messages = message.to_letta_message()
Built with