Real APIs, error handling, memory — take your agents from simulated toys to production-ready tools
By the end of this session, you'll have both conceptual understanding and hands-on experience with the foundations of AI.
Replace simulated tools with live data sources. Build a Wikipedia search tool and a web page fetcher that work with real HTTP requests.
Build agents that gracefully handle 404s, timeouts, and bad input — instead of crashing, they adapt and try alternatives.
Implement conversation history so your agent remembers context across turns. Understand why memory is just a list — and why that matters.
Apply real tools, error handling, and memory concepts to upgrade the product and agent you built last session.
A carefully crafted progression from concepts to hands-on building.
See a production AI agent in action — the theory from Session 4 running in the real world.
Why simulated tools aren't enough, and how to connect agents to the real world.
Build an agent with real tools that fetches live data from the internet.
Stretch, grab coffee. Your agent now talks to the real internet.
The missing piece — agents that remember what you said 5 minutes ago.
Apply what you learned to upgrade your Session 4 product.
From consumer to builder to architect — and the journey ahead.
Everything you need to explore, experiment, and build.
Build an agent with real APIs: Wikipedia search, web page fetcher, error handling, and conversation memory. Uses Claude/Anthropic SDK.
Open in ColabSame real-world agent workshop using Google Gemini. Identical tools and structure — different LLM backend. Requires a Google API key.
Open in ColabVisual explainer from Session 4: Chatbot vs Agent, the Agent Loop, and the NanoClaw case study. Review before diving into real APIs.
View deep-diveFree, no-key API for page summaries, search, and more. The real API your agent uses in today's workshop.
Read docsPython library for parsing HTML and extracting text from web pages. Powers the web fetcher tool in today's notebook.
Read docsOfficial documentation for giving Claude tools. The foundation of building AI agents with the Anthropic API.
Read docsFree cloud-based Python notebooks. No installation needed — just open and start coding.
Open ColabThree interactive challenges to build your intuition.
Build an agent that connects to live APIs — real data, real errors, real power:
Copy the calculator tool and run_agent() loop from Session 4. Verify everything works before adding new tools.
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'.
Build a tool that fetches any URL, extracts text with BeautifulSoup, and truncates to 3000 chars. Handle timeouts and connection errors.
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.'
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." Give your agent the ability to remember — and understand why it matters:
Ask 'Who founded Tesla?' then 'How old is he?' — watch the agent fail because it has no memory of the first question.
Implement run_agent_with_memory() that maintains a conversation history list. Memory is just a list — that's the key insight.
Chain 3+ questions: research a topic → ask follow-up → request a calculation based on previous answers.
Discuss: More memory = more tokens = more cost. When should an agent forget? How does NanoClaw handle this?
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 Apply real-world concepts to upgrade your Session 4 product:
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.
List 3 things that could go wrong with your real API. How should your agent respond to each failure? Write the fallback messages.
Does your product need multi-turn conversation? What should it remember? What should it forget? Write a 3-sentence memory strategy.
Tell a neighbor: 'My product now uses [real API] to [do what]. It handles [these errors] and remembers [this context].'
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.
Complete these tasks before our next class to prepare for prompt engineering.
ReAct reasoning, multi-agent architectures, and the patterns that separate demos from production systems.