fix: update lettaresponse type to be union
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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}.")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user