Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: patching openapi schema #2035

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions letta/schemas/letta_request.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import List, Union
from typing import List

from pydantic import BaseModel, Field

from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG
from letta.schemas.message import Message, MessageCreate
from letta.schemas.message import MessageCreate


class LettaRequest(BaseModel):
messages: Union[List[MessageCreate], List[Message]] = Field(..., description="The messages to be sent to the agent.")
messages: List[MessageCreate] = Field(..., description="The messages to be sent to the agent.")
run_async: bool = Field(default=False, description="Whether to asynchronously send the messages to the agent.") # TODO: implement

stream_steps: bool = Field(
Expand Down
16 changes: 15 additions & 1 deletion letta/schemas/letta_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from typing import List, Union

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, RootModel

from letta.schemas.enums import MessageStreamStatus
from letta.schemas.letta_message import LettaMessage, LettaMessageUnion
Expand All @@ -14,6 +14,20 @@
# TODO: consider moving into own file


class MessageListResponse(RootModel):
root: List[Message]

class Config:
title = "MessageListResponse" # Explicit title for Stainless


class LettaMessageListResponse(RootModel):
root: List[LettaMessageUnion]

class Config:
title = "LettaMessageListResponse" # Explicit title for Stainless


class LettaResponse(BaseModel):
"""
Response object from an agent interaction, consisting of the new messages generated by the agent and usage statistics.
Expand Down
28 changes: 19 additions & 9 deletions letta/server/rest_api/routers/v1/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG
from letta.schemas.agent import AgentState, CreateAgent, UpdateAgentState
from letta.schemas.enums import MessageStreamStatus
from letta.schemas.letta_message import (
LegacyLettaMessage,
LettaMessage,
LettaMessageUnion,
)
from letta.schemas.letta_message import LegacyLettaMessage, LettaMessage
from letta.schemas.letta_request import LettaRequest
from letta.schemas.letta_response import LettaResponse
from letta.schemas.letta_response import (
LettaMessageListResponse,
LettaResponse,
MessageListResponse,
)
from letta.schemas.memory import (
ArchivalMemorySummary,
BasicBlockMemory,
Expand Down Expand Up @@ -310,7 +310,11 @@ def delete_agent_archival_memory(
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": f"Memory id={memory_id} successfully deleted"})


@router.get("/{agent_id}/messages", response_model=Union[List[Message], List[LettaMessageUnion]], operation_id="list_agent_messages")
@router.get(
"/{agent_id}/messages",
response_model=Union[MessageListResponse, LettaMessageListResponse],
operation_id="list_agent_messages",
)
def get_agent_messages(
agent_id: str,
server: "SyncServer" = Depends(get_letta_server),
Expand Down Expand Up @@ -372,8 +376,14 @@ def update_message(
200: {
"description": "Successful response",
"content": {
"application/json": {"$ref": "#/components/schemas/LettaResponse"}, # Use model_json_schema() instead of model directly
"text/event-stream": {"description": "Server-Sent Events stream"},
"application/json": {
"schema": {
"$ref": "#/components/schemas/LettaResponse",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was missing a nesting layer w/ schema

},
},
"text/event-stream": {
"description": "Server-Sent Events stream",
},
},
}
},
Expand Down
Loading