Skip to content

Commit e57ca6c

Browse files
authored
Merge pull request #313 from tcdent/tool-suggestions
Suggest a similar tool name if the user specifies a non-existent tool name
2 parents 59e4610 + 1bb716f commit e57ca6c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

agentstack/cli/tools.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Optional
22
import itertools
3+
from difflib import get_close_matches
34
import inquirer
4-
from agentstack import conf
5+
from agentstack import conf, log
56
from agentstack.utils import term_color, is_snake_case
67
from agentstack import generation
78
from agentstack import repo
8-
from agentstack._tools import get_all_tools
9+
from agentstack._tools import get_all_tools, get_all_tool_names
910
from agentstack.agents import get_all_agents
1011
from pathlib import Path
1112
import sys
@@ -63,6 +64,16 @@ def add_tool(tool_name: Optional[str], agents=Optional[list[str]]):
6364
"""
6465
conf.assert_project()
6566

67+
all_tool_names = get_all_tool_names()
68+
if tool_name and not tool_name in all_tool_names:
69+
# tool was provided, but not found. make a suggestion.
70+
suggestions = get_close_matches(tool_name, all_tool_names, n=1)
71+
message = f"Tool '{tool_name}' not found."
72+
if suggestions:
73+
message += f"\nDid you mean '{suggestions[0]}'?"
74+
log.error(message)
75+
return
76+
6677
if not tool_name:
6778
# Get all available tools including custom ones
6879
available_tools = [t for t in get_all_tools() if t is not None]

0 commit comments

Comments
 (0)