# Agent Bricks Lifecycle Console (FastAPI)

## PURPOSE
The Databricks Agent Bricks demo walks through a six-stage production loop:
index a Delta table with a vector search index that uses **managed embeddings**,
build the agent as code, trace it with MLflow, register it to Unity Catalog,
evaluate it, and deploy it to a real-time endpoint with a review app for human
feedback. This project turns that loop into a small FastAPI service so every
stage is an explicit, testable HTTP entry point instead of a sequence of clicks
inside a notebook.

## WHY THIS MATTERS
The transcript's central claim is the *agent-as-code* pattern: "keeping the
agent in code rather than clicking it together is what makes it reviewable,
versionable, and deployable later." A service that exposes index -> build ->
trace -> register -> evaluate -> deploy as endpoints makes that claim concrete.
Each transition is now a request you can log, gate in CI, and audit — and the
same shape works "whether you're building a weekend prototype or something that
serves real traffic."

## HOW TO BUILD
1. Define Pydantic models for each stage's request/response (`IndexRequest`,
   `EvalRequest`, `StageResult`).
2. Add a `LIFECYCLE` list mirroring the demo's six stages in order.
3. Wrap each Databricks call (vector index create, agent load, Unity Catalog
   register, model-serving deploy) behind a thin client function.
4. Return deterministic stubs where a live workspace is unavailable.

Key snippet — the stage runner that keeps the loop honest:

```python
@app.post("/lifecycle/run")
def run_lifecycle(req: LifecycleRequest) -> list[StageResult]:
    results = []
    for stage in LIFECYCLE:
        fn = STAGE_HANDLERS[stage]
        results.append(StageResult(stage=stage, ok=True,
                                   detail=fn(req)))
    return results
```

## WHEN TO USE IN PRODUCTION
Use it as a **control plane** for a platform team: notebooks, CI jobs, or an
internal UI call it to promote an agent version across the six stages. Do NOT
put this in the request path of user traffic — the deployed agent belongs on a
Databricks model-serving endpoint behind the review app; this service only
orchestrates and records. Skip it for one-off experiments where a notebook is
already fast enough.

## HOW IT HELPS STUDENTS
Students learn to separate control plane from data plane, to model a
multi-stage deployment lifecycle as pure API contracts, and to write FastAPI
services with Pydantic validation. They practise the exact vocabulary the
video uses — index, build, trace, register, evaluate, deploy — and see how
"reviewable and versionable" translates into typed endpoints and CI gates.

## STARTER CODE
See `starter/main.py` for a runnable FastAPI skeleton with deterministic
stubs for each stage and `# TODO` markers where real Databricks SDK calls go.
