What FastAPI is, and why it fits agent backends
What FastAPI actually is
FastAPI is a Python web framework, but it’s worth naming precisely what it’s built on, since both pieces matter directly to this course: it’s built on Starlette (an ASGI framework handling the actual HTTP mechanics) and Pydantic (for request/response validation — the exact library from earlier in this course).
ASGI (Asynchronous Server Gateway Interface) is the modern successor
to WSGI (what older frameworks like Flask were originally built on)
— the key difference being ASGI is async-native from the ground up,
which is exactly what makes async def routes, covered later in this
lesson, possible at all. A WSGI-based framework can’t natively support
the concurrent-request-handling model
Lesson 7 built up from scratch.
A minimal app
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "agent backend running"}app = FastAPI() creates the application instance. @app.get("/") is
— worth saying plainly —
just a decorator,
doing familiar work in a new context: it registers read_root to run
whenever a GET request arrives at the path /. Returning a plain
dict is enough — FastAPI serializes it to JSON automatically.
Running it: uvicorn
FastAPI itself doesn’t run a server — it defines what should happen
for a given request; something else has to actually listen on a port and
call it. uvicorn is the standard ASGI server used to run a FastAPI app:
click Run to see this pane's outputmain:app means “in main.py, find the object named app” — the
FastAPI() instance from above. --reload restarts the server
automatically whenever a source file changes, useful during development
so you don’t have to manually stop and restart after every edit. Hitting
http://127.0.0.1:8000/ in a browser works the same way curl does
above — this is a real, network-reachable server now, not just a
function you’d call directly.
Why this fits agent backends specifically
This isn’t an arbitrary framework choice for this course — three things about FastAPI line up directly with what this course has already built:
- Automatic validation is Pydantic, the exact library from Lesson
5 — a request body typed as a
BaseModelgets validated before your route function ever runs, the identical mechanism that closed the validation gap back then, just now validating an incoming HTTP request instead of a config file. - Async routes are Lesson 7’s
async def/await, directly — an agent backend that calls an LLM API, or fans out to multiple tools per request, is exactly the I/O-bound situationasynciowas built to handle, and FastAPI’s ASGI foundation means that’s a first-class, natively supported way to write a route, not a workaround. - A route is genuinely just a decorator applying to a function — the exact mechanism from Lesson 4, now doing the work of wiring up an HTTP endpoint instead of logging or counting calls.
None of the rest of this lesson is teaching unfamiliar mechanisms —
decorators, Pydantic models, async/await are all already yours. It’s
teaching how those mechanisms compose into something that serves an
actual, network-reachable API.
What two things is FastAPI built on top of?