Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: Remove name from Create/Update tool (#741)

Matthew Zhou03fe2978462a
diff --git a/letta/cli/cli_config.py b/letta/cli/cli_config.py
index 87e43567c..12c039485 100644
--- a/letta/cli/cli_config.py
+++ b/letta/cli/cli_config.py
@@ -135,7 +135,7 @@ def add_tool(
func = eval(func_def.name)
# 4. Add or update the tool
- tool = client.create_or_update_tool(func=func, name=name, tags=tags, update=update)
+ tool = client.create_or_update_tool(func=func, tags=tags, update=update)
print(f"Tool {tool.name} added successfully")
diff --git a/letta/client/client.py b/letta/client/client.py
index 72f6dd432..30731d272 100644
--- a/letta/client/client.py
+++ b/letta/client/client.py
@@ -185,20 +185,15 @@ class AbstractClient(object):
def load_composio_tool(self, action: "ActionType") -> Tool:
raise NotImplementedError
- def create_tool(
- self, func, name: Optional[str] = None, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT
- ) -> Tool:
+ def create_tool(self, func, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT) -> Tool:
raise NotImplementedError
- def create_or_update_tool(
- self, func, name: Optional[str] = None, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT
- ) -> Tool:
+ def create_or_update_tool(self, func, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT) -> Tool:
raise NotImplementedError
def update_tool(
self,
id: str,
- name: Optional[str] = None,
description: Optional[str] = None,
func: Optional[Callable] = None,
tags: Optional[List[str]] = None,
@@ -1545,7 +1540,6 @@ class RESTClient(AbstractClient):
def create_tool(
self,
func: Callable,
- name: Optional[str] = None,
tags: Optional[List[str]] = None,
return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,
) -> Tool:
@@ -1565,7 +1559,7 @@ class RESTClient(AbstractClient):
source_type = "python"
# call server function
- request = ToolCreate(source_type=source_type, source_code=source_code, name=name, return_char_limit=return_char_limit)
+ request = ToolCreate(source_type=source_type, source_code=source_code, return_char_limit=return_char_limit)
if tags:
request.tags = tags
response = requests.post(f"{self.base_url}/{self.api_prefix}/tools", json=request.model_dump(), headers=self.headers)
@@ -1576,7 +1570,6 @@ class RESTClient(AbstractClient):
def create_or_update_tool(
self,
func: Callable,
- name: Optional[str] = None,
tags: Optional[List[str]] = None,
return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,
) -> Tool:
@@ -1596,7 +1589,7 @@ class RESTClient(AbstractClient):
source_type = "python"
# call server function
- request = ToolCreate(source_type=source_type, source_code=source_code, name=name, return_char_limit=return_char_limit)
+ request = ToolCreate(source_type=source_type, source_code=source_code, return_char_limit=return_char_limit)
if tags:
request.tags = tags
response = requests.put(f"{self.base_url}/{self.api_prefix}/tools", json=request.model_dump(), headers=self.headers)
@@ -1607,7 +1600,6 @@ class RESTClient(AbstractClient):
def update_tool(
self,
id: str,
- name: Optional[str] = None,
description: Optional[str] = None,
func: Optional[Callable] = None,
tags: Optional[List[str]] = None,
@@ -1638,7 +1630,6 @@ class RESTClient(AbstractClient):
source_type=source_type,
source_code=source_code,
tags=tags,
- name=name,
return_char_limit=return_char_limit,
)
response = requests.patch(f"{self.base_url}/{self.api_prefix}/tools/{id}", json=request.model_dump(), headers=self.headers)
@@ -2975,7 +2966,6 @@ class LocalClient(AbstractClient):
def create_tool(
self,
func,
- name: Optional[str] = None,
tags: Optional[List[str]] = None,
description: Optional[str] = None,
return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,
@@ -3017,7 +3007,6 @@ class LocalClient(AbstractClient):
def create_or_update_tool(
self,
func,
- name: Optional[str] = None,
tags: Optional[List[str]] = None,
description: Optional[str] = None,
return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,
@@ -3027,7 +3016,6 @@ class LocalClient(AbstractClient):
Args:
func (callable): The function to create a tool for.
- name: (str): Name of the tool (must be unique per-user.)
tags (Optional[List[str]], optional): Tags for the tool. Defaults to None.
description (str, optional): The description.
return_char_limit (int): The character limit for the tool's return value. Defaults to FUNCTION_RETURN_CHAR_LIMIT.
@@ -3045,7 +3033,6 @@ class LocalClient(AbstractClient):
Tool(
source_type=source_type,
source_code=source_code,
- name=name,
tags=tags,
description=description,
return_char_limit=return_char_limit,
@@ -3056,7 +3043,6 @@ class LocalClient(AbstractClient):
def update_tool(
self,
id: str,
- name: Optional[str] = None,
description: Optional[str] = None,
func: Optional[Callable] = None,
tags: Optional[List[str]] = None,
@@ -3067,7 +3053,6 @@ class LocalClient(AbstractClient):
Args:
id (str): ID of the tool
- name (str): Name of the tool
func (callable): Function to wrap in a tool
tags (List[str]): Tags for the tool
return_char_limit (int): The character limit for the tool's return value. Defaults to FUNCTION_RETURN_CHAR_LIMIT.
@@ -3079,7 +3064,6 @@ class LocalClient(AbstractClient):
"source_type": "python", # Always include source_type
"source_code": parse_source_code(func) if func else None,
"tags": tags,
- "name": name,
"description": description,
"return_char_limit": return_char_limit,
}
diff --git a/letta/schemas/tool.py b/letta/schemas/tool.py
index 0296f0906..ab4736e60 100644
--- a/letta/schemas/tool.py
+++ b/letta/schemas/tool.py
@@ -112,7 +112,6 @@ class Tool(BaseTool):
class ToolCreate(LettaBase):
- name: Optional[str] = Field(None, description="The name of the function (auto-generated from source_code if not provided).")
description: Optional[str] = Field(None, description="The description of the tool.")
tags: List[str] = Field([], description="Metadata tags.")
source_code: str = Field(..., description="The source code of the function.")
@@ -155,7 +154,6 @@ class ToolCreate(LettaBase):
json_schema = generate_tool_schema_for_composio(composio_action_schema.parameters, name=wrapper_func_name, description=description)
return cls(
- name=wrapper_func_name,
description=description,
source_type=source_type,
tags=tags,
@@ -187,7 +185,6 @@ class ToolCreate(LettaBase):
json_schema = generate_schema_from_args_schema_v2(langchain_tool.args_schema, name=wrapper_func_name, description=description)
return cls(
- name=wrapper_func_name,
description=description,
source_type=source_type,
tags=tags,
@@ -198,7 +195,6 @@ class ToolCreate(LettaBase):
class ToolUpdate(LettaBase):
description: Optional[str] = Field(None, description="The description of the tool.")
- name: Optional[str] = Field(None, description="The name of the function.")
tags: Optional[List[str]] = Field(None, description="Metadata tags.")
source_code: Optional[str] = Field(None, description="The source code of the function.")
source_type: Optional[str] = Field(None, description="The type of the source code.")
diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.py
index 5ea0b6b44..01e4c8557 100644
--- a/letta/services/tool_manager.py
+++ b/letta/services/tool_manager.py
@@ -122,6 +122,7 @@ class ToolManager:
new_schema = derive_openai_json_schema(source_code=pydantic_tool.source_code)
tool.json_schema = new_schema
+ tool.name = new_schema["name"]
# Save the updated tool to the database
return tool.update(db_session=session, actor=actor).to_pydantic()
diff --git a/tests/integration_test_agent_tool_graph.py b/tests/integration_test_agent_tool_graph.py
index 61db6dfbd..3a24e29bd 100644
--- a/tests/integration_test_agent_tool_graph.py
+++ b/tests/integration_test_agent_tool_graph.py
@@ -194,8 +194,8 @@ def test_check_tool_rules_with_different_models(mock_e2b_api_key_none):
# Create two test tools
t1_name = "first_secret_word"
t2_name = "second_secret_word"
- t1 = client.create_or_update_tool(first_secret_word, name=t1_name)
- t2 = client.create_or_update_tool(second_secret_word, name=t2_name)
+ t1 = client.create_or_update_tool(first_secret_word)
+ t2 = client.create_or_update_tool(second_secret_word)
tool_rules = [InitToolRule(tool_name=t1_name), InitToolRule(tool_name=t2_name)]
tools = [t1, t2]
@@ -217,7 +217,7 @@ def test_check_tool_rules_with_different_models(mock_e2b_api_key_none):
# Create tool rule with single initial tool
t3_name = "third_secret_word"
- t3 = client.create_or_update_tool(third_secret_word, name=t3_name)
+ t3 = client.create_or_update_tool(third_secret_word)
tool_rules = [InitToolRule(tool_name=t3_name)]
tools = [t3]
for config_file in config_files:
@@ -237,8 +237,8 @@ def test_claude_initial_tool_rule_enforced(mock_e2b_api_key_none):
# Create tool rules that require tool_a to be called first
t1_name = "first_secret_word"
t2_name = "second_secret_word"
- t1 = client.create_or_update_tool(first_secret_word, name=t1_name)
- t2 = client.create_or_update_tool(second_secret_word, name=t2_name)
+ t1 = client.create_or_update_tool(first_secret_word)
+ t2 = client.create_or_update_tool(second_secret_word)
tool_rules = [
InitToolRule(tool_name=t1_name),
ChildToolRule(tool_name=t1_name, children=[t2_name]),
@@ -366,8 +366,8 @@ def test_agent_conditional_tool_easy(mock_e2b_api_key_none):
coin_flip_name = "flip_coin"
secret_word_tool = "fourth_secret_word"
- flip_coin_tool = client.create_or_update_tool(flip_coin, name=coin_flip_name)
- reveal_secret = client.create_or_update_tool(fourth_secret_word, name=secret_word_tool)
+ flip_coin_tool = client.create_or_update_tool(flip_coin)
+ reveal_secret = client.create_or_update_tool(fourth_secret_word)
# Make tool rules
tool_rules = [
@@ -435,9 +435,9 @@ def test_agent_conditional_tool_hard(mock_e2b_api_key_none):
play_game = "can_play_game"
coin_flip_name = "flip_coin_hard"
final_tool = "fourth_secret_word"
- play_game_tool = client.create_or_update_tool(can_play_game, name=play_game)
- flip_coin_tool = client.create_or_update_tool(flip_coin_hard, name=coin_flip_name)
- reveal_secret = client.create_or_update_tool(fourth_secret_word, name=final_tool)
+ play_game_tool = client.create_or_update_tool(can_play_game)
+ flip_coin_tool = client.create_or_update_tool(flip_coin_hard)
+ reveal_secret = client.create_or_update_tool(fourth_secret_word)
# Make tool rules - chain them together with conditional rules
tool_rules = [
@@ -507,8 +507,8 @@ def test_agent_conditional_tool_without_default_child(mock_e2b_api_key_none):
# Create tools - we'll make several available to the agent
tool_name = "return_none"
- tool = client.create_or_update_tool(return_none, name=tool_name)
- secret_word = client.create_or_update_tool(first_secret_word, name="first_secret_word")
+ tool = client.create_or_update_tool(return_none)
+ secret_word = client.create_or_update_tool(first_secret_word)
# Make tool rules - only map one output, let others be free choice
tool_rules = [
@@ -568,8 +568,8 @@ def test_agent_reload_remembers_function_response(mock_e2b_api_key_none):
# Create tools
flip_coin_name = "flip_coin"
secret_word = "fourth_secret_word"
- flip_coin_tool = client.create_or_update_tool(flip_coin, name=flip_coin_name)
- secret_word_tool = client.create_or_update_tool(fourth_secret_word, name=secret_word)
+ flip_coin_tool = client.create_or_update_tool(flip_coin)
+ secret_word_tool = client.create_or_update_tool(fourth_secret_word)
# Make tool rules - map coin flip to fourth_secret_word
tool_rules = [
@@ -622,13 +622,12 @@ def test_simple_tool_rule(mock_e2b_api_key_none):
# Create tools
flip_coin_name = "flip_coin"
- another_secret_word = "first_secret_word"
secret_word = "fourth_secret_word"
random_tool = "can_play_game"
- flip_coin_tool = client.create_or_update_tool(flip_coin, name=flip_coin_name)
- secret_word_tool = client.create_or_update_tool(fourth_secret_word, name=secret_word)
- another_secret_word_tool = client.create_or_update_tool(first_secret_word, name=another_secret_word)
- random_tool = client.create_or_update_tool(can_play_game, name=random_tool)
+ flip_coin_tool = client.create_or_update_tool(flip_coin)
+ secret_word_tool = client.create_or_update_tool(fourth_secret_word)
+ another_secret_word_tool = client.create_or_update_tool(first_secret_word)
+ random_tool = client.create_or_update_tool(can_play_game)
tools = [flip_coin_tool, secret_word_tool, another_secret_word_tool, random_tool]
# Create tool rule: after flip_coin, must call fourth_secret_word
diff --git a/tests/test_client.py b/tests/test_client.py
index 2294c62fd..721a293fb 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -506,7 +506,7 @@ def test_attach_detach_agent_tool(client: Union[LocalClient, RESTClient], agent:
"""
return x * 2
- tool = client.create_or_update_tool(func=example_tool, name="test_tool")
+ tool = client.create_or_update_tool(func=example_tool)
# Initially tool should not be attached
initial_tools = client.list_attached_tools(agent_id=agent.id)
@@ -688,8 +688,8 @@ def test_agent_creation(client: Union[LocalClient, RESTClient]):
"""Another test tool."""
return "Hello from another test tool!"
- tool1 = client.create_or_update_tool(func=test_tool, name="test_tool", tags=["test"])
- tool2 = client.create_or_update_tool(func=another_test_tool, name="another_test_tool", tags=["test"])
+ tool1 = client.create_or_update_tool(func=test_tool, tags=["test"])
+ tool2 = client.create_or_update_tool(func=another_test_tool, tags=["test"])
# Create test blocks
offline_persona_block = client.create_block(label="persona", value="persona description", limit=5000)
diff --git a/tests/test_local_client.py b/tests/test_local_client.py
index f3d6945ef..7ea1c74d2 100644
--- a/tests/test_local_client.py
+++ b/tests/test_local_client.py
@@ -311,7 +311,7 @@ def test_tools(client: LocalClient):
assert client.get_tool(tool.id).tags == extras2
# update tool: source code
- client.update_tool(tool.id, name="print_tool2", func=print_tool2)
+ client.update_tool(tool.id, func=print_tool2)
assert client.get_tool(tool.id).name == "print_tool2"
diff --git a/tests/test_managers.py b/tests/test_managers.py
index 4865c58cc..3f5d8a0e3 100644
--- a/tests/test_managers.py
+++ b/tests/test_managers.py
@@ -1731,7 +1731,7 @@ def test_update_tool_source_code_refreshes_schema_only(server: SyncServer, print
name = "counter_tool"
# Create a ToolUpdate object to modify the tool's source_code
- tool_update = ToolUpdate(name=name, source_code=source_code)
+ tool_update = ToolUpdate(source_code=source_code)
# Update the tool using the manager method
server.tool_manager.update_tool_by_id(print_tool.id, tool_update, actor=default_user)
diff --git a/tests/test_v1_routes.py b/tests/test_v1_routes.py
index ad21c7713..4a0d027bc 100644
--- a/tests/test_v1_routes.py
+++ b/tests/test_v1_routes.py
@@ -48,7 +48,6 @@ def add_integers_tool():
@pytest.fixture
def create_integers_tool(add_integers_tool):
tool_create = ToolCreate(
- name=add_integers_tool.name,
description=add_integers_tool.description,
tags=add_integers_tool.tags,
source_code=add_integers_tool.source_code,
@@ -61,7 +60,6 @@ def create_integers_tool(add_integers_tool):
@pytest.fixture
def update_integers_tool(add_integers_tool):
tool_update = ToolUpdate(
- name=add_integers_tool.name,
description=add_integers_tool.description,
tags=add_integers_tool.tags,
source_code=add_integers_tool.source_code,
@@ -291,7 +289,6 @@ def test_add_composio_tool(client, mock_sync_server, add_integers_tool):
# Mock ToolCreate.from_composio to return the expected ToolCreate object
with patch("letta.schemas.tool.ToolCreate.from_composio") as mock_from_composio:
mock_from_composio.return_value = ToolCreate(
- name=add_integers_tool.name,
source_code=add_integers_tool.source_code,
json_schema=add_integers_tool.json_schema,
)