Skip to content

Commit

Permalink
fix: create new request model that drops user_id (#2220)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker authored Dec 11, 2024
1 parent ac8bd80 commit c9c2cca
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion letta/server/rest_api/routers/v1/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
status,
)
from fastapi.responses import JSONResponse, StreamingResponse
from pydantic import Field

from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG
from letta.schemas.agent import AgentState, CreateAgent, UpdateAgentState
Expand Down Expand Up @@ -87,9 +88,18 @@ def get_agent_context_window(
return server.get_agent_context_window(user_id=actor.id, agent_id=agent_id)


class CreateAgentRequest(CreateAgent):
"""
CreateAgent model specifically for POST request body, excluding user_id which comes from headers
"""

# Override the user_id field to exclude it from the request body validation
user_id: Optional[str] = Field(None, exclude=True)


@router.post("/", response_model=AgentState, operation_id="create_agent")
def create_agent(
agent: CreateAgent = Body(...),
agent: CreateAgentRequest = Body(...),
server: "SyncServer" = Depends(get_letta_server),
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
):
Expand Down

0 comments on commit c9c2cca

Please sign in to comment.