From 3108968c0d6d7832e2ba0283aff487c2f913c775 Mon Sep 17 00:00:00 2001 From: Sarah Wooders Date: Mon, 30 Sep 2024 09:50:15 -0700 Subject: [PATCH 1/3] minor patch to tool linking --- letta/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letta/agent.py b/letta/agent.py index 3fbc701633..3750249f99 100644 --- a/letta/agent.py +++ b/letta/agent.py @@ -353,7 +353,7 @@ def link_tools(self, tools: List[Tool]): from pprint import pprint pprint(tool.json_schema) - self.functions_python[tool.name] = env[tool.json_schema["name"]] + self.functions_python[tool.json_schema["name"]] = env[tool.json_schema["name"]] self.functions.append(tool.json_schema) assert all([callable(f) for k, f in self.functions_python.items()]), self.functions_python From ce49fa8499326eb4445d8e2271aad5e66d845d14 Mon Sep 17 00:00:00 2001 From: Sarah Wooders Date: Mon, 30 Sep 2024 09:53:47 -0700 Subject: [PATCH 2/3] remove error for tool linking --- letta/agent.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/letta/agent.py b/letta/agent.py index 3750249f99..b4b479b90e 100644 --- a/letta/agent.py +++ b/letta/agent.py @@ -237,10 +237,8 @@ def __init__( self.agent_state = agent_state assert isinstance(self.agent_state.memory, Memory), f"Memory object is not of type Memory: {type(self.agent_state.memory)}" - try: - self.link_tools(tools) - except Exception as e: - raise ValueError(f"Encountered an error while trying to link agent tools during initialization:\n{str(e)}") + # link tools + self.link_tools(tools) # gpt-4, gpt-3.5-turbo, ... self.model = self.agent_state.llm_config.model @@ -345,16 +343,20 @@ def link_tools(self, tools: List[Tool]): env = {} env.update(globals()) for tool in tools: - # WARNING: name may not be consistent? - if tool.module: # execute the whole module - exec(tool.module, env) - else: - exec(tool.source_code, env) - from pprint import pprint + try: + # WARNING: name may not be consistent? + if tool.module: # execute the whole module + exec(tool.module, env) + else: + exec(tool.source_code, env) + from pprint import pprint - pprint(tool.json_schema) - self.functions_python[tool.json_schema["name"]] = env[tool.json_schema["name"]] - self.functions.append(tool.json_schema) + pprint(tool.json_schema) + self.functions_python[tool.json_schema["name"]] = env[tool.json_schema["name"]] + self.functions.append(tool.json_schema) + except Exception as e: + print(f"WARNING: tool {tool.name} failed to link") + print(e) assert all([callable(f) for k, f in self.functions_python.items()]), self.functions_python def _load_messages_from_recall(self, message_ids: List[str]) -> List[Message]: From 54e6944c8545c8db7a1394dd6f4d11abd2641456 Mon Sep 17 00:00:00 2001 From: Sarah Wooders Date: Mon, 30 Sep 2024 09:58:12 -0700 Subject: [PATCH 3/3] change to warnings.warn --- letta/agent.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/letta/agent.py b/letta/agent.py index b4b479b90e..45ba882f70 100644 --- a/letta/agent.py +++ b/letta/agent.py @@ -349,13 +349,11 @@ def link_tools(self, tools: List[Tool]): exec(tool.module, env) else: exec(tool.source_code, env) - from pprint import pprint - pprint(tool.json_schema) self.functions_python[tool.json_schema["name"]] = env[tool.json_schema["name"]] self.functions.append(tool.json_schema) except Exception as e: - print(f"WARNING: tool {tool.name} failed to link") + warnings.warn(f"WARNING: tool {tool.name} failed to link") print(e) assert all([callable(f) for k, f in self.functions_python.items()]), self.functions_python