Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: update list message response to not be a union (#783)

cthomasf27657ad3851
diff --git a/letta/client/client.py b/letta/client/client.py
index 30731d272..a2b62fa7c 100644
--- a/letta/client/client.py
+++ b/letta/client/client.py
@@ -280,7 +280,7 @@ class AbstractClient(object):
def get_messages(
self, agent_id: str, after: Optional[str] = None, before: Optional[str] = None, limit: Optional[int] = 1000
- ) -> List[Message]:
+ ) -> List[LettaMessage]:
raise NotImplementedError
def list_model_configs(self) -> List[LLMConfig]:
@@ -965,7 +965,7 @@ class RESTClient(AbstractClient):
def get_messages(
self, agent_id: str, before: Optional[str] = None, after: Optional[str] = None, limit: Optional[int] = 1000
- ) -> List[Message]:
+ ) -> List[LettaMessage]:
"""
Get messages from an agent with pagination.
@@ -983,7 +983,7 @@ class RESTClient(AbstractClient):
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/messages", params=params, headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get messages: {response.text}")
- return [Message(**message) for message in response.json()]
+ return [LettaMessage(**message) for message in response.json()]
def send_message(
self,
@@ -3355,7 +3355,7 @@ class LocalClient(AbstractClient):
def get_messages(
self, agent_id: str, before: Optional[str] = None, after: Optional[str] = None, limit: Optional[int] = 1000
- ) -> List[Message]:
+ ) -> List[LettaMessage]:
"""
Get messages from an agent with pagination.
@@ -3377,6 +3377,7 @@ class LocalClient(AbstractClient):
after=after,
limit=limit,
reverse=True,
+ return_message_object=False,
)
def list_blocks(self, label: Optional[str] = None, templates_only: Optional[bool] = True) -> List[Block]:
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index c940e1c93..91f1f191a 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -1,5 +1,5 @@
from datetime import datetime
-from typing import Annotated, List, Optional, Union
+from typing import Annotated, List, Optional
from fastapi import APIRouter, BackgroundTasks, Body, Depends, Header, HTTPException, Query, status
from fastapi.responses import JSONResponse
@@ -391,15 +391,7 @@ def delete_archival_memory(
AgentMessagesResponse = Annotated[
- Union[List[Message], List[LettaMessageUnion]],
- Field(
- json_schema_extra={
- "anyOf": [
- {"type": "array", "items": {"$ref": "#/components/schemas/Message"}},
- {"type": "array", "items": {"$ref": "#/components/schemas/LettaMessageUnion"}},
- ]
- }
- ),
+ List[LettaMessageUnion], Field(json_schema_extra={"type": "array", "items": {"$ref": "#/components/schemas/LettaMessageUnion"}})
]
@@ -410,7 +402,6 @@ def list_messages(
after: Optional[str] = Query(None, description="Message after which to retrieve the returned messages."),
before: Optional[str] = Query(None, description="Message before which to retrieve the returned messages."),
limit: int = Query(10, description="Maximum number of messages to retrieve."),
- msg_object: bool = Query(False, description="If true, returns Message objects. If false, return LettaMessage objects."),
config: LettaRequestConfig = Query(LettaRequestConfig(), description="Configuration options for the LettaRequest."),
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
):
@@ -426,7 +417,7 @@ def list_messages(
before=before,
limit=limit,
reverse=True,
- return_message_object=msg_object,
+ return_message_object=False,
assistant_message_tool_name=config.assistant_message_tool_name,
assistant_message_tool_kwarg=config.assistant_message_tool_kwarg,
)