Tools & Superpowers

Module 3: How Agents Use Tools to Act

What Are Tools?

Tools are the agent's superpowers. They let agents interact with the external world, execute tasks, and solve problems. Without tools, agents are just text generators. With tools, they become action-taking systems.

๐Ÿงฎ

Calculator

Performs mathematical operations: add, subtract, multiply, divide, exponents.

calc.multiply(15, 8) โ†’ 120
๐Ÿ”

Search

Searches the web, databases, or document collections for information.

search("AI agents") โ†’ 1.2M results
๐Ÿ—„๏ธ

Database

Queries and retrieves data from structured databases and knowledge bases.

db.query("SELECT * FROM users WHERE city='NYC'")
๐ŸŒ

API

Calls external services and integrates with third-party platforms.

weather_api.get_temperature('NYC') โ†’ 72ยฐF
๐Ÿ“„

File System

Reads, writes, and manages files on local or cloud storage.

file.read('report.txt') โ†’ content
๐Ÿ“ง

Communication

Sends emails, messages, notifications, and schedules events.

email.send(to="user@example.com", subject="Update")

Tool-Using Workflow

1
User Query
โ†’
2
Agent Analyzes
โ†’
3
Select Tools
โ†’
4
Execute Tools
โ†’
5
Combine Results
โ†’
6
Respond

Before you click Practice โ€” Module 3 notebook

Tools are ordinary Python functions the model is allowed to request. You decorate them with @tool, then bind_tools so Groq can emit a structured tool_calls object instead of only chatting.

Installโ†’API keyโ†’@tool multiply / weatherโ†’bind_tools + invoke

After you run bind_tools, the interesting print is not the sentence โ€” it is Tool Calls output by model.

Practice task 1

Install packages into this notebookโ€™s Python

Run the first code cell. It uses sys.executable -m pip so packages go into Kodinโ€™s Jupyter kernel, not a random Windows pip.

# Install into THIS notebook kernel (not Windows pip).
import sys
import subprocess

print("Installing into:", sys.executable)
subprocess.check_call([
    sys.executable, "-m", "pip", "install", "-qU",
    "langgraph", "langchain-groq", "langchain-core",
])
print("Done. Run the next cells.")

Expected: Prints the kernel path, then โ€œDone.โ€

Why this cell: A plain !pip install on Windows often installs into a different Python, then the next cell fails with ModuleNotFoundError: langgraph. If import still fails: Kernel โ†’ Restart Kernel, then Run All.
Practice task 2

API key + MODEL + groq_text (same as Module 1)

Every practice notebook repeats this cell. Run it before any Groq call. Key stays in os.environ["GROQ_API_KEY"] for this kernel session.

import os
MODEL = "openai/gpt-oss-20b"

def groq_text(msg) -> str:
    # GPT-OSS may return text, a list of parts, or reasoning_content
    ...

if not os.getenv("GROQ_API_KEY"):
    os.environ["GROQ_API_KEY"] = input("Enter GROQ_API_KEY: ").strip()
print("API key ready. Model:", MODEL)

Expected: โ€œAPI key ready. Model: openai/gpt-oss-20bโ€

Why this cell: Without this cell, ChatGroq has no key. Without groq_text, later prints can look empty even when the model answered.
Practice task 3

Create tools with @tool

The docstring is the description the model reads. Type hints become the argument schema. These functions are fake on purpose (weather is always sunny) so the lab never needs the internet.

from langchain_core.tools import tool

@tool
def multiply(a: int, b: int) -> int:
    """Multiply two integers."""
    return a * b

@tool
def get_weather(location: str) -> str:
    """Get the current weather in a given location."""
    return f"The weather in {location} is sunny and 75 degrees."

tools = [multiply, get_weather]
print("Tools created:", [t.name for t in tools])
  • Write a one-line docstring โ€” that is the โ€œmanualโ€ the LLM sees.
  • Put tools in a list; later cells pass that same list to bind_tools.

Expected: Tools created: ['multiply', 'get_weather']

Why this cell: Without @tool, LangChain cannot send a JSON schema to Groq. The name of the function becomes the tool name (multiply, get_weather).
Practice task 4

Bind tools and watch the model request them

bind_tools does not run the functions yet. It only lets the model ask to run them. You print response.tool_calls to see name + arguments.

from langchain_groq import ChatGroq

llm = ChatGroq(model=MODEL, temperature=0)
llm_with_tools = llm.bind_tools(tools)

response = llm_with_tools.invoke("What is 15 multiplied by 4?")
print("Tool Calls output by model:", getattr(response, "tool_calls", None) or [])

response2 = llm_with_tools.invoke("What is the weather like in Paris?")
print("Tool Calls output by model (Weather):", getattr(response2, "tool_calls", None) or [])
  • llm_with_tools = llm.bind_tools(tools) โ€” attach schemas to this chat model.
  • tool_calls โ€” structured request, not the number 60 yet.
  • If the list is empty, re-run Task 2 (key) and check the prompt is clearly a math/weather question.

Expected: tool_calls for multiply with a=15, b=4, then get_weather with location Paris.

Why this cell: This matches the Tool-Using Workflow on this page: the model chooses a tool. A full agent (Module 5) would execute the tool and send the result back. Here you stop at โ€œthe model requested multiply(15, 4).โ€

โœ๏ธ Practice: Choose the Right Tool

Scenario 1: A user asks "What's the weather in Paris and the population?" Which tools should the agent use?