|
| 1 | +--- |
| 2 | +title: 'Observe, evaluate, and secure your agents' |
| 3 | +lab: |
| 4 | + title: 'Observe, evaluate, and secure your agents' |
| 5 | + description: 'Find out what your Tailwind Traders agent is actually doing: trace it with OpenTelemetry, score its answers against ground truth with built-in evaluators, and attack it with the AI Red Teaming Agent. A modular lab you can complete end to end or one task at a time.' |
| 6 | + type: 'lab' |
| 7 | + id: 'D' |
| 8 | + order: 4 |
| 9 | + difficulty: 3 |
| 10 | + duration: 60 |
| 11 | + access: 'open' |
| 12 | + level: 300 |
| 13 | + concepts: 'tracing, OpenTelemetry, evaluation, groundedness, AI red teaming' |
| 14 | + islab: true |
| 15 | + status: 'draft' |
| 16 | +--- |
| 17 | + |
| 18 | +<!-- |
| 19 | +PILOT NOTE (remove before publishing): |
| 20 | +"Lab D" is new content: there was no observability, evaluation or safety-testing |
| 21 | +material anywhere in this repo. It follows the same template as Labs A-C. |
| 22 | +Starter code lives in a single folder — Labfiles/D-observe-evaluate-and-secure-agents/Python/ — |
| 23 | +shared by every task (one virtual environment, one .env). The completed reference code is |
| 24 | +in Labfiles/D-observe-evaluate-and-secure-agents/Solution/Python/. |
| 25 | +
|
| 26 | +This landing page is the lab overview. Setup lives in D0-getting-started.md and each task is |
| 27 | +its own page (D1-D3) so it can be completed on its own. The azd template and Bicep are |
| 28 | +generated from Labfiles/_shared/ — edit them there, not in the lab folder. |
| 29 | +--> |
| 30 | + |
| 31 | +# Observe, evaluate, and secure your agents |
| 32 | + |
| 33 | +**Level** ▰▰▰▱▱ **L300** (**L100** beginner → **L500** expert) |
| 34 | + |
| 35 | +You can build an agent in an afternoon. Knowing whether it's any good — and whether it |
| 36 | +behaves when someone tries to make it misbehave — is a different job. This lab is about |
| 37 | +that job: seeing inside a running agent, measuring the quality of its answers, and |
| 38 | +attacking it before someone else does. |
| 39 | + |
| 40 | +<br /><strong>Meet Anton, your AI guide.</strong><br />You'll spot **Ask Anton** tips throughout this lab. Want more interactive, hands-on help? Chat with Anton in the *[Ask Anton](https://aka.ms/choose-anton)* app. |
| 41 | + |
| 42 | +<details> |
| 43 | +<summary><strong><i>About the Ask Anton app</i></strong></summary> |
| 44 | + |
| 45 | +<strong><i><a href="https://aka.ms/choose-anton" target="_blank">Ask Anton</a></i></strong> is a generative AI agent that can answer questions about AI concepts and Microsoft Foundry technologies. It's available in two versions at <code>https://aka.ms/choose-anton</code>: |
| 46 | +<ul> |
| 47 | +<li><strong>Azure-based</strong>: Best experience <i>(requires an Azure subscription and deployment of a model in a Foundry project)</i>.</li> |
| 48 | +<li><strong>Browser-based</strong>: Use a small language model in your browser <i>(reduced functionality - may be slow or work only in "basic" mode in older/lower-spec devices)</i>.</li> |
| 49 | +</ul> |
| 50 | +<blockquote><i>Ask Anton is <u>not</u> a supported Microsoft product or a component of Microsoft Learn or AI Skills Navigator.</i></blockquote> |
| 51 | +</details> |
| 52 | + |
| 53 | +<style> |
| 54 | +/* "Ask Anton" just-in-time concept blocks */ |
| 55 | +details.concept { margin:.6rem 0 1rem; } |
| 56 | +details.concept > summary { display:inline-block; cursor:pointer; list-style:none; |
| 57 | + font-size:.85em; font-weight:600; color:#6b4ba1; background:#6b4ba112; |
| 58 | + border:1px solid #6b4ba133; border-radius:999px; padding:.2em .7em; } |
| 59 | +details.concept > summary::-webkit-details-marker { display:none; } |
| 60 | +details.concept > summary::before { content:"Ask Anton: "; font-weight:700; |
| 61 | + padding-left:1.5em; |
| 62 | + background:url("../Media/anton-avatar.png") left center / 1.25em 1.25em no-repeat; } |
| 63 | +details.concept > summary:hover { background:#6b4ba1; color:#fff; border-color:#6b4ba1; } |
| 64 | +details.concept[open] > summary { border-bottom-left-radius:0; border-bottom-right-radius:0; } |
| 65 | +details.concept .concept-body { border:1px solid #6b4ba133; border-top:none; |
| 66 | + border-radius:0 8px 8px 8px; padding:.6rem .9rem; background:#6b4ba108; font-size:.95em; } |
| 67 | +</style> |
| 68 | + |
| 69 | +<details markdown="1" class="concept"> |
| 70 | +<summary>Why can't I just read the output?</summary> |
| 71 | +<div class="concept-body" markdown="1"> |
| 72 | + |
| 73 | +Because the output is the one part of an agent that looks fine when everything else isn't. |
| 74 | +An answer can be fluent and confidently wrong, or correct but produced by three retries and |
| 75 | +a tool call that timed out. **Tracing** shows you what happened on the way to the answer. |
| 76 | +**Evaluation** scores the answer against something you already know to be true. |
| 77 | +**Red teaming** tells you what the agent does when the question is hostile. |
| 78 | + |
| 79 | +</div> |
| 80 | +</details> |
| 81 | + |
| 82 | +**Your scenario:** you work at **Tailwind Traders**, an outdoor-gear retailer that also runs |
| 83 | +guided trips. The staff assistant you built in earlier labs is now answering real questions |
| 84 | +on the shop floor — and store managers are asking harder questions about it. *Why was that |
| 85 | +answer slow? Is it making things up about the returns policy? What happens if a customer |
| 86 | +tries to talk it into something it shouldn't say?* In this lab you answer all three with |
| 87 | +evidence rather than opinion. |
| 88 | + |
| 89 | +You'll start with the **Core** tasks, which get you from "it runs" to "I can prove how well |
| 90 | +it runs". The **Optional** task then goes after safety. |
| 91 | + |
| 92 | +> **Note**: Some of the technologies used in this exercise are in preview or in active |
| 93 | +> development. You may experience some unexpected behavior, warnings, or errors. |
| 94 | +
|
| 95 | +## What you'll learn |
| 96 | + |
| 97 | +By completing the **Core** tasks of this exercise, you'll be able to: |
| 98 | + |
| 99 | +- **Trace an agent** with OpenTelemetry, export the traces to Azure Monitor, and read them |
| 100 | + in the Foundry portal — including custom spans you add around your own code. |
| 101 | +- **Evaluate answer quality** against ground truth using built-in evaluators |
| 102 | + (groundedness, relevance, similarity) and a JSONL dataset. |
| 103 | + |
| 104 | +The **Optional** task lets you additionally: |
| 105 | + |
| 106 | +- **Red team your agent** with the AI Red Teaming Agent: run adversarial attack strategies |
| 107 | + and your own seed prompts against a deployed agent, and read the attack success rate. |
| 108 | + |
| 109 | +## How this lab is organized |
| 110 | + |
| 111 | +This lab is **modular**. Each task is written to be completed **on its own, starting fresh** — |
| 112 | +so you can pick a single task and do just that one. Every task also shares one starter folder, |
| 113 | +one virtual environment, and one `.env`, so if you'd rather work straight through, you can. |
| 114 | + |
| 115 | +1. **Start with [Getting started](D0-getting-started.md)** — create your Microsoft Foundry |
| 116 | + project, connect Application Insights, get the starter code, and set up your `.env`. Every |
| 117 | + task begins from here; if you're doing the whole lab in one sitting, you only need to do |
| 118 | + this once. |
| 119 | +2. **Do any task.** Each task lists the setup it needs so you can start it independently. If |
| 120 | + you're moving straight from the previous task, a short *"Continuing from a previous task?"* |
| 121 | + note at the top lets you skip the repeated setup and keep going. |
| 122 | + |
| 123 | +## Lab at a glance |
| 124 | + |
| 125 | +Complete the **Core** tasks first (about **1 hour**) — they end with an agent you can see |
| 126 | +inside and a scorecard for its answers. Then add the **Optional** task if you want to test |
| 127 | +how it stands up to attack. |
| 128 | + |
| 129 | +{% include lab-tasks-table.html lab='D' %} |
| 130 | + |
| 131 | +**Choosing your path** — pick the tasks that fit the time you have: |
| 132 | + |
| 133 | +- **Core only (~1h):** do Tasks 1–2. |
| 134 | +- **Everything (~1h 35m):** add **Task 3**, the red team scan. |
| 135 | + |
| 136 | +> **One agent, three questions**: Task 1 traces an agent you create in code. Tasks 2 and 3 |
| 137 | +> both point at the **grounded knowledge agent** from |
| 138 | +> [Lab B](B-integrate-agents-with-enterprise-knowledge-and-m365.md). If you haven't done Lab B, |
| 139 | +> one command creates an equivalent agent so this lab stands alone — see |
| 140 | +> [Getting started](D0-getting-started.md). |
| 141 | +
|
| 142 | +## Measure, don't guess |
| 143 | + |
| 144 | +The three techniques in this lab answer different questions, and it's worth being clear about |
| 145 | +which is which: |
| 146 | + |
| 147 | +- **Tracing** answers *"what happened?"* It's a record of one run: which spans took how long, |
| 148 | + which tools were called, what the model was sent. Use it when something is slow or broke. |
| 149 | +- **Evaluation** answers *"how good is it, on average?"* It's a score over a dataset, so it's |
| 150 | + the only one of the three that tells you whether a change made things better or worse. |
| 151 | +- **Red teaming** answers *"what can I make it do?"* It's an adversarial probe, and a clean |
| 152 | + result is a floor, not a guarantee. |
| 153 | + |
| 154 | +None of them replaces the others, and all three are cheap compared to finding out from a |
| 155 | +customer. |
| 156 | + |
| 157 | +## Summary |
| 158 | + |
| 159 | +Across this lab you: |
| 160 | + |
| 161 | +- **Instrumented an agent** with OpenTelemetry, exported traces to Application Insights, and |
| 162 | + read them — including your own custom spans — in the Foundry portal. |
| 163 | +- **Evaluated a grounded agent** against a ground-truth dataset with built-in groundedness, |
| 164 | + relevance and similarity evaluators, and got a score you can compare across changes. |
| 165 | +- (Optionally) **Red teamed the agent** with adversarial attack strategies and your own seed |
| 166 | + prompts, and read the resulting attack success rate. |
| 167 | + |
| 168 | +Together these turn "the demo worked" into evidence you can show someone. |
| 169 | + |
| 170 | +## Clean up |
| 171 | + |
| 172 | +If you're finished, delete the resources you created to avoid unnecessary Azure costs. |
| 173 | + |
| 174 | +1. In the [Azure portal](https://portal.azure.com), navigate to the resource group that contains your Foundry resource. |
| 175 | +1. On the toolbar, select **Delete resource group**, enter the resource group name, and confirm. |
| 176 | + |
| 177 | +> The code you run in Task 1 deletes the agent version it creates. The agent Tasks 2 and 3 |
| 178 | +> measure is removed when you delete the resource group. If you provisioned with `azd`, run |
| 179 | +> `azd down` instead — but note that Application Insights, if you created it from the Foundry |
| 180 | +> portal, is a separate resource and is deleted with the resource group rather than by `azd`. |
0 commit comments