Agentic AI Notebook
Agent Foundations
Phase 4Module 1 of 15

What is an AI Agent?

LLMs alone only generate text. Agents complete multi-step workflows by calling APIs, databases, and external systems.

A chatbot advises from a chair; an agent logs in, pulls data, drafts the report, and sends it for review.

Visual Workflows

Start here — scroll inside each diagram frame to explore, then use + / to zoom up to 200% if needed.

Overview

100%
Loading diagram...

Scroll inside the frame to explore · use + / − to zoom up to 200%

100%
Loading diagram...

Scroll inside the frame to explore · use + / − to zoom up to 200%

End-to-End Agent Runtime

100%
Loading diagram...

Scroll inside the frame to explore · use + / − to zoom up to 200%

User goal through bounded loop to final output — with guardrails and HITL.

Five Components Working Together

100%
Loading diagram...

Scroll inside the frame to explore · use + / − to zoom up to 200%

How brain tools memory planning and loop connect in one run.

Key Takeaways

  • 1.Agent = LLM reasoning + tools + memory + loop until goal is done.
  • 2.Chatbots answer once; agents observe, act, and iterate.
  • 3.Five components: brain, tools, memory, planning, orchestration.
  • 4.Production needs limits, guardrails, tracing, and human approval.

Real Example

Scenario

A sales VP asks: 'Summarize Q3 revenue by region and email the board.' The agent must query Snowflake, build a chart, draft the email, wait for approval, then send via Gmail.

What you would do

Break the goal into subtasks: (1) call `run_sql` on Snowflake for Q3 regional revenue, (2) pass rows to `create_chart`, (3) draft the email with the chart attached, (4) pause at a human-approval gate because `send_email` is destructive, (5) send and return the message ID. Monitor: tool success rate, steps per task, and approval bypass attempts.

Practice Task

Pick one recurring task from your work (weekly report, ticket triage, data pull). Write 5–7 agent loop steps, name the tool for each step, and mark where human approval is required.

Code Walkthrough

Highlighted lines show where What is an AI Agent? happens in the code.

What is an AI Agent?
1from openai import OpenAI  # import dependencies2
3client = OpenAI()  # create API client4tools = [5    {"type": "function", "function": {"name": "run_sql", "parameters": {"type": "object", "properties": {"query": {"type": "string"}}}}},6    {"type": "function", "function": {"name": "send_email", "parameters": {"type": "object", "properties": {"to": {"type": "string"}, "body": {"type": "string"}}}}},7]8
9messages = [{"role": "user", "content": "Summarize Q3 revenue by region and email the board"}]10MAX_STEPS = 811
12for step in range(MAX_STEPS):13    response = client.chat.completions.create(  # core API call for What is an AI Agent?14        model="gpt-4o-mini",15        messages=messages,16        tools=tools,17    )18    msg = response.choices[0].message19    if not msg.tool_calls:20        print("Final:", msg.content)  # show output for debugging21        break22    # Execute tool, append result, loop again23    messages.append(msg)24    messages.append({"role": "tool", "tool_call_id": msg.tool_calls[0].id, "content": '{"rows": [...]}'})

Cheat Sheet

Quick recap

quick ref
  • Agent = LLM + Tools + Memory + Loop
  • Observe → Reason → Act → Update → Repeat
  • max_iterations + cost budget required
  • Trace every step for debugging
  • Human approval for writes and deletes
  • Sandbox tool execution in production

Common Mistakes

  • No iteration limit on the agent loop
  • Unrestricted tool access without sandboxing
  • Treating agents as single-turn chatbots