Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: minor patch to tool linking with JSON schema and Tool.name do not match #1802

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions letta/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -345,16 +343,18 @@ 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)

pprint(tool.json_schema)
self.functions_python[tool.name] = env[tool.json_schema["name"]]
self.functions.append(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:
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

def _load_messages_from_recall(self, message_ids: List[str]) -> List[Message]:
Expand Down
Loading