AI Engineering in Practice8 min read
FastAPI lifespan for agentic services: startup and shutdown
Why FastAPI lifespan is the only right place for agent startup code. Per-worker initialization, ordered teardown, and the bugs it kills.
Loading...
Build Your First Software Factory Execution Harness live Thursday, Oct 1, 12:00 PM ET
Oct 1, Reserve a seatExplore our latest articles and insights about Production AI.
62 posts in total
AI Engineering in Practice8 min read
Why FastAPI lifespan is the only right place for agent startup code. Per-worker initialization, ordered teardown, and the bugs it kills.
AI Engineering in Practice9 min read
How async context managers prevent connection leaks in Python AI services. The lifespan, contextvars, and middleware patterns that survive load.
AI Engineering in Practice8 min read
How to wire LangGraph into a FastAPI chatbot API with streaming, persistence, and per-user threads. The production pattern that scales past demos.
AI Engineering in Practice9 min read
How FastAPI Depends makes agent auth testable and composable. The pattern, the chain, and why module-level globals break at scale.
AI Engineering in Practice9 min read
How to persist agent state in Postgres so conversations survive restarts. The schema, the session writer, and the idempotency rule that prevents loss.
AI Engineering in Practice9 min read
How to Dockerize a production AI service with multi-stage builds, layer caching, and a 150 MB runtime image. The pattern that survives real deploys.
AI Engineering in Practice9 min read
How to parse environment variables in Python AI services without os.environ.get footguns. Pydantic Settings, type coercion, and the validation layer.
AI Engineering in Practice10 min read
How to structure an agentic AI codebase so it survives growth. The 4-layer pattern, the cut lines, and the refactor that keeps a project shippable.
AI Engineering in Practice10 min read
How to instrument an agentic AI service with Prometheus. The 4 metrics that matter, the histogram trap, and the dashboard that surfaces regressions.
LLM Engineering11 min read
Why linear LangChain chains fall over on real agents and how LangGraph's stateful graphs replace them. The state model, loops, and upgrade path.
AI Engineering11 min read
How circuit breakers prevent LLM outages from cascading through your agent. The 3 states, the failure window, and the 50-line implementation.
AI Engineering in Practice9 min read
How to survive LLM provider outages with Tenacity retries and fallback models. The retry policy, the fallback chain, and the 60-line pattern.