Skip to content
2 min read · 391 words

Module 4: API & Business Logic

**Intermediate**  ·  **~35 min**  ·  **7 lessons**

Overview

This is where the models and services from Modules 2–3 become an actual HTTP API. You'll walk every one of the 20 endpoints across routers/agents.py (937 lines — the largest file in the backend) and routers/documents.py, including a real, verified bug found by reading the source rather than running it. Then dependency injection, the current (non-existent) auth story, and how an "AI agent" is really just configuration data.

What You'll Learn

  • All 20 endpoints, their request/response schemas, and the pattern every one of them follows
  • The 7 module-level helper functions in routers/agents.py and what each one does
  • How FastAPI's Depends() actually works — and the one dependency this codebase actually uses
  • Why there's no authentication today, and what adding JWT/OAuth2 would look like
  • The tool-gating pattern (enabled_tools + agent_has_tool()) that stands in for real authorization

Prerequisites

Lessons in This Module

#LessonWhat it covers
09API Routers OverviewAll 20 endpoints, the shared pattern
09aAgents Router Deep DiveAll 15 endpoints + 7 helpers, including a verified bug
09bDocuments Router Deep DiveAll 5 endpoints: upload, search, corrective-RAG ask
10Dependency InjectionDepends(), and the one real dependency here
11AuthenticationCurrent state (none), how JWT/OAuth2 would fit
12Multi-Agent WorkflowsThe email workflow's sequential orchestration
13AI AgentsThe Agent model, tool gating, and what "tool calling" means here

Learning Outcomes

By the end of this module you can:

  • List all 20 endpoints and their HTTP methods from memory
  • Explain exactly what's wrong with GET /agents/{id}/stats and why it can't succeed
  • Explain why get_db is the only real FastAPI dependency in this codebase
  • Explain the difference between OpenAI-native tool calling and this codebase's enabled_tools pattern

Start Module → Back to Module 3