feat: add message_types filter to list messages endpoint (#8280)
* feat: add message_types filter to list messages endpoint
Add the ability to filter messages by type when listing message history
via GET /v1/agents/{agent_id}/messages. This brings parity with the
create message endpoint which already supports include_return_message_types.
Changes:
- Add message_types query parameter to list_messages endpoint in agents.py
- Add message_types parameter to get_agent_recall_async in server.py
- Filter messages by message_type after LettaMessage conversion
- Add test for message_types filtering
Closes #8277
Written by Cameron ◯ Letta Code
> "Simplicity is the ultimate sophistication." - Leonardo da Vinci
🐙 Generated with [Letta Code](https://letta.com)
Co-Authored-By: Letta <noreply@letta.com>
* chore: regenerate OpenAPI spec and SDK for message_types filter
🐧 Generated with [Letta Code](https://letta.com)
Co-Authored-By: Letta <noreply@letta.com>
Written by Cameron ◯ Letta Code
"The only way to do great work is to love what you do." - Steve Jobs
---------
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -817,6 +817,7 @@ class SyncServer(object):
|
||||
assistant_message_tool_name: str = constants.DEFAULT_MESSAGE_TOOL,
|
||||
assistant_message_tool_kwarg: str = constants.DEFAULT_MESSAGE_TOOL_KWARG,
|
||||
include_err: Optional[bool] = None,
|
||||
message_types: Optional[List[MessageType]] = None,
|
||||
) -> Union[List[Message], List[LettaMessage]]:
|
||||
records = await self.message_manager.list_messages(
|
||||
agent_id=agent_id,
|
||||
@@ -844,6 +845,11 @@ class SyncServer(object):
|
||||
text_is_assistant_message=text_is_assistant_message,
|
||||
)
|
||||
|
||||
# Filter by message_types if specified
|
||||
if message_types:
|
||||
message_types_set = set(message_types)
|
||||
records = [msg for msg in records if msg.message_type in message_types_set]
|
||||
|
||||
if reverse:
|
||||
records = records[::-1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user