Lesson 7 of 23 ยท Part 0: Foundations

Agents & Tools

When LLMs can DO things โ€” not just talk about them.

Last time: RAG finds the right documents and adds them to the prompt so the AI can answer.
Today: Agents let the AI DO things: it picks tools, our code runs them, and it loops.
๐Ÿง 

I KNOW how

Knowledge exists

"To book a flight, search airline websites..."

"Use a weather API to get forecasts..."

"Run SELECT * FROM sales..."

๐Ÿง โœ•

But CAN'T do it

No ability to act

โœˆ๏ธActually book the flightโœ•
๐ŸŒค๏ธCheck real weather right nowโœ•
๐Ÿ—„๏ธRun SQL on your databaseโœ•
๐Ÿ“งSend a real emailโœ•

The Gap: Knowledge without Action

๐Ÿง 
LLMReasoning
+
โš™๏ธ
ToolsCapabilities
+
๐Ÿ”„
LoopIteration
=
โญ
AgentAutonomous

The LLM THINKS, your code ACTS.

LLM outputs:

{
ย ย "tool": "get_weather",
ย ย "args": {
ย ย ย ย "city": "Paris"
ย ย }
}
โ†’
โš™๏ธ

Your Code

โ†’

Result:

{
ย ย "result": "22ยฐC, Sunny"
}
๐Ÿง 
Think
๐Ÿงญ
Decide
โš™๏ธ
Execute
๐Ÿ‘
Observe

Agent

Loop

โ†’
Done!

Step-by-step walkthrough

๐Ÿ’ฌ
User asks

"What's the weather in Paris?"

๐Ÿง 
Agent THINKS

"I need the weather tool"

โš™๏ธ
Tool call

get_weather("Paris")

๐Ÿ“Š
Result

{ "temp": "22ยฐC", "conditions": "Sunny" }

๐Ÿง 
Agent THINKS

"I have the data, time to respond"

โœ…
Final response

"It's 22ยฐC and sunny in Paris!"

Try another:
"Plan a trip to Paris"
1
โœˆ๏ธ
search_flights("Paris, Mar")
โ†’
$340 round-trip, Air France
2
๐Ÿจ
search_hotels("Paris, 4โ˜…+")
โ†’
Hotel Le Marais, $120/night
3
๐ŸŒค๏ธ
get_weather("Paris, March")
โ†’
15ยฐC avg, light rain expected

Final Response

"I found a $340 round-trip on Air France, Hotel Le Marais for $120/night. March weather averages 15ยฐC with light rain -- pack a jacket!"

3 loop iterations, each adding to the response

Try another task:

Real Tool Examples

๐Ÿ”Search Tool

Command:

Googled "flights to Paris March"

Output:

3 results: Air France $340, Delta $420...

๐Ÿ’ปCode Execution

Command:

Ran python analyze.py

Output:

Analysis complete: 847 rows processed

๐Ÿ—„๏ธDatabase Query

Command:

SELECT revenue FROM sales
WHERE quarter='Q3'

Output:

Result: $4.2M (+18% YoY)

โœ…Good Design

name:

get_weather

description:

"Get current weather for a city name. Returns temperature in Celsius and conditions."

โŒBad Design

name:

do_stuff

description:

"Does things"

The LLM reads your descriptions to decide WHEN to use each tool.

Bad descriptions = wrong tool choices = broken agents

get_weather("Paris")
โ†’
{ "error": "Network timeout" }
๐Ÿง Agent reads the error and decides...
๐Ÿ”„

Retry

Try the same tool again

๐Ÿ”€

Fallback

Use a different tool

๐Ÿ’ฌ

Tell User

"Sorry, weather service is down"

Best choice here: Retry. Timeouts are often temporary, so trying again usually works.

Try another error:

What do you need?

Just a summary or answer

๐Ÿ“ก

Simple API Call

Cheaper & faster

Real-time data or actions

๐Ÿค–

Use an Agent

Tools + reasoning

Multiple steps with decisions

๐Ÿš€

Definitely Agent

Loop + multi-tool

Don't over-engineer: pick the simplest approach that works

RAG Becomes a Tool in the Agent Loop

๐Ÿง 
Think
โ†’
๐Ÿ’ญ
"I need company data"
โ†’
๐Ÿ“š
RAG Search
โ†’
๐Ÿ“„
Documents
โ†’
๐Ÿง 
Continue

RAG is just another tool

The agent decides when to search documents, just like it decides when to call any other tool.

search_docs()get_weather()run_code()

What You'll Build

Part 2

Simple Calculator Agent

Your first agent with add, multiply tools

Part 2

Math Tutor with 4 Tools

Calculator + explainer + hint generator + quiz

Part 3

Study Buddy + Knowledge

Agent with RAG-powered document lookup

Part 3

Terminal Assistant

Real file operations, system commands

Terminal Assistant Preview

$ List all Python files in /src

Calling list_files(path="/src", pattern="*.py")...

Found 12 files: main.py, utils.py, api.py...

$ Show me the largest one

Calling file_info(path="/src/api.py")...

api.py (2.4KB, 89 lines) - REST API endpoints

Key Takeaways

1Agent = LLM + Tools + Loop
2The LLM thinks, your code acts
3Clear tool names and descriptions matter
4Handle errors gracefully -- retry, fallback, or tell user
5Don't use agents when a simple API call would work
โ† Prev
1/0
Next: Basic API โ†’