AI agent tutorial: build a site doctor that checks your website in 15 minutes

A few days ago I thought I knew what an AI agent was. A personal assistant, basically. You tell it “remind me of this”, “book me a table”, “check my server every five minutes”, and it does the chores. Then we sat down and built one, and I found out I had it half right.
The chores part is just scheduling. A script that checks a server every five minutes has existed since the nineties. What makes something an agent is that it decides what to do next by itself. You give it a goal and a few tools, it uses a tool, looks at the result, and picks the next step. Nobody writes the steps for it.
So in this tutorial we’ll build a small one: a site doctor. You give it a website, it opens pages, checks the security certificate and the DNS, follows its own hunches, and writes you a short diagnosis in plain words. It only looks. It can’t change anything on your server, which makes it a very safe first agent.
What you need
About 15 minutes, Python 3.10 or newer, and an API key from the Claude Console (console.anthropic.com). Make a dedicated key for this project so you can delete it later without breaking anything else. A run usually costs well under a dollar.
Step 1: set up the folder
mkdir site-doctor && cd site-doctor
python3 -m venv .venv
.venv/bin/pip install anthropic
You should see pip install the anthropic package and a few small dependencies. That’s the only library we need. Everything else comes with Python.
Step 2: give it the key, safely
Never paste the key into the code, a chat or a file you might share. Put it in an environment variable for this terminal session:
read -s ANTHROPIC_API_KEY && export ANTHROPIC_API_KEY
Paste the key and press Enter. Nothing shows on screen, and that’s on purpose. On a Mac you can go one better and keep it in the Keychain (security add-generic-password -s site-doctor -w), then read it back with security find-generic-password -s site-doctor -w each time.
Step 3: the whole agent
Create a file called site_doctor.py and paste this. It’s about 80 lines, and it has exactly three parts.
import json, socket, ssl, sys, time, urllib.error, urllib.request
from datetime import datetime, timezone
import anthropic
# ---------- the tools: the agent's eyes (they only look, they never change anything)
def check_page(url):
start = time.time()
req = urllib.request.Request(url, headers={"User-Agent": "site-doctor"})
try:
with urllib.request.urlopen(req, timeout=20) as r:
body, status, final_url = r.read(400_000).decode("utf-8", "replace"), r.status, r.url
except urllib.error.HTTPError as e:
body, status, final_url = e.read(50_000).decode("utf-8", "replace"), e.code, e.url
except Exception as e:
return {"url": url, "error": str(e)}
clues = [w for w in ("fatal error", "database connection", "warning:", "maintenance") if w in body.lower()]
return {"url": url, "final_url": final_url, "status": status,
"seconds": round(time.time() - start, 2), "error_clues": clues}
def check_certificate(host):
try:
ctx = ssl.create_default_context()
with socket.create_connection((host, 443), timeout=10) as sock:
with ctx.wrap_socket(sock, server_hostname=host) as s:
cert = s.getpeercert()
expires = datetime.strptime(cert["notAfter"], "%b %d %H:%M:%S %Y %Z").replace(tzinfo=timezone.utc)
return {"host": host, "valid": True, "days_left": (expires - datetime.now(timezone.utc)).days}
except Exception as e:
return {"host": host, "valid": False, "error": str(e)}
def check_dns(host):
try:
return {"host": host, "ips": sorted({a[4][0] for a in socket.getaddrinfo(host, 443)})}
except Exception as e:
return {"host": host, "error": str(e)}
RUN = {"check_page": check_page, "check_certificate": check_certificate, "check_dns": check_dns}
TOOLS = [
{"name": "check_page", "description": "Open a URL. Returns HTTP status, final URL after redirects, load time in seconds and any error text found in the page.",
"input_schema": {"type": "object", "properties": {"url": {"type": "string"}}, "required": ["url"]}},
{"name": "check_certificate", "description": "Check the HTTPS certificate of a domain (e.g. example.com): valid or not, days left before it expires.",
"input_schema": {"type": "object", "properties": {"host": {"type": "string"}}, "required": ["host"]}},
{"name": "check_dns", "description": "Look up the IP addresses a domain points to.",
"input_schema": {"type": "object", "properties": {"host": {"type": "string"}}, "required": ["host"]}},
]
# ---------- the instructions: the job description
SYSTEM = """You are a website doctor. Check the site you are given with your tools: the home page first,
then a few important pages you discover, the certificate and DNS. Decide yourself what to check next.
You can only look, you cannot change anything.
Then write a short report in plain words: overall health, what you checked, problems, likely causes,
and fixes the owner can apply. End with one line that is exactly STATUS: OK or STATUS: PROBLEM."""
# ---------- the loop: the brain at work
def diagnose(site):
client = anthropic.Anthropic() # reads the ANTHROPIC_API_KEY environment variable
messages = [{"role": "user", "content": f"Please check {site} and give me your report."}]
for step in range(1, 11): # safety cap: at most 10 rounds
response = client.messages.create(model="claude-opus-5-5", max_tokens=16000,
system=SYSTEM, tools=TOOLS, messages=messages)
messages.append({"role": "assistant", "content": response.content})
calls = [b for b in response.content if b.type == "tool_use"]
if not calls: # it wants no more tools: this is the report
return "".join(b.text for b in response.content if b.type == "text")
results = []
for call in calls:
print(f"[step {step}] {call.name}({json.dumps(call.input)})")
output = RUN[call.name](**call.input)
results.append({"type": "tool_result", "tool_use_id": call.id, "content": json.dumps(output)})
messages.append({"role": "user", "content": results})
return "Stopped after 10 rounds without a report.\nSTATUS: PROBLEM"
if __name__ == "__main__":
site = sys.argv[1] if len(sys.argv) > 1 else input("Which site should I check? ")
if not site.startswith("http"):
site = "https://" + site
print("\n" + diagnose(site))
Here’s what each part does.
The tools are plain Python functions. check_page opens a URL and times it, check_certificate reads the HTTPS certificate, check_dns looks up the server address. The TOOLS list describes them to Claude in words, and those descriptions matter more than you’d think. Claude never runs anything itself. It says “please run check_page on /blog/”, our script runs it, and the result goes back.
The instructions are a short job description. Notice what’s not there: no list of pages, no order of checks. Just the goal, the limits (“you can only look”) and the shape of the report.
The loop is what turns this into an agent. We send the conversation to Claude. If it asks for tools, we run them, add the results to the conversation and send it again. When it stops asking for tools, whatever it wrote is the report. There’s a cap of 10 rounds so a confused agent can’t run forever.
Step 4: run it
.venv/bin/python site_doctor.py example.com
You’ll see its steps as it works, then the report. Here’s part of our first real run on our own site:
[step 1] check_page({"url": "https://coderaas.com/"})
[step 1] check_certificate({"host": "coderaas.com"})
[step 1] check_dns({"host": "coderaas.com"})
[step 2] check_page({"url": "https://coderaas.com/blogs/"})
[step 2] check_page({"url": "https://coderaas.com/fr/"})
[step 2] check_page({"url": "https://coderaas.com/contact/"})
[step 2] check_dns({"host": "www.coderaas.com"})
[step 3] check_page({"url": "https://www.coderaas.com/"})
[step 3] check_certificate({"host": "www.coderaas.com"})
[step 3] check_page({"url": "https://coderaas.com/contact-us/"})
Look at step 3. Nobody told it to check the www version. It saw www in the DNS results and decided to check that page and its certificate too. When /contact/ failed, it tried /contact-us/ on its own. That’s the “decides by itself” part, happening in front of you.
What surprised us
It found a real problem. Our French and Arabic home pages were loading in about 2 seconds while English took 1.2. In the first run it guessed “fonts or cache”, which was wrong.
Better tools, better diagnosis. We added one thing to check_page: report the final URL after redirects. Same loop, same instructions. On the next run it spotted that /fr/ and /ar/ were redirecting to another page first, which explained the extra second. Same brain, better eyes.
It’s honest about what it can’t see. Before that change, it said it couldn’t tell whether http redirects to https, instead of making something up.
It still needs a human. It once guessed the name of a caching plugin we don’t use, and it guessed our contact link wrong. Read the report, don’t obey it blindly.
It doesn’t take the same path twice. Run it again and it may pick different pages. That’s normal for an agent.
Common problems
“Could not resolve authentication method”: the key isn’t in this terminal. Run step 2 again, in the same window you run the script from.
A certificate error on your Mac for every site: Python from python.org needs its certificates installed once. Run “Install Certificates.command” from the Python folder in Applications.
It stops after 10 rounds: the site is big or very broken. Raise the cap a little, or give it a more specific goal like “only check the blog”.
Where to go from here
You can add a fourth tool the same way. We added an SEO check (title, description, headings, sitemap), and the report grew a short SEO section without changing the loop at all. That’s the nice thing about this shape: new skills are just new tools.
At this point it’s a script you run. For us, the moment it started checking our site every morning and only bothering me when something was actually wrong, it became something else: an agent on duty.
Want it to run without your computer on? Here’s the next tutorial: GitHub Actions, a small server or AWS Lambda, and a bonus way to call it from any Claude chat on your phone.
If you’d like an agent like this built around your own systems, get in touch.