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

Case insensitive tool and agent names #126

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 8 additions & 7 deletions src/crewai/agents/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def _call(
) -> Dict[str, Any]:
"""Run text through and get agent response."""
# Construct a mapping of tool name to tool for easy lookup
name_to_tool_map = {tool.name: tool for tool in self.tools}
name_to_tool_map = {tool.name.casefold(): tool for tool in self.tools}
# We construct a mapping from each tool to a color, used for logging.
color_mapping = get_color_mapping(
[tool.name for tool in self.tools], excluded_colors=["green", "red"]
[name for name in name_to_tool_map.keys()], excluded_colors=["green", "red"]
)
intermediate_steps: List[Tuple[AgentAction, str]] = []
# Let's start tracking the number of iterations and time elapsed
Expand Down Expand Up @@ -170,7 +170,7 @@ def _iter_next_step(
output = action.copy()
output.tool_input = f"tool:{action.tool}|input:{action.tool_input}"
output.tool = tool.name
name_to_tool_map[tool.name] = tool
name_to_tool_map[tool.name.casefold()] = tool
color_mapping[tool.name] = color_mapping[action.tool]

actions: List[AgentAction]
Expand All @@ -180,10 +180,11 @@ def _iter_next_step(
if run_manager:
run_manager.on_agent_action(agent_action, color="green")
# Otherwise we lookup the tool
if agent_action.tool in name_to_tool_map:
tool = name_to_tool_map[agent_action.tool]
action_tool_name = agent_action.tool.casefold()
if action_tool_name in name_to_tool_map:
tool = name_to_tool_map[action_tool_name]
return_direct = tool.return_direct
color = color_mapping[agent_action.tool]
color = color_mapping[action_tool_name]
tool_run_kwargs = self.agent.tool_run_logging_kwargs()
if return_direct:
tool_run_kwargs["llm_prefix"] = ""
Expand All @@ -200,7 +201,7 @@ def _iter_next_step(
observation = InvalidTool().run(
{
"requested_tool_name": agent_action.tool,
"available_tool_names": list(name_to_tool_map.keys()),
"available_tool_names": [tool.name for tool in name_to_tool_map.values()],
},
verbose=self.verbose,
color=None,
Expand Down
3 changes: 2 additions & 1 deletion src/crewai/tools/agent_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def __execute(self, command):
if not agent or not task or not context:
return self.i18n.errors("agent_tool_missing_param")

agent_name = agent.strip().casefold()
agent = [
available_agent
for available_agent in self.agents
if available_agent.role == agent
if available_agent.role.casefold() == agent_name
]

if not agent:
Expand Down
Loading