Suffolk University • Sawyer Business School

Agents Meet the Real World

Real APIs, error handling, memory — take your agents from simulated toys to production-ready tools

Session 5 of 13
150 Minutes
40 Students
Hands-On Learning
01 // LEARNING OBJECTIVES

What You'll Learn Today

By the end of this session, you'll have both conceptual understanding and hands-on experience with the foundations of AI.

01

Connect Agents to Real APIs

Replace simulated tools with live data sources. Build a Wikipedia search tool and a web page fetcher that work with real HTTP requests.

02

Handle Real-World Failures

Build agents that gracefully handle 404s, timeouts, and bad input — instead of crashing, they adapt and try alternatives.

03

Give Agents Memory

Implement conversation history so your agent remembers context across turns. Understand why memory is just a list — and why that matters.

04

Iterate Your Session 4 Product

Apply real tools, error handling, and memory concepts to upgrade the product and agent you built last session.

02 // SESSION AGENDA

Today's Journey

A carefully crafted progression from concepts to hands-on building.

5:00 PM - 5:15 PM

Part 1: NanoClaw Live Demo

15 minutes

See a production AI agent in action — the theory from Session 4 running in the real world.

  • LIVE DEMO: Send a WhatsApp message to NanoClaw, watch it reason and respond in real-time
  • Code highlights: How index.ts, ipc-mcp.ts, and db.ts work together (Session 4 overflow)
  • Key observation: Real agents deal with real problems — network delays, bad input, context limits
  • The gap: Your Session 4 agent used fake data. Today we close that gap.
5:15 PM - 5:35 PM

Part 2: From Fake to Real

20 minutes

Why simulated tools aren't enough, and how to connect agents to the real world.

  • The problem: Your Session 4 stock tool returns the SAME price every time. Real data changes.
  • Real APIs 101: What is an API endpoint? HTTP requests. JSON responses. Status codes.
  • Wikipedia API: Free, no key needed, returns structured summaries — perfect first real tool
  • Web fetching: requests + BeautifulSoup = read any web page programmatically
  • ACTION: Open Colab now, run Setup cells while I talk
5:35 PM - 6:20 PM

Part 3: Hands-On — Real-World Agent

45 minutes

Build an agent with real tools that fetches live data from the internet.

  • 5:35-5:45 — Bring back the calculator from Session 4 + the run_agent() loop as foundation
  • 5:45-5:55 — Build Wikipedia search tool: live API, real data, error handling for 404s
  • 5:55-6:10 — Build web page fetcher: requests + BeautifulSoup, timeout handling, text truncation
  • 6:10-6:20 — Multi-tool challenge: Ask questions that require calculator + Wikipedia + web fetch together
6:20 PM - 6:30 PM

Break

10 minutes

Stretch, grab coffee. Your agent now talks to the real internet.

6:30 PM - 6:50 PM

Part 4: Agent Memory

20 minutes

The missing piece — agents that remember what you said 5 minutes ago.

  • THE PROBLEM: Ask 'Who founded Tesla?' then 'How old is he?' — agent forgets everything
  • The fix: Conversation history = just a list of messages. That's it. Memory demystified.
  • LIVE CODING: run_agent_with_memory() — maintains context across turns
  • Multi-turn test: research → follow-up → calculation chain
  • Trade-offs: More memory = more tokens = more cost. When to forget on purpose.
6:50 PM - 7:10 PM

Part 5: Product Iteration Workshop

20 minutes

Apply what you learned to upgrade your Session 4 product.

  • Review: Session 4 = simulated tools. Session 5 = real APIs + errors + memory.
  • Exercise: Pick one real API that would make your Session 4 product actually useful
  • Design: What errors could happen? How should your agent handle them?
  • Memory: Does your product need multi-turn conversation? Why or why not?
  • Share: 60-second pitch of your upgraded product concept to a neighbor
7:10 PM - 7:30 PM

Part 6: Wrap-Up + Homework

20 minutes

From consumer to builder to architect — and the journey ahead.

  • The arc: Session 4 built agents with fake tools → Session 5 connected them to the real world
  • You learned 3 production essentials: real APIs, error handling, conversation memory
  • Next session: Agent Patterns & Production Intelligence — ReAct reasoning, multi-agent architectures, and MCP. The patterns that power NanoClaw.
  • Homework preview: Add a real API tool to your agent, test edge cases, design memory strategy
03 // INTERACTIVE RESOURCES

Tools & Learning Materials

Everything you need to explore, experiment, and build.

Hands-On

Real-World Agent Notebook (Claude)

Build an agent with real APIs: Wikipedia search, web page fetcher, error handling, and conversation memory. Uses Claude/Anthropic SDK.

Open in Colab
Hands-On

Real-World Agent Notebook (Gemini)

Same real-world agent workshop using Google Gemini. Identical tools and structure — different LLM backend. Requires a Google API key.

Open in Colab
Review

Agentic AI Deep-Dive

Visual explainer from Session 4: Chatbot vs Agent, the Agent Loop, and the NanoClaw case study. Review before diving into real APIs.

View deep-dive
Docs ?

Wikipedia REST API Docs

Free, no-key API for page summaries, search, and more. The real API your agent uses in today's workshop.

Read docs
Docs ?

Beautiful Soup Documentation

Python library for parsing HTML and extracting text from web pages. Powers the web fetcher tool in today's notebook.

Read docs
Docs ?

Anthropic Tool Use Docs

Official documentation for giving Claude tools. The foundation of building AI agents with the Anthropic API.

Read docs
Tool ?

Google Colab

Free cloud-based Python notebooks. No installation needed — just open and start coding.

Open Colab
04 // HANDS-ON ACTIVITIES

Learning by Doing

Three interactive challenges to build your intuition.

? Activity 1

Real-World Agent Workshop

Build an agent that connects to live APIs — real data, real errors, real power:

1

Bring Back the Foundation (10 min)

Copy the calculator tool and run_agent() loop from Session 4. Verify everything works before adding new tools.

2

Wikipedia Search Tool (10 min)

Build a tool that queries the Wikipedia API for any topic. Handle 404s for pages that don't exist. Test with 'Suffolk University' and 'artificial intelligence'.

3

Web Page Fetcher (15 min)

Build a tool that fetches any URL, extracts text with BeautifulSoup, and truncates to 3000 chars. Handle timeouts and connection errors.

4

Multi-Tool Challenge (10 min)

Ask questions that need all 3 tools: 'Look up Suffolk University on Wikipedia, then visit their website and calculate how many years they've been open.'

python
import requests

def wikipedia_search(topic: str) -> str:
    """Search Wikipedia for a topic — REAL API!"""
    url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{topic}"
    try:
        response = requests.get(url, timeout=10)
        if response.status_code == 404:
            return f"No Wikipedia page found for '{topic}'."
        data = response.json()
        return json.dumps({
            "title": data.get("title", ""),
            "summary": data.get("extract", ""),
            "url": data.get("content_urls", {}).get("desktop", {}).get("page", "")
        })
    except requests.exceptions.Timeout:
        return "Error: Request timed out."
Activity 2

Agent Memory Lab

Give your agent the ability to remember — and understand why it matters:

1

See the Problem (3 min)

Ask 'Who founded Tesla?' then 'How old is he?' — watch the agent fail because it has no memory of the first question.

2

Build Memory (7 min)

Implement run_agent_with_memory() that maintains a conversation history list. Memory is just a list — that's the key insight.

3

Multi-Turn Test (5 min)

Chain 3+ questions: research a topic → ask follow-up → request a calculation based on previous answers.

4

Memory Trade-offs (5 min)

Discuss: More memory = more tokens = more cost. When should an agent forget? How does NanoClaw handle this?

python
def run_agent_with_memory(user_message, tools, tool_functions,
                         conversation_history=None):
    """
    Agent with memory! Maintains conversation history
    across multiple turns.
    """
    if conversation_history is None:
        conversation_history = []

    # Add new user message to history
    conversation_history.append(
        {"role": "user", "content": user_message}
    )

    # Send FULL history to LLM (that's the memory!)
    # ... same agent loop, but with conversation_history
    # instead of a single message

    return final_answer, conversation_history
? Activity 3

Product Iteration Workshop

Apply real-world concepts to upgrade your Session 4 product:

1

Pick a Real API (5 min)

What real data source would make your product actually useful? Weather, news, maps, stocks, recipes? Find one that's free and doesn't need a key.

2

Design Error Handling (5 min)

List 3 things that could go wrong with your real API. How should your agent respond to each failure? Write the fallback messages.

3

Memory Strategy (5 min)

Does your product need multi-turn conversation? What should it remember? What should it forget? Write a 3-sentence memory strategy.

4

60-Second Pitch (5 min)

Tell a neighbor: 'My product now uses [real API] to [do what]. It handles [these errors] and remembers [this context].'

05 // KEY TAKEAWAYS

What to Remember

?

Real APIs change everything. Simulated tools are training wheels. Today you connected your agent to Wikipedia and the live web — real data, real value.

Errors are features, not bugs. Production agents don't crash on 404s — they adapt. You built agents that handle timeouts, missing pages, and bad input gracefully.

Memory is just a list. Conversation history isn't magic — it's appending messages to a list and sending the full list each time. Simple concept, massive impact.

Session 4 → Session 5 → Session 6. Fake tools → real APIs → production patterns. Each session builds on the last. Next session adds ReAct reasoning, multi-agent, and MCP.

?

The business decision is which APIs to connect. The agent loop is ~50 lines. The value is in choosing the right data sources and designing how your agent handles the messy real world.

06 // HOMEWORK

Before Next Session

Complete these tasks before our next class to prepare for prompt engineering.

Build: Add a new real API tool to your notebook (weather, news, recipes, etc.). It must be a live API — no simulated data. Test it with 3 different queries.
Break: Deliberately trigger 3 different error conditions in your agent (bad URL, nonexistent page, timeout). Document how your agent handles each one.
Remember: Use run_agent_with_memory() to have a 5-turn conversation with your agent. Save the conversation and annotate where memory helped vs where it wasn't needed.
Design: Write a 1-page upgrade plan for your Session 4 product: which real APIs to add, what errors to handle, and your memory strategy.
Coming Next

Session 6: Agent Patterns & Production Intelligence

ReAct reasoning, multi-agent architectures, and the patterns that separate demos from production systems.

ReAct PatternMulti-Agent SystemsMCPBusiness Automation