Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: modify REST API schemas (#2121)
Sarah Woodersfae2d06755cc
diff --git a/letta/schemas/agent.py b/letta/schemas/agent.pyindex d15dc6b3d..f0372f8fa 100644--- a/letta/schemas/agent.py+++ b/letta/schemas/agent.py@@ -4,6 +4,7 @@ from typing import Dict, List, Optionalfrom pydantic import BaseModel, Field, field_validator+from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLSfrom letta.schemas.block import CreateBlockfrom letta.schemas.embedding_config import EmbeddingConfigfrom letta.schemas.letta_base import LettaBase@@ -108,7 +109,7 @@ class CreateAgent(BaseAgent): ## all optional as server can generate defaultsname: Optional[str] = Field(None, description="The name of the agent.")message_ids: Optional[List[str]] = Field(None, description="The ids of the messages in the agent's in-context memory.")-+# memory creationmemory_blocks: List[CreateBlock] = Field(# [CreateHuman(), CreatePersona()], description="The blocks to create in the agent's in-context memory."@@ -116,11 +117,11 @@ class CreateAgent(BaseAgent): #description="The blocks to create in the agent's in-context memory.",)- tools: Optional[List[str]] = Field(None, description="The tools used by the agent.")+ tools: List[str] = Field(BASE_TOOLS + BASE_MEMORY_TOOLS, description="The tools used by the agent.")tool_rules: Optional[List[ToolRule]] = Field(None, description="The tool rules governing the agent.")tags: Optional[List[str]] = Field(None, description="The tags associated with the agent.")system: Optional[str] = Field(None, description="The system prompt used by the agent.")- agent_type: Optional[AgentType] = Field(None, description="The type of agent.")+ agent_type: AgentType = Field(AgentType.memgpt_agent, description="The type of agent.")llm_config: Optional[LLMConfig] = Field(None, description="The LLM configuration used by the agent.")embedding_config: Optional[EmbeddingConfig] = Field(None, description="The embedding configuration used by the agent.")# Note: if this is None, then we'll populate with the standard "more human than human" initial message sequencediff --git a/letta/schemas/letta_request.py b/letta/schemas/letta_request.pyindex 11ef8bad4..123d817cf 100644--- a/letta/schemas/letta_request.py+++ b/letta/schemas/letta_request.py@@ -1,13 +1,13 @@-from typing import List, Union+from typing import Listfrom pydantic import BaseModel, Fieldfrom letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG-from letta.schemas.message import Message, MessageCreate+from letta.schemas.message import MessageCreateclass LettaRequest(BaseModel):- messages: Union[List[MessageCreate], List[Message]] = Field(..., description="The messages to be sent to the agent.")+ messages: List[MessageCreate] = Field(..., description="The messages to be sent to the agent.")# Flags to support the use of AssistantMessage message typesdiff --git a/letta/schemas/tool_rule.py b/letta/schemas/tool_rule.pyindex 42f460e46..b320917d2 100644--- a/letta/schemas/tool_rule.py+++ b/letta/schemas/tool_rule.py@@ -17,7 +17,6 @@ class ChildToolRule(BaseToolRule):A ToolRule represents a tool that can be invoked by the agent."""- # type: str = Field("ToolRule")type: ToolRuleType = ToolRuleType.constrain_child_toolschildren: List[str] = Field(..., description="The children tools that can be invoked.")@@ -27,7 +26,6 @@ class InitToolRule(BaseToolRule):Represents the initial tool rule configuration."""- # type: str = Field("InitToolRule")type: ToolRuleType = ToolRuleType.run_first@@ -36,7 +34,6 @@ class TerminalToolRule(BaseToolRule):Represents a terminal tool rule configuration where if this tool gets called, it must end the agent loop."""- # type: str = Field("TerminalToolRule")type: ToolRuleType = ToolRuleType.exit_loopdiff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex 52e280697..3a758bba3 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -165,7 +165,7 @@ def get_agent_state(return server.get_agent_state(user_id=actor.id, agent_id=agent_id)[email protected]("/{agent_id}", response_model=None, operation_id="delete_agent")[email protected]("/{agent_id}", response_model=AgentState, operation_id="delete_agent")def delete_agent(agent_id: str,server: "SyncServer" = Depends(get_letta_server),@@ -176,7 +176,12 @@ def delete_agent("""actor = server.get_user_or_default(user_id=user_id)- return server.delete_agent(user_id=actor.id, agent_id=agent_id)+ agent = server.get_agent(agent_id)+ if not agent:+ raise HTTPException(status_code=404, detail=f"Agent agent_id={agent_id} not found.")++ server.delete_agent(user_id=actor.id, agent_id=agent_id)+ return agent@router.get("/{agent_id}/sources", response_model=List[Source], operation_id="get_agent_sources")