From 1fdfb181ac4729a3c56c48be0ddf18075101a935 Mon Sep 17 00:00:00 2001 From: Caren Thomas Date: Thu, 26 Dec 2024 12:06:01 -0800 Subject: [PATCH 1/3] change delete agent return type to none --- letta/server/rest_api/routers/v1/agents.py | 5 +++-- letta/services/agent_manager.py | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index 6f78fbfa..79f35aff 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -170,7 +170,7 @@ def get_agent_state( raise HTTPException(status_code=404, detail=str(e)) -@router.delete("/{agent_id}", response_model=AgentState, operation_id="delete_agent") +@router.delete("/{agent_id}", response_model=None, operation_id="delete_agent") def delete_agent( agent_id: str, server: "SyncServer" = Depends(get_letta_server), @@ -181,7 +181,8 @@ def delete_agent( """ actor = server.user_manager.get_user_or_default(user_id=user_id) try: - return server.agent_manager.delete_agent(agent_id=agent_id, actor=actor) + server.agent_manager.delete_agent(agent_id=agent_id, actor=actor) + return JSONResponse(status_code=status.HTTP_200_OK) except NoResultFound: raise HTTPException(status_code=404, detail=f"Agent agent_id={agent_id} not found for user_id={actor.id}.") diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py index 4e6b80ec..26ce034a 100644 --- a/letta/services/agent_manager.py +++ b/letta/services/agent_manager.py @@ -279,7 +279,7 @@ class AgentManager: return agent.to_pydantic() @enforce_types - def delete_agent(self, agent_id: str, actor: PydanticUser) -> PydanticAgentState: + def delete_agent(self, agent_id: str, actor: PydanticUser) -> None: """ Deletes an agent and its associated relationships. Ensures proper permission checks and cascades where applicable. @@ -288,15 +288,14 @@ class AgentManager: agent_id: ID of the agent to be deleted. actor: User performing the action. - Returns: - PydanticAgentState: The deleted agent state + Raises: + NoResultFound: If agent doesn't exist """ with self.session_maker() as session: # Retrieve the agent agent = AgentModel.read(db_session=session, identifier=agent_id, actor=actor) agent_state = agent.to_pydantic() agent.hard_delete(session) - return agent_state # ====================================================================================================================== # In Context Messages Management From 7141e5909dca34eac2b93d7d9164ef85110a3977 Mon Sep 17 00:00:00 2001 From: Caren Thomas Date: Thu, 26 Dec 2024 14:22:10 -0800 Subject: [PATCH 2/3] remove lettaresponse spec hardcode and add references to pydantic --- letta/schemas/letta_response.py | 28 ++++++++++++++++++++++++++-- letta/server/rest_api/app.py | 3 --- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py index c6a1e8be..d12b2dc7 100644 --- a/letta/schemas/letta_response.py +++ b/letta/schemas/letta_response.py @@ -23,8 +23,32 @@ class LettaResponse(BaseModel): usage (LettaUsageStatistics): The usage statistics """ - messages: List[LettaMessageUnion] = Field(..., description="The messages returned by the agent.") - usage: LettaUsageStatistics = Field(..., description="The usage statistics of the agent.") + messages: List[LettaMessageUnion] = Field( + ..., + description="The messages returned by the agent.", + json_schema_extra={ + "items": { + "oneOf": [ + {"x-ref-name": "SystemMessage"}, + {"x-ref-name": "UserMessage"}, + {"x-ref-name": "ReasoningMessage"}, + {"x-ref-name": "ToolCallMessage"}, + {"x-ref-name": "ToolReturnMessage"}, + {"x-ref-name": "AssistantMessage"} + ], + "discriminator": { + "propertyName": "message_type" + } + } + } + ) + usage: LettaUsageStatistics = Field( + ..., + description="The usage statistics of the agent.", + json_schema_extra={ + "x-ref-name": "LettaUsageStatistics" + } + ) def __str__(self): return json_dumps( diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py index 8e2b7fb7..a8d31df4 100644 --- a/letta/server/rest_api/app.py +++ b/letta/server/rest_api/app.py @@ -68,9 +68,6 @@ def generate_openapi_schema(app: FastAPI): openai_docs["info"]["title"] = "OpenAI Assistants API" letta_docs["paths"] = {k: v for k, v in letta_docs["paths"].items() if not k.startswith("/openai")} letta_docs["info"]["title"] = "Letta API" - letta_docs["components"]["schemas"]["LettaResponse"] = { - "properties": LettaResponse.model_json_schema(ref_template="#/components/schemas/LettaResponse/properties/{model}")["$defs"] - } # Split the API docs into Letta API, and OpenAI Assistants compatible API for name, docs in [ From bc53881ad6234048568258bd54232dd8e1df3d5c Mon Sep 17 00:00:00 2001 From: Caren Thomas Date: Thu, 26 Dec 2024 20:09:19 -0800 Subject: [PATCH 3/3] rebase, run formatter --- letta/schemas/letta_response.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py index d12b2dc7..10a1b380 100644 --- a/letta/schemas/letta_response.py +++ b/letta/schemas/letta_response.py @@ -24,7 +24,7 @@ class LettaResponse(BaseModel): """ messages: List[LettaMessageUnion] = Field( - ..., + ..., description="The messages returned by the agent.", json_schema_extra={ "items": { @@ -34,20 +34,14 @@ class LettaResponse(BaseModel): {"x-ref-name": "ReasoningMessage"}, {"x-ref-name": "ToolCallMessage"}, {"x-ref-name": "ToolReturnMessage"}, - {"x-ref-name": "AssistantMessage"} + {"x-ref-name": "AssistantMessage"}, ], - "discriminator": { - "propertyName": "message_type" - } + "discriminator": {"propertyName": "message_type"}, } - } + }, ) usage: LettaUsageStatistics = Field( - ..., - description="The usage statistics of the agent.", - json_schema_extra={ - "x-ref-name": "LettaUsageStatistics" - } + ..., description="The usage statistics of the agent.", json_schema_extra={"x-ref-name": "LettaUsageStatistics"} ) def __str__(self):