diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py index c6a1e8be..10a1b380 100644 --- a/letta/schemas/letta_response.py +++ b/letta/schemas/letta_response.py @@ -23,8 +23,26 @@ 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 [ 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