Agentic Step 1: What Are Agents?

Understand the concept of "agentic AI" — AI that can use tools and make decisions.

What Is an Agent?

A regular AI chat model works like this:

User: "What's 234 × 567?"
AI: "I'm sorry, I can't compute that precisely."

LLMs are bad at math. They're also bad at accessing real-time data, querying databases, or controlling hardware.

An agent fixes this by giving the AI access to tools:

User: "What's 234 × 567?"
AI: "Let me use my calculator tool."
     → Calls calculate(234 * 567)
     → Gets result: 132,678
AI: "234 × 567 = 132,678"

The Agent Loop

                    ┌─────────────────────────┐
                    │  User sends a message    │
                    └──────────┬──────────────┘
                               ▼
                    ┌─────────────────────────┐
                    │  LLM decides what to do  │
                    └──────────┬──────────────┘
                               │
                    ┌──────────▼──────────┐
                    │  Does the LLM want   │
                    │  to call a tool?     │
                    └──────┬──────┬───────┘
                           │      │
                        Yes │      │ No
                           │      │
                    ┌──────▼──┐ ┌─▼──────────┐
                    │ Execute  │ │ Return     │
                    │ tool     │ │ response   │
                    │ function │ │ to user    │
                    └──────┬──┘ └────────────┘
                           │
                    ┌──────▼──────┐
                    │ Feed result │
                    │ back to LLM │
                    └──────┬──────┘
                           │
                    ┌──────▼──────┐
                    │ LLM decides │ (loops back)
                    └─────────────┘

The LLM can call tools multiple times in sequence. For example: 1. "Search Wikipedia for the population of France" 2. "Calculate the result divided by 10" 3. "Format the answer nicely"

Tools vs. Functions

Term Meaning
Tool A capability the AI can use (calculator, search, database query)
Function The actual Python function that runs when the tool is called
Tool schema A JSON description of the tool that the AI uses to decide when to call it

OpenAI Function Calling

OpenAI's API has a tools parameter. You define tools as JSON schemas:

tools = [
    {
        "type": "function",
        "function": {
            "name": "calculate",
            "description": "Evaluate a math expression",
            "parameters": {
                "type": "object",
                "properties": {
                    "expression": {
                        "type": "string",
                        "description": "The math expression (e.g., 2 + 2)"
                    }
                },
                "required": ["expression"]
            }
        }
    }
]

When the AI thinks it needs to calculate something, it returns a tool_calls response instead of a text response. You execute the function and send the result back.

Why Agents Matter

Without agents: - AI can't access real-time data - AI can't do math - AI can't interact with your database - AI can't control hardware or APIs

With agents: - AI can search the web for current information - AI can calculate precise results - AI can query your database ("Show me all users who signed up last week") - AI can call external APIs ("Book a flight ticket")

What You'll Build

In the next steps: 1. Calculator tool — let the AI do math 2. Research agent — let the AI search Wikipedia 3. Chain-of-thought — let the AI reason step by step 4. Chat enhancement — add tools to your existing chat app