Interact with your agents via messages
Send messages to agents, receive responses, and manage conversation history via the API.
Sending messages
Section titled “Sending messages”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);# message a system message (non-user)response = client.send_message( agent_id=agent_state.id, role="system", message="[system] user has logged in. send a friendly message.")print("Usage", response.usage)print("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
Section titled “Message Types”LettaMessage
Section titled “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 agentfunction_call: An agent function callfunction_response: The response to an agent function callsystem_message: A system messageuser_message: A user message
Message
Section titled “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);response = client.user_message( agent_id=agent_state.id, message="hello!", include_full_message=True)You can convert a raw Message object to a list of LettaMessage objects:
// Convert a `Message` object to a `LettaMessage` objectconst lettaMessages = message.toLettaMessage();# Convert a `Message` object to a `LettaMessage` objectletta_messages = message.to_letta_message()