feat: add stop reason object (#2783)
This commit is contained in:
@@ -17,6 +17,7 @@ from letta.schemas.enums import JobStatus
|
||||
from letta.schemas.file import FileMetadata
|
||||
from letta.schemas.job import Job
|
||||
from letta.schemas.letta_message import LettaMessage
|
||||
from letta.schemas.letta_stop_reason import LettaStopReason
|
||||
from letta.schemas.llm_config import LLMConfig
|
||||
from letta.schemas.memory import ArchivalMemorySummary, BasicBlockMemory, ChatMemory, Memory, RecallMemorySummary
|
||||
from letta.schemas.message import Message
|
||||
|
||||
44
letta/schemas/letta_stop_reason.py
Normal file
44
letta/schemas/letta_stop_reason.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from enum import Enum
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class StopReasonType(str, Enum):
|
||||
end_turn = "end_turn"
|
||||
error = "error"
|
||||
invalid_tool_call = "invalid_tool_call"
|
||||
max_steps = "max_steps"
|
||||
no_tool_call = "no_tool_call"
|
||||
|
||||
|
||||
class LettaStopReason(BaseModel):
|
||||
"""
|
||||
The stop reason from letta used during streaming response.
|
||||
"""
|
||||
|
||||
message_type: Literal["stop_reason"] = "stop_reason"
|
||||
stop_reason: StopReasonType = Field(..., description="The type of the message.")
|
||||
|
||||
|
||||
def create_letta_stop_reason_schema():
|
||||
return {
|
||||
"properties": {
|
||||
"message_type": {
|
||||
"type": "string",
|
||||
"const": "stop_reason",
|
||||
"title": "Message Type",
|
||||
"description": "The type of the message.",
|
||||
"default": "stop_reason",
|
||||
},
|
||||
"stop_reason": {
|
||||
"type": "string",
|
||||
"enum": list(StopReasonType.__members__.keys()),
|
||||
"title": "Stop Reason",
|
||||
},
|
||||
},
|
||||
"type": "object",
|
||||
"required": ["stop_reason"],
|
||||
"title": "LettaStopReason",
|
||||
"description": "Letta provided stop reason for why agent loop ended.",
|
||||
}
|
||||
@@ -24,6 +24,7 @@ from letta.schemas.letta_message_content import (
|
||||
create_letta_message_content_union_schema,
|
||||
create_letta_user_message_content_union_schema,
|
||||
)
|
||||
from letta.schemas.letta_stop_reason import create_letta_stop_reason_schema
|
||||
from letta.server.constants import REST_DEFAULT_PORT
|
||||
|
||||
# NOTE(charles): these are extra routes that are not part of v1 but we still need to mount to pass tests
|
||||
@@ -68,6 +69,7 @@ def generate_openapi_schema(app: FastAPI):
|
||||
letta_docs["components"]["schemas"]["LettaMessageContentUnion"] = create_letta_message_content_union_schema()
|
||||
letta_docs["components"]["schemas"]["LettaAssistantMessageContentUnion"] = create_letta_assistant_message_content_union_schema()
|
||||
letta_docs["components"]["schemas"]["LettaUserMessageContentUnion"] = create_letta_user_message_content_union_schema()
|
||||
letta_docs["components"]["schemas"]["LettaStopReason"] = create_letta_stop_reason_schema()
|
||||
|
||||
# Update the app's schema with our modified version
|
||||
app.openapi_schema = letta_docs
|
||||
|
||||
Reference in New Issue
Block a user