fix: use JSON schema name instead of tool name for loading from env (#1798)

This commit is contained in:
Sarah Wooders
2024-09-30 09:24:10 -07:00
committed by GitHub
parent 4382c9be4b
commit 622de59fd0
3 changed files with 10 additions and 3 deletions

View File

@@ -350,7 +350,10 @@ class Agent(BaseAgent):
exec(tool.module, env)
else:
exec(tool.source_code, env)
self.functions_python[tool.name] = env[tool.name]
from pprint import pprint
pprint(tool.json_schema)
self.functions_python[tool.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

View File

@@ -1752,7 +1752,7 @@ class SyncServer(Server):
# TODO: not sure if this always works
func = env[functions[-1]]
json_schema = generate_schema(func, request.name)
json_schema = generate_schema(func)
else:
# provided by client
json_schema = request.json_schema

View File

@@ -106,7 +106,7 @@ def test_create_tool(client: Union[LocalClient, RESTClient]):
tools = client.list_tools()
print(f"Original tools {[t.name for t in tools]}")
tool = client.create_tool(print_tool, tags=["extras"])
tool = client.create_tool(print_tool, name="my_name", tags=["extras"])
tools = client.list_tools()
assert tool in tools, f"Expected {tool.name} in {[t.name for t in tools]}"
@@ -117,6 +117,10 @@ def test_create_tool(client: Union[LocalClient, RESTClient]):
assert tool is not None, "Expected tool to be created"
assert tool.id == tool.id, f"Expected {tool.id} to be {tool.id}"
# create agent with tool
agent_state = client.create_agent(tools=[tool.name])
response = client.user_message(agent_id=agent_state.id, message="hi")
# TODO: add back once we fix admin client tool creation
# def test_create_agent_tool_admin(admin_client):