0–5 min
Real Hook
5–25 min
Core Concept
25–45 min
Live Coding
45–55 min
You Code It
55–60 min
Cheat Sheet
🔥 Real-World Hook (0–5 min)

GitHub Copilot doesn't just autocomplete — it can read your entire repo, run tests, write a fix, and open a PR. That's an AI agent.

Agents are LLMs that can USE TOOLS: search the web, run code, read files, call APIs, query databases. They decide which tool to call, call it, observe the result, and repeat until the task is done. ReAct = Reason + Act.

📈 The ReAct Loop (5–25 min)

💡 Thought → Action → Observation → repeat

Thought — LLM reasons about what to do next.
Action — LLM calls a tool (calculator, search, Python REPL).
Observation — tool returns a result.
Final Answer — LLM synthesises all observations into a response.

💻 Live Demo — Research Agent (25–45 min)

>from langchain_groq import ChatGroq
from langchain.agents import create_react_agent, AgentExecutor
from langchain_core.tools import tool
from langchain import hub
import os, math

llm = ChatGroq(model="llama3-8b-8192", api_key=os.getenv("GROQ_API_KEY"), temperature=0)

# Define tools the agent can use
@tool
def calculator(expression: str) -> str:
    "Evaluate a mathematical expression. Input: a Python math expression string."
    try:
        result = eval(expression, {"__builtins__": {}}, vars(math))
        return f"Result: {result}" 
    except Exception as e:
        return f"Error: {e}" 

@tool
def unit_converter(value_and_units: str) -> str:
    "Convert units. Input format: "100 km to miles" or "5 kg to pounds"."
    parts = value_and_units.split()
    if len(parts) < 4:
        return "Invalid format. Use: "100 km to miles""
    val, from_u, _, to_u = parts[0], parts[1].lower(), parts[2], parts[3].lower()
    conversions = {("km","miles"): 0.621371, ("kg","pounds"): 2.20462,
                   ("celsius","fahrenheit"): None}
    if (from_u, to_u) in conversions:
        factor = conversions[(from_u, to_u)]
        if factor:
            return f"{float(val) * factor:.4f} {to_u}" 
        else:
            return f"{float(val) * 9/5 + 32:.1f} fahrenheit" 
    return "Conversion not supported"

tools = [calculator, unit_converter]

# Load standard ReAct prompt from LangChain hub
react_prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, tools, react_prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True, max_iterations=5)

result = executor.invoke({
    "input": "If I run 42.2 km (a marathon) and burn 2800 calories,
            how many calories per mile is that?"
})
print(result["output"])

📋 You Code It (45–55 min)

✍ Task

Add a word_counter tool that counts words in a string. Ask the agent: "Count the words in this sentence and tell me the square root of that number: The quick brown fox jumps over the lazy dog."

⚡ Day 12 Cheat Sheet

@tool
Decorator to register a tool
create_react_agent(llm, tools, prompt)
Build ReAct agent
AgentExecutor(agent, tools)
Run loop with tools
executor.invoke({"input": q})
Ask the agent
verbose=True
See Thought/Action/Obs
max_iterations=5
Prevent infinite loops
hub.pull("hwchase17/react")
Standard ReAct prompt
tool docstring
LLM reads this to know when to use the tool