Introduction
Tool selection helps an AI agent pick the best tool to solve a problem quickly and correctly.
Jump into concepts and practice - no test required
agent.select_tool(tools: list[str], task: str) -> str
tools = ['calculator', 'translator', 'search_engine'] task = 'translate English to Spanish' selected = agent.select_tool(tools, task)
tools = ['weather_api', 'news_api'] task = 'get today\'s weather' selected = agent.select_tool(tools, task)
class SimpleAgent: def select_tool(self, tools, task): task = task.lower() if 'calculate' in task or 'math' in task: return 'calculator' if 'calculator' in tools else None if 'translate' in task or 'language' in task: return 'translator' if 'translator' in tools else None if 'weather' in task: return 'weather_api' if 'weather_api' in tools else None return 'search_engine' if 'search_engine' in tools else None agent = SimpleAgent() tools = ['calculator', 'translator', 'weather_api', 'search_engine'] tasks = [ 'Calculate 5 plus 7', 'Translate hello to French', 'What is the weather today?', 'Find news about AI' ] for task in tasks: tool = agent.select_tool(tools, task) print(f"Task: {task}\nSelected tool: {tool}\n")
calculator should be used for a task containing the word 'math'?'math' in task_description.tools = ['calculator', 'translator', 'weather']
task = 'translate this sentence'
selected_tool = None
for tool in tools:
if tool in task:
selected_tool = tool
break
print(selected_tool)None. What is the error?
tools = {'calc': 'calculator', 'trans': 'translator'}
task = 'please compute this'
selected_tool = None
for key in tools:
if key in task:
selected_tool = tools[key]
print(selected_tool)