Architecting Intelligent Agents in Azure: Building Agentic Systems with Python and the Microsoft Agent Framework
Architecting Intelligent Agents in Azure takes you from your first interaction with an AI agent to deploying a fully orchestrated, production-ready system that can reason, remember, collaborate, and act.
Using the Microsoft Agent Framework and Python, this book walks you through every engineering layer behind modern agentic systems, from grounding and memory to tools, semantic recall, and autonomous action.
Across the chapters, you'll build Thain, an Azure-native feedback agent that evolves into a multi-agent system with the ability to retrieve knowledge, coordinate tasks, and refine its performance.
With a balanced mix of architecture, hands-on code, and cloud patterns, you'll learn how Azure Cosmos DB, Azure AI Search, Azure Monitor, and serverless components come together to form intelligent, self-improving enterprise agents.
Whether you're an AI engineer, Azure developer, or solution architect, this book offers a practical, end-to-end guide to building agents that can reason, recall, collaborate, and grow over time.
What You Will Learn:
- Build a fully functioning agent using Python and the Microsoft Agent Framework
- Implement reasoning loops, short-term memory, and tool-based actions
- Add persistent memory using Azure Cosmos DB and semantic recall using Azure AI Search
- Create safe and governed agents with telemetry, observability, and policy enforcement
- Integrate external systems through tools for tickets, documents, notifications, and workflows
- Orchestrate collaborative multi-agent systems with shared memory
- Deploy agentic workloads using Azure Functions, CI/CD pipelines, and cloud-native architecture
- Optimize cost, scale, and performance for enterprise production environments
Who This Book Is For:
AI engineers and developers building real agentic systems and evaluating the Microsoft Agent Framework, vector search, and Azure AI services
Cloud and Azure engineers looking to integrate AI capabilities deeply into existing or new applications
Solution architects designing AI-native or AI-augmented enterprise platforms
Full-stack engineers transitioning into AI engineering and wanting an end-to-end practical pathway into agentic systems
Architecting Intelligent Agents in Azure....2
Introduction....6
How to Read This Book....7
Who This Book Is For....8
What You Will Need....8
How the Book Is Structured....10
If You Are Joining Mid-book....10
A Note on the Code....10
Acknowledgments....13
Table of Contents....14
About the Author....29
About the Technical Reviewer....30
1. Thain: The Beginning....32
Introduction....32
The Agent Runtime: From Responses to Systems....32
Thains Architecture: Capability Evolution....33
Building the Core Agent....34
From Capable to Production-Ready....34
Learning and Scaling....35
Thains Capability Arc Diagram....35
Provisioning the Microsoft Foundry Environment....36
Setting Up Azure....36
Create Your Foundry Workspace....37
Launch the Project Space....38
Deploy the Language Model....39
Summary....43
2. Thain Meets the Agent Framework....44
Introduction....44
Thain v0.1: The First Working Agent....44
Designing Thain v0.1....45
Setting Up Your Workspace in VS Code....46
Creating the Project Structure....46
Project Layout....47
Installing Dependencies....47
Adding the .env File....48
The Configuration Layer....49
Building the Memory Layer....51
Building the Classification Tool....53
Inside the Classifier....55
Orchestrating Thain with the Agent Framework....55
Running and Testing Thain v0.1....64
Expected Output:....64
Running Thain in Dev UI Mode....65
Dev UI Tabs....67
Understanding the Three-Layer Execution....68
Troubleshooting....69
Note on SDK Versions and Compatibility....69
Thain v0.1 Architecture....70
Summary....70
Architectural Outcomes....71
3. Thain Learns to Remember....72
Introduction....72
Thain v0.2 at a Glance....72
Seeing Thain Forget....72
Setting Up Cosmos DB in Azure....73
Provisioning the Cosmos DB Account....73
Configuring the Database and Container....74
Configure TTL....75
Update the . env File and Dependencies....76
Update Dependencies....77
Implementing Persistent Memory in Code....77
Defining the Data Model....77
How This Model Supports Persistent Memory....78
Repository Layer....79
Repository Layer: Storage and Retrieval Flow....81
Service Layer....82
How the Service Layer Coordinates Persistent Memory....84
Persistent Context Provider....84
How Persistent Memory Is Injected into Reasoning....86
Updating Configuration....86
Configuration Changes for Persistent Memory....86
Configuration Loading and Validation....87
Integrating Persistent Memory....88
Extending the Agent Entry Point....88
Persistent Memory Initialization....89
Provider Chaining....89
Automatic Persistence....89
How Persistent Memory Is Integrated....90
How It All Comes Together....90
Seeing Thain Remember....91
Demo Conversations....91
Verify in Azure Cosmos DB....93
TTL Experiment....93
Thain v0.2 Architecture....94
Summary....95
Architectural Outcomes....95
4. Thain Connects the Dots Azure AI Search....97
Introduction....97
Structuring Thains Responses....97
The Limits of Persistent Memory....99
The Limits of User-Scoped Memory....103
Azure AI Search and Embedding Model....104
Provisioning Azure AI Search....104
Deploying the Embedding Model....105
Configuring Semantic Retrieval in .env....106
Installing Required Dependencies....107
Configuring Semantic Retrieval....108
1. Adding the Semantic Retrieval Dataclass....108
What This Class Captures (field-accurate)....108
2. Environment Variable Rules....109
3. Loader for Semantic Retrieval....110
4. Mapping the .env Variables....110
5. Integration in main.py....110
Semantic Retrieval Behavior....111
Building the Embedding Service....111
Understanding the Embedding Service....112
Constructor and Client Setup....112
Generating an Embedding....113
Cleaning Up....113
Concurrency and Async Execution....113
Where This Fits in Thain....113
Creating the Semantic Search Client....113
Index Creation and Schema....117
Fields in the Index....117
Vector Search Configuration....118
Upserting Complaint Documents....118
Vector-Based Retrieval....118
Where This Fits in Thain....118
Building the Semantic Retrieval Service....118
Purpose of the SemanticRecallService....120
Constructor and Dependencies....120
Indexing Complaints....120
Retrieving Similar Complaints....121
Error Handling and Service Cleanup....121
Where This Fits in Thain....121
Injecting Semantic Context into the Agent....121
Purpose of the Semantic Context Provider....123
Initialization and Configuration....123
Extracting the User Message....124
Performing the Semantic Lookup....124
Formatting the Context Instructions....124
Semantic-OnSemantic-Off Mode....124
Integration with main.py....124
Where This Fits in Thain....124
Validating Semantic Retrieval....125
Prerequisites....125
Test Setup....125
Run 1: Alen Starc Creates the First Complaint....125
Run 2: New User, Semantically Similar Complaint....125
Inspecting the Azure AI Search Index....126
Embeddings and Vectors....127
Where Azure AI Search Stores the Vectors....127
Why This Matters for Thain....128
Unit Tests Included in This Chapter....128
Semantic Retrieval Thains Processing Pipeline....128
Looking Ahead: Managed Retrieval Services....129
Summary....130
Architectural Outcomes....130
5. Thain Builds Its Toolkit....131
Introduction....131
Thain v0.4 at a Glance....131
Extending the Complaint Record for Agentic Outcomes....132
Preparing the Search Index for Agentic Retrieval....133
Extending the Index Schema....133
Persisting Outcome Fields During Upsert....134
Supporting Time-Scoped Agentic Queries....135
Returning Outcome Fields in Search Results....136
Making Retrieval Agent Directed....136
Refining Semantic Retrieval for Deliberate Use....137
Add Imports for Time Scoping....137
Enhancing Semantic Retrieval with Time and Outcome Awareness....137
Design Implications of the Retrieval Update....138
Exposing Semantic Retrieval As an Explicit Tool....139
Designing the Tool Contract....139
Creating the Search Tool....139
Design Principles Behind the Retrieval Tool....140
Integrating Agentic Retrieval into Thain....141
Import the Search Tool Factory....141
Wiring Semantic Context Injection by Mode....141
Registering the Agentic Search Tool....141
How Retrieval Modes Shape Agent Behavior....142
Observing Agentic Retrieval in Practice....142
Seed Run: Establishing the Baseline....143
Semantic Mode: Passive Recall....143
Agentic Mode: Explicit, Evidence-Driven Retrieval....144
Why Explicit Retrieval Matters....145
Introducing Core Action Tools....146
Adding the Action Tools Module....146
Controlling Tool Availability via Feature Flags....150
Wiring Feature Flags into Settings....150
1. Adding a Helper for Boolean Environment Flags....150
2. Defining Configuration for Action Tools....150
3. Loading Action Tool Configuration....151
Wiring Action Tools into the Agent Runtime....151
1. Import Action Tool Helpers....151
2. Load the Action Tools Configuration....151
3. Register Action Tools with the Agent....152
4. Add Agentic-Only Guidance for Document Retrieval....152
5. Surface Tool Availability in Agent Instructions....152
6. Wire Action Tools into the Dev UI Agent....153
Separating Agentic Retrieval from Agentic Actions....153
Validating Action Tools in the Dev UI....154
Initial Query: Requesting Known Procedures....154
Follow-Up Query: Requesting Action....155
Approval Gates for Agentic Actions....156
Enable Write Approvals via Configuration....156
Introducing an Approval Service....157
Implement a Tool Registry and Restrict Access to Write Tools....158
1. Creating an Explicit Tool Registry....158
2. Providing Approval Controls to Action Tools....158
3. Implementing Gating for the Write Tools....158
Integrating Approval into the Agent Runtime....160
1. Importing the Approval Service....160
2. Initializing the Approval Service....160
3. Providing the Approval Service to Action Tools....160
Testing the Approval Gate in the Dev UI....161
Step 1: Read Tools Remain Unblocked....161
Step 2: Write Action Approved (Yes)....162
Step 3: Write Action Denied (No)....163
The Role of Approval Gates in Agentic Systems....164
Thains Tool Architecture....164
Note on Stubbed Integrations and Governance....165
Summary....166
Architectural Outcomes....166
6. Thain Earns Trust....168
Introduction....168
Working with This Chapters Code....168
Code Reference Convention....169
Part A: Tracing Foundations....170
Design Goals for Tracing....170
Stable Identity: Run, Trace, and Turn IDs....170
Core Enforcement Mechanics (Key Excerpts)....171
1. UUID-Based Run and Trace Identity....171
2. Monotonic Turn Sequencing....171
Architectural Results....171
Safe Payload Handling by Default....171
Core Enforcement Mechanics (Key Excerpts)....172
1. Truncation Primitive....172
2. Recursive Safe Payload Reduction....172
Architectural Results....173
Event Model and Recorder....173
Core Enforcement Mechanics (Key Excerpts)....173
1. Immutable Event Contract....173
2. Strictly Sequenced, Append-Only Capture....173
3. Decoupled Emission....174
Architectural Results....174
Emitting Traces via Pluggable Sinks....175
Core Enforcement Mechanics (Key Excerpts)....175
1. Pluggable Sink Protocol....175
2. Deterministic File Path Construction....175
Architectural Results....176
Integrating Tracing....176
Core Enforcement Mechanics (Key Excerpts)....176
1. Create a Stable Run Identifier....176
2. Tool-Wrapping Helpers....176
3. Start a Trace Recorder....178
4. Wrap Tools Before Creating the Agent....178
5. Finalize and Emit the Trace....178
Architectural Results....179
Failure Visibility at the Tool Boundary....179
Core Enforcement Mechanics (Key Excerpts)....180
1. Return a Sentinel on Failure....180
Architectural Results....180
Verifying the Tracing Foundation....180
Test 1: Basic Interaction Trace Is Created....181
What to Observe....181
Test 2: Multiple Turns Create Separate Traces....182
What to Observe....182
Test 3: Sensitive Input Is Not Logged....183
What to Observe....183
Test 4: Tool Usage Captured in Traces....183
What to Observe....184
Test 5: Tool Failures Are Recorded Without Disrupting the User....185
What to Observe....185
Part B: The Governance Layer....187
Canonical Tool Identity....187
Architectural Results....187
Safety Signal Detection....188
Architectural Results....188
Policy Evaluation Engine....189
Core Enforcement Mechanics (Key Excerpts)....189
1. Governance Contracts....189
2. Evaluation Logic....189
Architectural Results....190
Logging Governance....191
Core Enforcement Mechanics (Key Excerpts)....191
1. Event-Level Allowlist....191
2. Policy Application....191
Architectural Results....192
Governing the Runtime....192
Core Enforcement Mechanics (Key Excerpts)....192
1. PolicyEngine Initialization....192
2. Centralized Recording Gate....193
3. Policy-Aware Tool Wrapper....193
4. Turn-Level Governance Wiring....194
Architectural Results....196
Verifying the Governance Layer....196
Test 1: Write Action Blocked When Approvals Are Disabled....196
What to Observe....197
Test 2: High-Frequency Write Actions Produce a Warning....197
What to Observe....198
Test 3: PII-Flagged Input Blocks External Notification....198
What to Observe....199
Test 4: Evidence-Free Write Action Produces an Audit Warning....199
What to Observe....200
Part C: Resilience and Auditability....201
Error Normalization for Observability....201
Core Enforcement Mechanics (Key Excerpts)....201
1. Error Taxonomy....201
2. Error Normalization....202
Architectural Results....202
Stable Trace Path Construction....203
Architectural Results....204
Resilient Tracing in the Agent Loop....204
Core Enforcement Mechanics (Key Excerpts)....204
1. Centralized Trace Emitter....204
2. Raised Exception Normalization....205
3. Sentinel Failure Normalization....205
4. Emission Idempotency Flags....206
5. Failure-Safe Execution Boundary....206
6. Success-Path Trace Emission....207
Architectural Results....207
Verifying Failure Modes and Audit Guarantees....207
Test 1: External Service Failure Traceability....208
What to Observe....208
Test 2: Policy-Denied Action Is Fully Audited....209
What to Observe....210
Test 3: Approval Denial Is Recorded Separately from Policy Denial....210
What to Observe....211
Test Summary....212
Audit and Trace Replay Utilities....212
Thain v0.5 Trust Architecture....213
Runtime Scope and Deployment Mapping....213
Summary....215
Architectural Outcomes....215
7. Thain Learns to Collaborate....217
Introduction....217
Multi-agent Architecture and Control Flow....218
Agent Roles....218
Control Flow and Orchestration Model....219
Shared Turn State (Blackboard)....219
Implementation Strategy....219
Working with This Chapters Code....220
Code Reference Convention....220
Python Package Initialization....221
Part A: Orchestrated Triage with Deterministic Control....222
Agent Contracts and Orchestration Stages....222
Core Enforcement Mechanics (Key Excerpts)....222
1. Orchestration Stage Identifiers....222
2. Safety Result Contract....223
3. Triage Result Contract....223
Architectural Results....224
Shared Turn State and Failure Recording....224
Core Enforcement Mechanics (Key Excerpts)....225
1. Structured Failure Recording....225
2. Turn-Scoped Message Metadata....225
Architectural Results....226
Deterministic Safety Gate....226
Core Enforcement Mechanics (Key Excerpts)....226
1. Deterministic Safety Signal Derivation....226
2. Execution Posture and Tool Permission Declaration....226
Architectural Results....227
Deterministic Triage Agent....227
Core Enforcement Mechanics (Key Excerpts)....227
1. Deterministic Urgency Derivation....227
2. Structured Triage Decision Emission....228
Architectural Results....228
Orchestrator: Owning the Turn....228
Core Enforcement Mechanics (Key Excerpts)....229
1. Deterministic Turn Initialization and Stage Ordering....229
2. Authoritative Safety Short-Circuiting....229
3. Structured Failure Recording....230
4. Centralized Response Normalization....230
Architectural Results....230
Routing Rules As Explicit Orchestration Guards....230
Core Enforcement Mechanics (Key Excerpts)....231
1. Guard Recall Eligibility....231
2. Guard Knowledge Retrieval Eligibility....231
3. Guard Action Eligibility....231
Architectural Results....232
Isolating Integration from Orchestration....232
Core Enforcement Mechanics (Key Excerpts)....232
1. Single Integration Boundary via Runner Wrapper....232
2. Deterministic Board Snapshotting for Tracing....233
Architectural Results....233
Application Entry Point Integration (Part A)....233
Core Integration Points (Key Excerpts)....233
1. Orchestration Helper Imports....233
2. Blackboard Construction....234
3. Triage Context Injection....234
Architectural Results....234
Validating Part A Control Plane....234
Test 1: Deterministic Triage Flow....235
Test 2: Triage Flags Action Without Execution....235
Test 3: Documentation-Oriented Requests....236
Test 4: Agent Restraint Under Ambiguous Input....236
Part B: Evidence Gathering Without Control Drift....238
Upgrading Triage....238
Core Enforcement Mechanics (Key Excerpts)....238
1. Strategy-Based Triage Implementations....238
2. Runtime Selection of Reasoning Strategy....239
3. Contract Validation As a Firewall....239
4. Constrained Agentic Reasoning....240
Architectural Results....240
Adding Recall As a Read-Only Evidence Agent....240
Recall Agent Responsibilities....241
Recall Agent Implementation....241
Architectural Results....242
Adding Knowledge As a Procedural Evidence Agent....242
Rationale for Separating Knowledge from Recall....242
Knowledge Agent Implementation....242
Architectural Results....243
Routing Evidence Agents with Explicit Guards....243
Routing Guards Determine Evidence Eligibility....243
Integrating Evidence Agents into the Runner....244
Architectural Results....245
Wiring Feature Flags and Multi-agent Config....246
Application Entry Point Integration (Part B)....247
Core Integration Points (Key Excerpts)....247
1. Construct Orchestrator Runner with Evidence Tools....247
2. Inject Merged Evidence Context into Agent Instructions....248
3. Disable LLM Tool Calls After Evidence Stages....248
Validating Part B: Evidence Gathering and Agentic Routing....248
Test 1: Recall and Knowledge Invoked....249
Test 2: Knowledge Agent Runs Without Recall....250
Test 3: Recall Failure Is Recorded....251
Test 4: Agentic Triage Preserves Contracts and Routing Behavior....252
Part C: Execution, Enforcement, and Safety....254
Governed Action Execution with the Action Agent....254
Why Execution Must Be Isolated....254
Responsibilities of the Action Agent....255
Core Enforcement Mechanics (Key Excerpts)....255
1. Action Agent Execution Boundary....255
2. Early Exit When No Action Is Requested....255
3. Action Deduplication and Idempotency Guard....256
4. Safety and Permission Enforcement Before Execution....256
5. Outcome Recording and Failure Capture....257
Recording Outcomes, Not Assumptions....257
Architectural Results....258
Updating the Orchestration Contracts....258
Core Enforcement Mechanics (Key Excerpts)....258
1. Expanding Action Result....258
2. Define Response Policy Contract....259
3. Enforce Policy During Response Composition....259
4. Add Failure Record....260
Routing with Safety-Aware Action Gating....260
Making the Safety Gate Authoritative....261
Core Enforcement Mechanics (Key Excerpts)....261
1. Derive Risk Level and Response Mode....261
2. Enforcing Tool Permissions from Safety Policy....262
3. Emitting the Authoritative Safety Result....262
Expanding Safety Detection and Redaction....263
Architectural Outcome....263
Standardizing Failures and Capturing Stage Progress....264
1. Record Failures As Typed Records....264
2. Add a Stage Timeline for Observability....265
Enforcing Execution Order and Response Consistency....266
Core Enforcement Mechanics (Key Excerpts)....266
1. Deterministic Stage Order and Short-Circuiting....266
2. Governed Evidence and Action Execution....267
3. Response Policy Derived from Authoritative State....268
4. Consistent, Redacted Context Assembly....268
Architectural Results....268
Wiring Governed Execution into the Runner....269
Core Enforcement Mechanics (Key Excerpts)....269
1. Extending the Runner for Action Execution....269
2. Conditionally Construct the Action Agent....270
3. Pass Action Agent into the Orchestrator....270
Making Approval Decisions Auditable....270
Core Enforcement Mechanics (Key Excerpts)....271
1. Extend the Approval Service with Decision Metadata....271
2. Emit Structured Approval Decisions....271
Allowing Approval Decisions Through the Logging Policy....272
Main Entry Point As the Enforcement Boundary....272
Core Enforcement Mechanics (Key Excerpts)....273
1. Add Safety-Aware Trace Redaction....273
2. Make Approval Decisions Traceable....273
3. Wrap Tools with Policy Checks and Consistent Redaction....274
4. Orchestrator–LLM Tool Decoupling....274
5. Post-Orchestrator Tool Call Gating....275
6. Response and Action Outcome Alignment....275
7. Redaction-Enforced Persistence....276
Final Validation: Thain v0.6 Pre-deployment Test Suite....276
Test 1: Safety Mode Normal Evidence Only, No Actions....277
Test 2: Write Action Denied Explicit Refusal, No Side Effects....277
Test 3: Write Action Approved Governed Execution....278
Test 4: Safety Mode Human-Escalate No Tools, Supportive Response....279
Validation Summary....279
Architecture Diagram: Thain v0.6....280
Summary....282
Architectural Outcomes....283
8. Thain Goes Live....284
Introduction....284
Architecture Overview: Thain in Azure....284
High-level Deployment Architecture....284
Mapping the Sprints to Enterprise Architecture Principles....285
Working with This Chapters Code....285
Code Reference Convention....286
Sprint 1: Foundation, Hosting, and Minimal CICD....286
Preparing the Runtime for Hosting....286
Runtime Compatibility Updates (main.py)....286
Agent Compatibility Update (agentstriage_agent.py)....287
Dependency Pinning (requirements.txt and constraints.txt)....287
Introducing a Stable Invocation Boundary....287
API-Specific Runtime Changes (main.py)....287
Minimal HTTP Layer (api)....287
Installing Runtime Dependencies (Optional)....288
Packaging Thain As a Container....288
Establishing the Azure Hosting Substrate....288
Building and Publishing the Container Image....289
Deploying Thain to Azure Container Apps....289
Assigning Azure AI Permissions....289
Executing Health and Chat Validation....290
Validating in Azure and via Swagger....290
Sprint 1 Outcome....291
Sprint 2: Identity and Secrets: Managed Identity Environment Separation....291
Preparing the Runtime for Managed Identity....292
Configuration Enforcement (settings.py)....292
Centralizing Credential Resolution....292
Enforcing Managed Identity in Runtime (main.py)....292
Migrating Data and Search Layers to Managed Identity....293
Cosmos DB (repositories.py, persistence.py)....293
Azure AI Search (search_client.py, semantic_service.py)....293
Dependency Support for Secret Management....293
Managed Identity Deployment, Promotion, and Validation....293
Preparing Infrastructure Configuration....293
Provisioning Identity and Secrets Infrastructure....293
Seeding Key Vault and Switching to Managed Identity....294
Assigning Role-Based Access Control (RBAC)....294
Building and Deploying the Managed Identity Runtime....294
Promoting the Build to Stage (Human Gated)....295
Validating Dev and Stage Environments....295
Sprint 2 Outcome....296
Sprint 3: Safety and Compliance....296
Integrating Managed Safety....296
Azure AI Content Safety Provider (content_safety.py)....296
Safety Gate Provider Selection (safety_gate.py)....296
Persisting Safety As Turn State (blackboard.py)....297
Deterministic Safety Responses (main.py)....297
Managed Safety Infrastructure and Deployment....297
Azure AI Content Safety Provisioning....297
Build and Deploy....297
Safety Validation and Enforcement Guarantees....297
Scripted Validation....298
Swagger Validation in Azure....298
Sprint 3 Outcome....299
Sprint 4: Observability and Deployment Safety....300
Emitting Auditable Traces....300
Trace Emission and Metadata Propagation (main.py)....300
Application Insights Trace Sink (trace_sinks.py)....300
Dependencies (requirements.txt, constraints.txt)....300
Managed Observability Infrastructure and Deployment....301
Application Insights Provisioning and Wiring....301
Observability Validation and Deployment Safety Gates....301
Trace Correlation Validation (Azure Portal)....301
Latency Signal Validation....302
Error-Rate Signal Validation....302
Sprint 4 Outcome....303
Sprint 5: Retrieval and Knowledge Base Hardening....303
Hardening Knowledge Retrieval....303
Retrieval Configuration and Validation (settings.py)....303
Azure AI Search Client Boundary (docs_search_client.py)....304
Retrieval Service Composition (docs_service.py)....304
Tool Integration and Governance Preservation (action_tools.py)....304
Runtime Wiring and Credential Resolution (main.py)....304
Retrieval Telemetry and Tool Audit Signals (trace_sinks.py)....304
Deployment and Retrieval Infrastructure....304
Retrieval Provisioning (s5-01-provision-retrieval.ps1)....304
Knowledge-Base Seeding (s5-02-seed-kb-index.ps1)....304
Retrieval Validation and Audit Proof....305
Azure AI Search Seed Verification (Portal)....305
Retrieval Validation (s5-03-validate-retrieval.ps1)....305
Retrieval Telemetry Proof (Application Insights)....305
Sprint 5 Outcome....306
Sprint 6: Governed Execution with Approvals....306
Implementing Asynchronous Approval-Gated Execution....307
Asynchronous Approval Requests (approvals.py)....307
Durable Approval Persistence (approval_store.py)....307
Tool-Level Approval Enforcement (action_tools.py)....307
Action State Awareness (action_agent.py)....307
Status Resolution and Deterministic Responses (main.py)....307
Approval Callback and Lookup Endpoints (app.py)....307
Approval Schemas (schemas.py)....308
Approval Configuration Validation (settings.py)....308
Approval Telemetry Signals (trace_sinks.py)....308
Provisioning the Approval Workflow and Communication Stack....308
Central Approval and Communication Configuration (infra_config.ps1)....308
Approval Infrastructure Provisioning (s6-01-provision-approvals.ps1)....308
Approval Workflow Definition (logicapp-approvals.json)....308
Runtime Configuration Wiring (s6-02-configure-approvals.ps1)....308
Execution Order....308
Validating Approval Enforcement and Auditability....309
End-to-End Approval Validation (s6-03-validate-approvals.ps1)....309
Portal Verification....309
Sprint 6 Outcome....310
Code-Driven Orchestration and the Path to Managed Workflow Runtimes....311
Conceptual Alignment with Workflow Runtimes....311
Azure Implications of a Workflow Runtime....311
Runtime Deferral As an Architectural Choice....312
MAF Workflow Alignment....312
Future Enterprise Extensions....312
Summary....313
Architectural Outcomes....313
9. Thain Learns from Us....315
Introduction....315
Working with This Chapters Code....316
Code Reference Convention....316
Human Feedback Loop....316
Extending the Runtime with a Durable Feedback Signal....317
Durable Feedback Persistence Layer (feedback_store.py)....317
Structured Feedback API Surface (schemas.py, app.py)....317
Feedback Telemetry Integration (app.py, trace_sinks.py)....318
Configuration and Cloud Enforcement (settings.py)....318
Provisioning and Wiring the Feedback Infrastructure....318
Provisioning the Feedback Container....318
Configuring the Feedback Runtime....319
Build and Deploy....319
Validating Feedback....319
Scripted Validation....319
Feedback Metrics Workbook in the Azure Portal....320
Version 1.1 Outcome....321
LLM-As-Judge Evaluation....322
Introducing a Repeatable Evaluation Capability....322
Batch Evaluation Runner (v11_eval_judge.py)....322
How the Judge Scores....323
Fixed Evaluation Dataset (v11-eval-set.json)....324
Provisioning and Executing the Evaluation Workflow....325
Baseline Run (Retrieval Disabled)....325
Improved Run (Retrieval Enabled)....325
Operational Verification....326
Inspecting Individual Prompt Deltas....327
Interpreting the Results and v1.11 Outcome....328
Response Policy Hardening for Evidence Integration....328
Correcting the Synthesis Gap....329
Surfacing Document Content from Search (docs_search_client.py)....329
Stabilizing the Service Boundary (docs_service.py)....329
Formatting Knowledge Context for LLM Consumption (orchestrator.py)....329
Hardening Response Policy Enforcement (main.py)....330
Validation....330
Scripted Evaluation....330
Inspecting Cosmos Records....331
Interpreting the Results....332
v1.12 Outcome....333
Quality Loop Architecture....334
Practical Considerations for LLM-Based Evaluation....337
How Thain Maps to Modern Agent Patterns....339
Summary....341
Architectural Outcomes....342
10. Thain at Scale....343
Introduction....343
Working with This Chapters Code....344
Code Reference Convention....344
Sprint 2.1: Instrument Dashboard....345
Sprint Scope....345
Telemetry Pipeline Implementation....345
Usage Extraction and Resolution....346
Cost Estimation....346
Structured Telemetry Event....347
Root Span Projection for Query Efficiency....347
Governance Alignment for Telemetry Propagation....348
Pricing Synchronization Automation....348
Build and Deployment Integration....349
Telemetry Validation....349
Operational Dashboard....350
Sprint 2.1 Outcome....354
Sprint 2.2: Controlled Optimization Under Governance....354
Implementing Runtime Optimization Controls....354
Runtime Compaction Controls (main.py)....354
In-Memory Response Cache (main.py)....355
Optimization Telemetry on the Root Span (trace_sinks.py)....355
Logging Policy Extension (logging_policy.py)....356
Operationalizing Optimization Controls....356
Optimization Configuration Script....356
Optimization Validation Gate....357
Deployment Sequence (Sprint 2.2)....357
Script Evidence....358
Portal Verification....358
Sprint 2.2 Outcome....361
Sprint 2.3: Data and Reliability Hardening....361
Reliability As a Controlled Execution Layer....362
Chat and Dependency Wrapping....363
Reliability Telemetry and Observability....364
Operational Alerting and SLO Enforcement....365
Configuration and Chaos Control....365
Deployment Sequence....366
Validation and Controlled Failure Behavior....367
Normal Scenario....367
Workbook Evidence....368
OpenAI Chaos....369
Cosmos Chaos....370
Search Chaos....371
Observed Failure Behavior Summary....371
Sprint 2.3 Outcome....372
Reliability Architecture....373
The Road to Production Scale....374
Summary....375
Architectural Outcomes....376
Enterprise Agent Architecture: A Reference Implementation....377
Plane 1: Data Acquisition and Curation....378
Plane 2: Data Preparation and Indexing....378
Plane 3: Agent Execution....379
MCP Exposure....380
Patterns in Practice....381
Enduring Principles for Agentic Systems....381
Index....384