Files
letta-server/fern/pages/agents/messages.mdx
2025-09-09 09:35:12 -07:00

59 lines
2.0 KiB
Plaintext

---
title: Interact with your agents via messages
slug: guides/agents/messages
---
## Sending messages
You can send message to agents from both the REST API and Python client:
```python
# message an agent as a user
response = client.send_message(
agent_id=agent_state.id,
role="user",
message="hello"
)
print("Usage", response.usage)
print("Agent messages", response.messages)
```
You can also send messages with different roles, such as `system`, `assistant`, or `user`:
```python
# 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
#### `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`:
```python
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:
```python
# Convert a `Message` object to a `LettaMessage` object
letta_messages = message.to_letta_message()
```