Skip to content

Commit

Permalink
Merge pull request #155 from Elektra58/patch-9
Browse files Browse the repository at this point in the history
simplified add_tool for improved readability
  • Loading branch information
bonk1t authored Nov 13, 2024
2 parents c9f39eb + d13053a commit 8597d9e
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions agency_swarm/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,29 +393,19 @@ def get_id_from_file(f_path):
def add_tool(self, tool):
if not isinstance(tool, type):
raise Exception("Tool must not be initialized.")
if issubclass(tool, FileSearch):
# check that tools name is not already in tools
for t in self.tools:
if issubclass(t, FileSearch):
return
self.tools.append(tool)
elif issubclass(tool, CodeInterpreter):
for t in self.tools:
if issubclass(t, CodeInterpreter):
return
self.tools.append(tool)
elif issubclass(tool, Retrieval):
for t in self.tools:
if issubclass(t, Retrieval):
return
self.tools.append(tool)
elif issubclass(tool, BaseTool):

subclasses = [FileSearch, CodeInterpreter, Retrieval]
for subclass in subclasses:
if issubclass(tool, subclass):
if not any(issubclass(t, subclass) for t in self.tools):
self.tools.append(tool)
return

if issubclass(tool, BaseTool):
if tool.__name__ == "ExampleTool":
print("Skipping importing ExampleTool...")
return
for t in self.tools:
if t.__name__ == tool.__name__:
self.tools.remove(t)
self.tools = [t for t in self.tools if t.__name__ != tool.__name__]
self.tools.append(tool)
else:
raise Exception("Invalid tool type.")
Expand Down

0 comments on commit 8597d9e

Please sign in to comment.