Tools help agents do more things and solve bigger problems. They add new skills and information that agents alone don't have.
Why tools extend agent capabilities in Agentic AI
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Agentic AI
agent = Agent() agent.add_tool(tool_name, tool_function) result = agent.use_tool(tool_name, input_data)
The agent is first created.
Tools are added to give the agent new abilities.
Examples
Agentic AI
agent.add_tool('calculator', calculate_function) result = agent.use_tool('calculator', '2 + 2')
Agentic AI
agent.add_tool('weather_api', get_weather) weather = agent.use_tool('weather_api', 'New York')
Sample Model
This program shows an agent that can do math and greet people by adding two tools. It then uses these tools to get results.
Agentic AI
class Agent: def __init__(self): self.tools = {} def add_tool(self, name, func): self.tools[name] = func def use_tool(self, name, input_data): if name in self.tools: return self.tools[name](input_data) else: return 'Tool not found' # Define a simple calculator tool def calculator(expression): try: return str(eval(expression)) except Exception: return 'Invalid expression' # Define a simple greeting tool def greeter(name): return f'Hello, {name}!' # Create agent and add tools agent = Agent() agent.add_tool('calculator', calculator) agent.add_tool('greeter', greeter) # Use tools calc_result = agent.use_tool('calculator', '3 * 4') greet_result = agent.use_tool('greeter', 'Alice') print(calc_result) print(greet_result)
Important Notes
Tools let agents handle tasks they were not originally designed for.
Adding tools is like giving an agent new gadgets to solve problems.
Always check if the tool exists before using it to avoid errors.
Summary
Tools expand what an agent can do beyond its built-in skills.
Agents use tools to access new information or perform special tasks.
Adding and using tools is simple and makes agents more helpful.
Practice
1. Why do agents use tools to extend their capabilities?
easy
Solution
Step 1: Understand agent built-in skills
Agents have a set of skills they can perform on their own, but these are limited.Step 2: Role of tools in extending capabilities
Tools allow agents to do more by accessing new information or performing special tasks beyond their built-in skills.Final Answer:
To perform tasks beyond their built-in skills -> Option AQuick Check:
Tools extend agent skills = C [OK]
Hint: Tools add new skills to agents quickly [OK]
Common Mistakes:
- Thinking tools slow down agents
- Believing tools limit agent abilities
- Assuming agents avoid new skills
2. Which of the following is the correct way to describe how an agent uses a tool?
easy
Solution
Step 1: Understand agent-tool interaction
Agents use tools by calling them when a task requires capabilities beyond their own.Step 2: Identify correct description
Calling a tool to perform a specific task matches how agents extend their abilities.Final Answer:
Agent calls a tool to perform a specific task -> Option CQuick Check:
Agent uses tools by calling them = B [OK]
Hint: Agents call tools to help with tasks [OK]
Common Mistakes:
- Thinking agents ignore tools
- Believing tools replace core skills
- Assuming tools are disabled after use
3. Given this code snippet, what will the agent output?
tools = {'calculator': lambda x, y: x + y}
agent_skills = ['chat']
# Agent uses calculator tool
result = tools['calculator'](3, 4)
print(f'Result: {result}')medium
Solution
Step 1: Understand the tool function
The 'calculator' tool is a function that adds two numbers x and y.Step 2: Calculate the result of the tool call
Calling tools['calculator'](3, 4) returns 3 + 4 = 7.Final Answer:
Result: 7 -> Option DQuick Check:
3 + 4 = 7 [OK]
Hint: Check what the tool function does with inputs [OK]
Common Mistakes:
- Concatenating numbers as strings
- Confusing tool name with output
- Assuming tools dictionary is missing
4. Find the error in this agent-tool usage code:
tools = {'search': lambda query: 'results for ' + query}
# Agent tries to use tool
output = tools['search'](123)
print(output)medium
Solution
Step 1: Check tool function input type
The 'search' tool concatenates 'results for ' with the input query, expecting a string.Step 2: Identify input type mismatch
The code passes 123 (a number), which causes a type error when concatenating with a string.Final Answer:
The tool function expects a string, but got a number -> Option BQuick Check:
String concat needs string input = A [OK]
Hint: Check input types for string operations [OK]
Common Mistakes:
- Ignoring input type mismatch
- Assuming tools dictionary is empty
- Thinking print syntax is wrong
5. An agent has built-in skills for chatting but needs to answer math questions. Which approach best extends its capabilities using tools?
hard
Solution
Step 1: Identify agent's current skills and needs
The agent can chat but lacks math skills needed to answer math questions.Step 2: Choose the best way to extend capabilities
Adding a calculator tool allows the agent to handle math tasks without losing chat skills or needing full retraining.Final Answer:
Add a calculator tool the agent can call for math tasks -> Option AQuick Check:
Tools add needed skills without retraining = D [OK]
Hint: Add tools for missing skills, not rewrite agent [OK]
Common Mistakes:
- Thinking agent must relearn all skills
- Disabling useful existing skills
- Ignoring tasks agent can't do
