Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
LLMOps for AI Agents: Observability and Cost Control
New

LLMOps for AI Agents: Observability and Cost Control

LLMOps in Python: trace, price and fix LLM agents with OpenTelemetry, Langfuse and LiteLLM. Real runs, no keys.
Created byAdi Tejus
Last updated 11/2026
English

What you'll learn

  • Instrument an LLM agent with OpenTelemetry spans that follow the GenAI semantic conventions for models, tools and agents
  • Trace sessions, users and tenants in Langfuse with scores, prompt versions and masking, and upgrade the SDK safely
  • Calculate cost per request, session, tenant and feature, and report cost per resolved session that finance accepts
  • Cut a day's LLM bill by two thirds with prompt caching and a context diet, proven by replaying the same day
  • Stop runaway agent loops with a step limit, a tool-retry bound and a deadline, and see each guard in the trace
  • Add LiteLLM fallbacks, latency-budget timeouts and per-department budgets that degrade before they refuse
  • Run a sampled LLM-as-judge, read user feedback honestly and catch drift between two weeks of traffic
  • Investigate incidents from traces alone, prove the fix with a replay and gate pull requests on cost and latency in CI

Course content

10 sections • 10 lectures • 3h 32m total length
  • Welcome: a $1.23 agent loop, and what you will build9:28

    The opening real run: one question, a broken ticket tool and a loop that cost $1.23, then the same question with one guard. Monitoring versus observability, the three pillars for agents (traces, cost, quality), Atlas and the traffic simulator, and the plan for the course. The full course code is attached to this lecture as a download.

  • Quiz: Welcome: the $1.23 question

Requirements

  • Basic Python: functions, decorators, virtual environments and running scripts in a terminal
  • A computer with Python 3.11 or newer (Windows, macOS or Linux). No GPU and no Docker needed
  • No API key needed: everything runs offline. Optional later: an OpenAI key with a spending cap and a Langfuse Cloud project

Description

This course contains the use of artificial intelligence.

One question to an AI helpdesk agent cost $1.23, on one of the cheapest models, and the employee never got an answer. The ticket system was down, the agent retried the tool again and again, and every retry re-read all the earlier ones. With one guard switched on, the same question costs about a fifth of a cent. This course teaches you to see that happening, explain it, put a price on it and stop it.

The whole course uses one project: Atlas, the internal IT and HR helpdesk agent of a made-up company, Northwind Logistics, with four departments (tenants), each with its own bill and budget. A deterministic traffic simulator replays a full working day (4,000 conversations, more than 10,000 requests) and can inject problems: a runaway loop, a slow model provider, a bad prompt change, a retrieval change that bloats every prompt. Everything runs offline with a mock model that gives realistic token counts, prices and latency, so you need no API key and no credit card. Switch to a real model when you are ready.

What you will build and run

  • Tracing with OpenTelemetry: a resource, a sampler, a bounded batch processor and exporters that fail safely, and span names and attributes that follow the GenAI semantic conventions so any backend understands them.
  • Langfuse on top: sessions, users, tenants, scores, prompt versions with labels and masking of personal data, plus a real Langfuse v4 to v5 upgrade: what broke and how it was fixed.
  • Agent loops: a step limit, a tool-retry bound and a deadline, each visible as an event in the trace.
  • Cost per resolved session: price every token, roll cost up by tenant, feature and model, produce a showback report, and cut a replayed day from $14.56 to $4.94 with prompt caching and a context diet, with the judge score unchanged.
  • Routing, fallbacks and budgets: a real LiteLLM Router with a tested fallback, a timeout derived from your latency budget (a slow provider's p95 from 8.8 s back to 3.8 s) and per-department budgets that degrade before they refuse.
  • Online evaluation: an LLM judge on a sample of live traffic, user feedback, drift between two weeks and a dataset built from real failures.
  • Incident response: three incidents investigated from traces alone, each fix proven by replaying the day, and a CI budget gate that fails the bad change in seconds.

How the course works

Every command is run for real on screen, on a small 2-core machine, and the exact command with its full output ships as a log next to the course code, so you can compare your numbers line by line. Library versions were checked on Oct 30, 2026 and model prices on Oct 31, 2026; the course shows how to re-check them on the day you use them. The narration uses an AI-generated voice of the instructor. All people, companies and data in the examples are made up.

The course is about 3.5 hours of video in 10 sections. Each hands-on section has a one-page cheat sheet (PDF), a quiz, a practical with starter and solution files and an assignment with a model answer, and the course ends with a capstone. The full course code is attached to the first lecture.

Who this course is for:

  • Python developers who built an LLM agent or chatbot and now need to answer: what does it cost, why is it slow, is it still good?
  • AI and ML engineers moving into LLMOps or AI platform roles
  • Backend, platform and SRE engineers asked to cover LLM workloads with OpenTelemetry
  • Tech leads who need cost per resolved session, budgets and an incident process for their agents