Skip to content

Commit

Permalink
fix: patch api routes (#2374)
Browse files Browse the repository at this point in the history
  • Loading branch information
carenthomas authored Jan 22, 2025
1 parent 13ec139 commit 2937494
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 150 deletions.
2 changes: 1 addition & 1 deletion examples/docs/agent_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
),
],
# LLM model & endpoint configuration
llm="openai/gpt-4",
model="openai/gpt-4",
context_window_limit=8000,
# embedding model & endpoint configuration (cannot be changed)
embedding="openai/text-embedding-ada-002",
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/agent_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
),
],
# set automatic defaults for LLM/embedding config
llm="openai/gpt-4",
model="openai/gpt-4",
embedding="openai/text-embedding-ada-002",
)
print(f"Created agent with name {agent_state.name} and unique ID {agent_state.id}")
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
value="I am a friendly AI",
),
],
llm=llm_configs[0].handle,
model=llm_configs[0].handle,
embedding=embedding_configs[0].handle,
)
print(f"Created agent: {agent_state.name} with ID {str(agent_state.id)}")
Expand Down
4 changes: 2 additions & 2 deletions examples/docs/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def roll_d20() -> str:
),
],
# set automatic defaults for LLM/embedding config
llm="openai/gpt-4",
model="openai/gpt-4",
embedding="openai/text-embedding-ada-002",
# create the agent with an additional tool
tool_ids=[tool.id],
Expand Down Expand Up @@ -88,7 +88,7 @@ def roll_d20() -> str:
value="username: sarah",
),
],
llm="openai/gpt-4",
model="openai/gpt-4",
embedding="openai/text-embedding-ada-002",
include_base_tools=False,
tool_ids=[tool.id, send_message_tool],
Expand Down
10 changes: 5 additions & 5 deletions examples/notebooks/Agentic RAG with Letta.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
" value=\"Name: Sarah\",\n",
" ),\n",
" ],\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
")"
]
Expand Down Expand Up @@ -305,7 +305,7 @@
" ),\n",
" ],\n",
" # set automatic defaults for LLM/embedding config\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
")\n",
"normal_agent.tools"
Expand Down Expand Up @@ -345,7 +345,7 @@
" ),\n",
" ],\n",
" # set automatic defaults for LLM/embedding config\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
" tools=['send_message'], \n",
" include_base_tools=False\n",
Expand Down Expand Up @@ -422,7 +422,7 @@
" + \"that you use to lookup information about users' birthdays.\"\n",
" ),\n",
" ],\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\"\n",
")"
]
Expand Down Expand Up @@ -852,7 +852,7 @@
" ),\n",
" ],\n",
" tool_ids=[search_tool.id], \n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
")"
]
},
Expand Down
10 changes: 5 additions & 5 deletions examples/notebooks/Multi-agent recruiting workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
" ],\n",
" block_ids=[org_block.id],\n",
" tool_ids=[read_resume_tool.id, submit_evaluation_tool.id]\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
")\n"
]
Expand Down Expand Up @@ -251,7 +251,7 @@
" ],\n",
" block_ids=[org_block.id],\n",
" tool_ids=[email_candidate_tool.id]\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
")"
]
Expand Down Expand Up @@ -623,7 +623,7 @@
" ],\n",
" block_ids=[org_block.id],\n",
" tool_ids=[read_resume_tool.id, submit_evaluation_tool.id]\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
")\n",
"\n",
Expand All @@ -637,7 +637,7 @@
" ],\n",
" block_ids=[org_block.id],\n",
" tool_ids=[email_candidate_tool.id]\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\",\n",
")"
]
Expand Down Expand Up @@ -740,7 +740,7 @@
" ],\n",
" block_ids=[org_block.id],\n",
" tool_ids=[search_candidate_tool.id, consider_candidate_tool.id],\n",
" llm=\"openai/gpt-4\",\n",
" model=\"openai/gpt-4\",\n",
" embedding=\"openai/text-embedding-ada-002\"\n",
")\n",
" \n"
Expand Down
52 changes: 28 additions & 24 deletions letta/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def get_in_context_memory(self, agent_id: str) -> Memory:
Returns:
memory (Memory): In-context memory of the agent
"""
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory", headers=self.headers)
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory", headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get in-context memory: {response.text}")
return Memory(**response.json())
Expand All @@ -797,7 +797,7 @@ def update_in_context_memory(self, agent_id: str, section: str, value: Union[Lis
"""
memory_update_dict = {section: value}
response = requests.patch(
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory", json=memory_update_dict, headers=self.headers
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory", json=memory_update_dict, headers=self.headers
)
if response.status_code != 200:
raise ValueError(f"Failed to update in-context memory: {response.text}")
Expand All @@ -814,10 +814,10 @@ def get_archival_memory_summary(self, agent_id: str) -> ArchivalMemorySummary:
summary (ArchivalMemorySummary): Summary of the archival memory
"""
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/archival", headers=self.headers)
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/context", headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get archival memory summary: {response.text}")
return ArchivalMemorySummary(**response.json())
return ArchivalMemorySummary(size=response.json().get("num_archival_memory", 0))

def get_recall_memory_summary(self, agent_id: str) -> RecallMemorySummary:
"""
Expand All @@ -829,10 +829,10 @@ def get_recall_memory_summary(self, agent_id: str) -> RecallMemorySummary:
Returns:
summary (RecallMemorySummary): Summary of the recall memory
"""
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/recall", headers=self.headers)
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/context", headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get recall memory summary: {response.text}")
return RecallMemorySummary(**response.json())
return RecallMemorySummary(size=response.json().get("num_recall_memory", 0))

def get_in_context_messages(self, agent_id: str) -> List[Message]:
"""
Expand All @@ -844,10 +844,10 @@ def get_in_context_messages(self, agent_id: str) -> List[Message]:
Returns:
messages (List[Message]): List of in-context messages
"""
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/messages", headers=self.headers)
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/context", headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get in-context messages: {response.text}")
return [Message(**message) for message in response.json()]
raise ValueError(f"Failed to get recall memory summary: {response.text}")
return [Message(**message) for message in response.json().get("messages", "")]

# agent interactions

Expand Down Expand Up @@ -889,7 +889,9 @@ def get_archival_memory(
params["before"] = str(before)
if after:
params["after"] = str(after)
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{str(agent_id)}/archival", params=params, headers=self.headers)
response = requests.get(
f"{self.base_url}/{self.api_prefix}/agents/{str(agent_id)}/archival_memory", params=params, headers=self.headers
)
assert response.status_code == 200, f"Failed to get archival memory: {response.text}"
return [Passage(**passage) for passage in response.json()]

Expand All @@ -906,7 +908,7 @@ def insert_archival_memory(self, agent_id: str, memory: str) -> List[Passage]:
"""
request = CreateArchivalMemory(text=memory)
response = requests.post(
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/archival", headers=self.headers, json=request.model_dump()
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/archival_memory", headers=self.headers, json=request.model_dump()
)
if response.status_code != 200:
raise ValueError(f"Failed to insert archival memory: {response.text}")
Expand All @@ -920,7 +922,7 @@ def delete_archival_memory(self, agent_id: str, memory_id: str):
agent_id (str): ID of the agent
memory_id (str): ID of the memory
"""
response = requests.delete(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/archival/{memory_id}", headers=self.headers)
response = requests.delete(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/archival_memory/{memory_id}", headers=self.headers)
assert response.status_code == 200, f"Failed to delete archival memory: {response.text}"

# messages (recall memory)
Expand Down Expand Up @@ -1463,12 +1465,14 @@ def get_tool_id(self, tool_name: str):
Returns:
id (str): ID of the tool (`None` if not found)
"""
response = requests.get(f"{self.base_url}/{self.api_prefix}/tools/name/{tool_name}", headers=self.headers)
if response.status_code == 404:
return None
elif response.status_code != 200:
response = requests.get(f"{self.base_url}/{self.api_prefix}/tools", headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get tool: {response.text}")
return response.json()

tools = [tool for tool in [Tool(**tool) for tool in response.json()] if tool.name == tool_name]
if not tools:
return None
return tools[0].id

def upsert_base_tools(self) -> List[Tool]:
response = requests.post(f"{self.base_url}/{self.api_prefix}/tools/add-base-tools/", headers=self.headers)
Expand Down Expand Up @@ -1852,7 +1856,7 @@ def add_agent_memory_block(self, agent_id: str, create_block: CreateBlock) -> Me
memory (Memory): The updated memory
"""
response = requests.post(
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block",
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory/blocks",
headers=self.headers,
json=create_block.model_dump(),
)
Expand Down Expand Up @@ -1893,14 +1897,14 @@ def remove_agent_memory_block(self, agent_id: str, block_label: str) -> Memory:
memory (Memory): The updated memory
"""
response = requests.delete(
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block/{block_label}",
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory/blocks/{block_label}",
headers=self.headers,
)
if response.status_code != 200:
raise ValueError(f"Failed to remove agent memory block: {response.text}")
return Memory(**response.json())

def get_agent_memory_blocks(self, agent_id: str) -> List[Block]:
def list_agent_memory_blocks(self, agent_id: str) -> List[Block]:
"""
Get all the blocks in the agent's core memory
Expand All @@ -1910,7 +1914,7 @@ def get_agent_memory_blocks(self, agent_id: str) -> List[Block]:
Returns:
blocks (List[Block]): The blocks in the agent's core memory
"""
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block", headers=self.headers)
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory/blocks", headers=self.headers)
if response.status_code != 200:
raise ValueError(f"Failed to get agent memory blocks: {response.text}")
return [Block(**block) for block in response.json()]
Expand All @@ -1927,7 +1931,7 @@ def get_agent_memory_block(self, agent_id: str, label: str) -> Block:
block (Block): The block corresponding to the label
"""
response = requests.get(
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block/{label}",
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory/blocks/{label}",
headers=self.headers,
)
if response.status_code != 200:
Expand Down Expand Up @@ -1960,7 +1964,7 @@ def update_agent_memory_block(
if limit:
data["limit"] = limit
response = requests.patch(
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block/{label}",
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/core_memory/blocks/{label}",
headers=self.headers,
json=data,
)
Expand Down Expand Up @@ -3523,7 +3527,7 @@ def remove_agent_memory_block(self, agent_id: str, block_label: str) -> Memory:
"""
return self.server.agent_manager.detach_block_with_label(agent_id=agent_id, block_label=block_label, actor=self.user)

def get_agent_memory_blocks(self, agent_id: str) -> List[Block]:
def list_agent_memory_blocks(self, agent_id: str) -> List[Block]:
"""
Get all the blocks in the agent's core memory
Expand Down
20 changes: 10 additions & 10 deletions letta/schemas/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CreateAgent(BaseModel, validate_assignment=True): #
)
description: Optional[str] = Field(None, description="The description of the agent.")
metadata_: Optional[Dict] = Field(None, description="The metadata of the agent.", alias="metadata_")
llm: Optional[str] = Field(
model: Optional[str] = Field(
None,
description="The LLM configuration handle used by the agent, specified in the format "
"provider/model-name, as an alternative to specifying llm_config.",
Expand All @@ -139,7 +139,7 @@ class CreateAgent(BaseModel, validate_assignment=True): #
tool_exec_environment_variables: Optional[Dict[str, str]] = Field(
None, description="The environment variables for tool execution specific to this agent."
)
variables: Optional[Dict[str, str]] = Field(None, description="The variables that should be set for the agent.")
memory_variables: Optional[Dict[str, str]] = Field(None, description="The variables that should be set for the agent.")

@field_validator("name")
@classmethod
Expand All @@ -166,26 +166,26 @@ def validate_name(cls, name: str) -> str:

return name

@field_validator("llm")
@field_validator("model")
@classmethod
def validate_llm(cls, llm: Optional[str]) -> Optional[str]:
if not llm:
return llm
def validate_model(cls, model: Optional[str]) -> Optional[str]:
if not model:
return model

provider_name, model_name = llm.split("/", 1)
provider_name, model_name = model.split("/", 1)
if not provider_name or not model_name:
raise ValueError("The llm config handle should be in the format provider/model-name")

return llm
return model

@field_validator("embedding")
@classmethod
def validate_embedding(cls, embedding: Optional[str]) -> Optional[str]:
if not embedding:
return embedding

provider_name, model_name = embedding.split("/", 1)
if not provider_name or not model_name:
provider_name, embedding_name = embedding.split("/", 1)
if not provider_name or not embedding_name:
raise ValueError("The embedding config handle should be in the format provider/model-name")

return embedding
Expand Down
Loading

0 comments on commit 2937494

Please sign in to comment.