Skip to content

Commit

Permalink
Merge pull request #313 from tcdent/tool-suggestions
Browse files Browse the repository at this point in the history
Suggest a similar tool name if the user specifies a non-existent tool name
  • Loading branch information
bboynton97 authored Feb 17, 2025
2 parents 59e4610 + 1bb716f commit e57ca6c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions agentstack/cli/tools.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Optional
import itertools
from difflib import get_close_matches
import inquirer
from agentstack import conf
from agentstack import conf, log
from agentstack.utils import term_color, is_snake_case
from agentstack import generation
from agentstack import repo
from agentstack._tools import get_all_tools
from agentstack._tools import get_all_tools, get_all_tool_names
from agentstack.agents import get_all_agents
from pathlib import Path
import sys
Expand Down Expand Up @@ -63,6 +64,16 @@ def add_tool(tool_name: Optional[str], agents=Optional[list[str]]):
"""
conf.assert_project()

all_tool_names = get_all_tool_names()
if tool_name and not tool_name in all_tool_names:
# tool was provided, but not found. make a suggestion.
suggestions = get_close_matches(tool_name, all_tool_names, n=1)
message = f"Tool '{tool_name}' not found."
if suggestions:
message += f"\nDid you mean '{suggestions[0]}'?"
log.error(message)
return

if not tool_name:
# Get all available tools including custom ones
available_tools = [t for t in get_all_tools() if t is not None]
Expand Down

0 comments on commit e57ca6c

Please sign in to comment.