Skip to content
Sign up

Interact with your agents via messages

Send messages to agents, receive responses, and manage conversation history via the API.

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

client.sendMessage( agent_state.id, "user", "hello" ); console.log("Usage",
response.usage); console.log("Agent messages", response.messages); ```

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

const response = await client.sendMessage(
agent_state.id,
"system",
"[system] user has logged in. send a friendly message.",
);
console.log("Usage", response.usage);
console.log("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

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

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:

const response = await client.userMessage(
agent_state.id,
"hello!",
true, // include_full_message
);

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

// Convert a `Message` object to a `LettaMessage` object
const lettaMessages = message.toLettaMessage();