📊 View Lecture Slides Full-screen presentation with navigation

Session 10: Introduction to AI Agents

Session Duration: 2 Hours     Block: 3 — Agents, Evaluation & Deployment

Learning Objectives

By the end of this session, students will be able to:

  • Distinguish between a reactive AI application (chatbot) and an agentic AI system
  • Describe the agent loop: perceive → plan → act → observe → repeat
  • Delegate a multi-step task to an AI agent and verify the generated artifacts
  • Identify the risks of autonomous AI systems and apply appropriate safeguards

Hour 1: From Chatbots to Agents (Instructor-Led — 60 minutes)

1.1 What Makes a System “Agentic”?

A chatbot responds to a single message. An agent pursues a goal across multiple steps.

The difference is autonomy: an agent decides what to do next based on previous results. It is not waiting for you to tell it each step.

Example comparison:

Chatbot:

  • User: “Write me a Python function that reads a CSV file”
  • AI: [produces one function]
  • Done.

Agent:

  • User: “Build me a data analysis script for this CSV file”
  • AI Step 1: Reads and analyses the CSV structure
  • AI Step 2: Decides what analyses would be useful
  • AI Step 3: Generates a data cleaning function
  • AI Step 4: Generates an analysis function
  • AI Step 5: Generates a visualisation
  • AI Step 6: Combines everything into a script and verifies it runs
  • Done.

The agent completed six sub-tasks that the user would otherwise have had to direct individually.

1.2 The Agent Loop

PERCEIVE: What is the current state? (user goal, environment, previous results)
    ↓
PLAN: What action should I take next to make progress toward the goal?
    ↓
ACT: Execute the action (call a function, write code, search, call an API)
    ↓
OBSERVE: What happened? Did the action succeed? What is the new state?
    ↓
REPEAT until the goal is achieved or a stopping condition is met

This loop is conceptually simple, but implementing it reliably is non-trivial. Agents can get stuck in loops, make incorrect assumptions, or take irreversible actions.

1.3 Types of Agent Actions

Agents can perform actions beyond just generating text:

  • Code execution: Write and run code, observe the output
  • Tool calling: Call external APIs, search the web, query databases (Session 11)
  • File operations: Read, write, and manage files
  • Sub-agent delegation: Create and direct other AI agents for specialised tasks

1.4 Safeguards for Autonomous AI

The more autonomous the agent, the higher the risk of unintended consequences. Critical safeguards:

Human-in-the-loop checkpoints: For any irreversible action (sending an email, writing to a database, making an API call that costs money), require explicit human approval before proceeding.

Artifact verification: Before accepting an agent’s output (especially code), verify it:

  • Does it run without errors?
  • Does it produce the expected output on test inputs?
  • Does it handle edge cases correctly?

Scope limits: Constrain what the agent can access. An agent that reads your email should not also have write access to your file system.

Logging and auditability: Every action the agent takes should be logged with sufficient detail to diagnose what happened when something goes wrong.


Hour 2: Practical — Delegate a Multi-Step Task (60 minutes)

Lab 10.1 — Agentic Task Decomposition

Choose a multi-step task relevant to your project. It should require 3–6 distinct steps to complete.

Example tasks:

  • “Research the top 5 RAG frameworks, summarise each, and produce a comparison table”
  • “Take this user story and generate: a requirements list, a data model, and a test plan”
  • “Analyse this dataset: identify patterns, suggest three insights, and generate visualisation code”

Write out the steps the agent would need to take before executing. This is the plan the agent will follow.

Lab 10.2 — Sequential Agent Prompting

Implement a simple sequential agent using a series of AI calls, where the output of each step becomes part of the context for the next:

def run_agent_task(goal: str) -> dict:
    """Simple sequential agent that executes a multi-step plan."""
    steps = []
    context = f"Goal: {goal}\n\n"

    # Step 1: Plan
    plan_prompt = f"{context}List the 4-5 specific steps needed to complete this goal. Number each step."
    plan = call_ai(plan_prompt)
    steps.append({'step': 'PLAN', 'output': plan})
    context += f"Plan:\n{plan}\n\n"

    # Step 2: Execute each planned step
    step_num = 1
    while step_num <= 4:  # bounded loop
        exec_prompt = f"{context}Execute step {step_num} of the plan. Produce the complete output for this step only."
        output = call_ai(exec_prompt)
        steps.append({'step': f'EXECUTE_{step_num}', 'output': output})
        context += f"Step {step_num} output:\n{output}\n\n"
        step_num += 1

    # Step 3: Synthesise
    synth_prompt = f"{context}Combine all step outputs into a final, coherent deliverable."
    final = call_ai(synth_prompt)
    steps.append({'step': 'SYNTHESISE', 'output': final})

    return {'steps': steps, 'final_output': final}

Lab 10.3 — Verify the Artifacts

Run the agent on your chosen task. For each output:

  1. Read it carefully. Is it accurate?
  2. If it generated code, run it. Does it work?
  3. If it generated text, verify at least one factual claim.
  4. What would go wrong if you used this output without checking?

Document your findings in your vault under 03-Project/Agent-Notes.md.


Key Takeaways

  • Agents pursue multi-step goals autonomously via a perceive → plan → act → observe loop
  • The key difference from a chatbot is autonomous sequencing of actions based on previous results
  • Safeguards — human-in-the-loop checkpoints, scope limits, and logging — are non-negotiable
  • Always verify agent-generated artifacts before using them
  • A simple sequential agent using chained AI calls is already a powerful productivity tool

Further Reading

  • “ReAct: Synergizing Reasoning and Acting in Language Models” (Yao et al., 2022)
  • LangChain Agents documentation
  • “Risks from Learned Optimization” — AI safety background