Blog Post

Azure Infrastructure Blog
11 MIN READ

Infra Know-How in Natural Language: Building a Secure, Governed Agentic Smart Meter Platform with AI

akkoike's avatar
akkoike
Icon for Microsoft rankMicrosoft
Dec 05, 2026

Introduction

When people talk about AI-driven development (using generative AI to write code), the focus is usually on quickly building app screens or APIs. But running an enterprise system in a production-like way also requires a set of "unglamorous but non-negotiable" design decisions, such as:

  • Keeping public endpoints to a minimum and connecting services privately through Private Endpoints
  • Storing secrets in Key Vault and retrieving them with managed identities and RBAC
  • Using Azure Policy to deny any attempt to switch resources back to public access
  • Monitoring, health checks, and cost visibility
  • Human approval and tamper-proof audit records

In this post, I'll walk through a demo environment for "agentic loss reduction and smart meter operations" for power distribution utilities. I'll show how an engineer with infrastructure know-how described this kind of infrastructure design in natural language, and how GitHub Copilot (agent mode) turned it into Bicep, scripts, and tests.

There's one thing I want to get across:
Infrastructure know-how becomes even more valuable in the age of AI-driven development. If you can put into words what needs to be protected, you can build it together with AI—quickly, and in a repeatable way.

To give you a sense of scale: I built the entire large-scale demo system in this post by myself, in two weeks. The model I used in GitHub Copilot was Claude Opus 5.5, and I used about 90,000 AI Credits.

Note: The demo runs entirely on synthetic data. It does not include any specific customer's environment or data.

Reference repository (Bicep, scripts, apps, tests, design artifacts, and the AI-driven development harness are all public):
https://github.com/akkoike/Agentic-SmartMeter-Operations
Paths such as infra/... and .github/... in this post refer to paths in this repository.

The Scenario: An Agentic Smart Meter Operations Demo

In power distribution networks, energy lost along the way—both technical losses and non-technical losses such as electricity theft—is a major challenge. Smart meter data can help detect anomalies, but the volume is far too large for people to keep up with on their own.

So I built a demo environment with the following architecture:

RoleMain services
The only public entry point (mutual TLS, XML schema validation, conversion to JSON)Azure API Management
Ingestion buffer (private)Azure Event Hubs
Storage, analytics, and alerts (Lakehouse Bronze/Silver/Gold, Activator)Microsoft Fabric
Five AI agents (using read-only tools only)Azure AI Foundry Agent Service
Agent runtime and proposal API (private)Azure Functions
Secret storageAzure Key Vault
Tamper-proof recordsAzure Storage (immutability policy)
Review screen for operatorsAzure App Service (Entra ID sign-in)
Monitoring, tracing, and costApplication Insights, Log Analytics, Azure Monitor workbooks
Simulated field systems (HES/MDMS)Azure Container Apps

The key point is that the AI agents don't "do everything." Responsibilities are clearly split:

  • Fabric calculates the numbers needed for decisions, Functions applies the rules, and generative AI handles only the explanations and wording
  • Decisions that could harm a customer (such as a disconnection notice) always go through human approval first
  • The cloud never operates field control systems (OT) directly. Field systems pull only the approved proposals
  • Decisions, approvals, and outcomes are recorded in a tamper-proof way

These may sound like application concerns, but most of them are actually implemented through infrastructure design.

What I Asked for in Natural Language

At the center of the implementation was GitHub Copilot (agent mode) in VS Code. What I wrote were mainly instructions in Japanese, and I hardly wrote any Bicep code by hand.

Here are some examples (summarized from my actual instructions):

  • "The only API reachable from the internet should be API Management. Disable public access on everything else and connect it through Private Endpoints."
  • "Put all secrets in Key Vault. Have APIM named values reference Key Vault too, and retrieve them using managed identity and RBAC."
  • "Assign policies that disable public access on the receiving resources. For resources we sometimes open temporarily by IP, use Audit instead of Deny, and record why."
  • "On top of Entra ID sign-in, the review screen should only allow approved IPs. Don't put the IPs in the repository—pass them as environment variables at deployment time."
  • "Build a workbook that shows at a glance where along the data path things stopped when something goes wrong."

From these, Copilot produced modular Bicep, deployment and validation scripts, and even integration tests. The infrastructure alone ended up as about 4,300 lines of Bicep across 25 files.

Private Networking

  • Receiving services (Storage, Key Vault, Event Hubs, Cosmos DB, AI Search, Foundry, Functions, and more) have public access disabled, and name resolution goes through Private Endpoints in the VNet and Private DNS zones (privatelink.*).
  • Functions and App Service use VNet integration, so their traffic to other services also flows through the VNet and Private Endpoints.
  • The simulated field systems (Container Apps) live in a separate VNet and region, with outbound traffic consolidated through a NAT Gateway. They send data to API Management over mutual TLS using a client certificate.
  • Fabric connects privately to Event Hubs through a Fabric managed private endpoint.
  • The only way in from the outside is API Management, which requires mutual TLS.
  • See: infra/modules/network.bicep, infra/modules/private-endpoint.bicep, infra/modules/private-dns.bicep, infra/modules/api-management.bicep

Creating a Private Endpoint itself isn't hard if you know the Bicep template. The hard part is getting everything lined up: DNS zone names that differ by service, subnet layout, whether VNet integration is needed, and what's supported in each region. I let AI handle that, so I could focus on deciding what to close, what to open, and why.

Key Vault and Secrets

  • Key Vault uses RBAC authorization (no access policies), has soft delete enabled and public access disabled, and is reachable only through a Private Endpoint.
  • API Management is granted the "Key Vault Secrets User" role on its managed identity and references Key Vault secrets from named values.
  • Foundry, Content Safety, and Application Insights have key-based authentication disabled and connect with Entra ID.
  • The rule "never put connection strings or keys in code or config files" is written into the instruction files (more on those below), so the AI follows it every time.
  • See: infra/modules/key-vault.bicep, infra/modules/api-management.bicep

Governance: Azure Policy and Tags

  • I assigned built-in "disable public access" policies to the receiving resources. Storage, Key Vault, Event Hubs, Cosmos DB, and AI Search use Deny (the change to public access is rejected outright). Foundry and Functions, which we sometimes open temporarily by IP for checks, use Audit (shown as non-compliant while left open).
  • Diagnostic settings are also checked by policy so that logs flow into Log Analytics.
  • Required tags on every resource are enforced mechanically by hooks (more on those below).
  • See: infra/modules/policy.bicep

Monitoring and Cost

  • Structured logs and traces are emitted with OpenTelemetry and collected in Application Insights.
  • I built two Azure Monitor workbooks. One shows cost per unit of business work ("per reconciliation run, per proposal"). The other shows where to look when something breaks (each stage of the data path, resource health and Azure-side incidents, and errors).
  • See: infra/modules/workbook.bicep, infra/modules/health-workbook.bicep

Keeping AI from Going Too Far: The Harness

Once you can build almost anything in natural language, the natural worry is: "What if the AI builds something risky on its own?" To address that, I built a "harness" into the repository that wraps around the AI's work itself. It's built entirely with GitHub Copilot's customization features.

0. You Can Build the Harness Itself with Prompts

When I talk about harnesses, many people tense up. They assume that to build the best harness, they need to learn each customization—custom agents, skills, instruction files, hooks—and understand exactly what to configure and how.

But here too, a well-crafted prompt is all it takes to build a great harness. LLMs are smart, so there's no need to overthink it.

  1. Find something you want to model it on—"I love this harness diagram" or "I really agree with the harness approach described on this web page"
  2. Create a docs folder in an empty local repository and put in whatever context you think is needed (the theme, requirements, evaluation criteria, the harness diagram you want to follow, and so on)
  3. Then give an instruction like this:

"Using the context in this repository, and referring to the harness image placed here as a reference diagram, please "deploy" the best harness environment for this environment."

That alone gives you a solid base harness tailored to your environment. In this repository, I placed the theme, the evaluation criteria, and a harness diagram (docs/harness-sample/) in docs/, and deployed the full set from there: the 8 steps, agents, skills, instruction files, and hooks described below.

From there, as development and deployment move forward and you find "I want to add this constraint" or "I want to block this operation," you just build it into the harness each time and let it grow. In this project, for example, I added the agent in charge of implementation (implementer) only once we reached the implementation phase. I also kept adding to the instruction files whenever something was decided, such as switching regions or the deviations allowed in the demo (covered later). A harness doesn't need to be perfect from day one—it gets smarter along with the project.

1. Design in 8 Steps Before Building

Instead of having the AI jump straight into code, I had it produce the following eight artifacts in order, and it can't move on while the previous step is still empty:

  1. Problem definition
  2. Specification
  3. Specification analysis (risks and trade-offs)
  4. Architecture review
  5. Plan
  6. Task breakdown
  7. Evaluation
  8. Governance

Each step has a dedicated custom agent (analyst, architect, planner, implementer, evaluator, governor) paired one-to-one with a skill (procedure, template, and completion criteria). The architecture review went through 18 revisions, and the decision records (why we chose each design and which alternatives we rejected) grew to more than 80.

  • See: artifacts in specs/001-loss-reduction/, agents in .github/agents/, skills in .github/skills/

2. Use Instruction Files to Keep "What Must Be Protected" Always in Effect

In .github/copilot-instructions.md, I wrote the invariants that apply to every task:

  • Consumption data stays in domestic regions
  • Keep the boundary with the OT network separate; agents never operate OT directly
  • Decisions that could harm a customer always require human approval
  • Store raw data separately from AI estimates and proposals, and keep decision records tamper-proof

On top of that, I wrote separate conventions: Bicep rules that load only when working in infra/, and security rules (Entra ID and managed identity, Key Vault, Private Endpoints, prompt injection defenses, and more) that load only when working in src/. This is how an infrastructure engineer's know-how gets passed on to the AI—by writing it down in words here.

  • See: .github/copilot-instructions.md, .github/instructions/ (bicep.instructions.md, implementation.instructions.md, and others)

3. Use Hooks to Make Rules Unbreakable

Instruction files are essentially "requests," so the AI can sometimes miss them. That's why I used Copilot hooks (scripts that run before and after each tool call) to enforce rules like these mechanically:

  • Check for required tags before writing Bicep or scripts, and before running az ... create or az deployment ... create; reject if they're missing
  • Don't allow remote templates that can't be validated
  • Reject any attempt to write a string that looks like a key or connection string to a file, and point the AI to Key Vault or managed identity instead
  • Enforce the order of the 8 steps (no writing the next artifact while the previous one is still empty)
  • Reject git push --force and git add --force (which ignores .gitignore), to prevent secrets from leaking into the public repository
  • Record every tool call in an audit log (JSON Lines), including rejected ones

The point is to enforce the line between what AI is trusted to do and what humans decide—not as a request, but as a mechanism.

  • See: .github/hooks/harness.json, .github/hooks/scripts/guard.cjs, .github/hooks/scripts/azure-tags.cjs, .github/hooks/scripts/audit.cjs

4. Deploy Only After Human Approval

The rule is that deployments to Azure happen only after a human has reviewed and approved the what-if results. The AI creates the templates and procedures; a human is the one who "presses the button" on production-like changes.

Being Upfront: Deviations Allowed in the Demo

Because of the effort involved and tenant constraints, I allowed a few deviations in the demo environment that wouldn't be acceptable in production. What matters is not hiding them—recording them as decisions and risks, and writing down how production would handle them.

PrincipleDeviation in the demoWhat production would do
Authentication with Entra ID and managed identitySome app-to-app calls use function keys or a listen-only shared access rule (stored only in Key Vault or similar)Replace with Entra ID and managed identity
API Management is the only public endpointThe review screen is public with Entra ID plus IP restrictions (Private Endpoint also kept). Monitoring uses public endpointsMake it private with Conditional Access, Private Endpoints, and Azure Monitor Private Link Scope
Tamper-proof recordsImmutability retention of 7 days, without a lockLegally required retention with a lock
Separation of dutiesOne account switches between seven roles (records keep both the actual person and the role they played)Separate accounts per role—one person, one role

Details of the deviations and how production would handle them are in specs/001-loss-reduction/04-architecture-review.md and specs/001-loss-reduction/08-governance.md.

Even with AI-driven development, managing these exceptions is a human's job. Put the other way around: once you define the exceptions in words, the AI keeps implementing within those boundaries.

What I Learned

  1. Infrastructure know-how directly shapes the quality of your instructions. "Make it private" isn't enough. When you can also say "where the Private DNS zones should live" and "whether a policy should be Deny or Audit, and why," the quality of what comes out changes dramatically.
  2. AI is fast at researching, aligning, and writing. It pulls from the docs and consistently lines up the details—API versions per service, DNS zone names, role definition IDs, and regional availability.
  3. Put guardrails in two places: not just instruction files, but hooks and policies too. Stopping things on both the AI side (hooks) and the Azure side (Policy) prevents most accidental mistakes.
  4. When you record the reasons behind decisions, neither AI nor humans get lost. Writing down "why this design" and "what we rejected" helps the AI make consistent decisions even when things change later.
  5. Failures become records, too. Trial and error—like switching regions because a service wasn't available, or reworking the design because a feature didn't support managed private endpoints—was captured in the decision records and fed into the next round of design.

Wrapping Up

With agentic systems, the "defensive" design—what data the AI can touch and how far it can act on its own—matters more than ever. And much of that defense lives in the infrastructure domain: networking, identity, secret management, policy, and monitoring.

AI-driven development greatly reduces the burden of writing that defense by hand. What's asked of infrastructure engineers is to put into words what to protect and how much to allow, to set up the mechanism that wraps around the AI's work (the harness), and to keep the final decision in human hands.

With infrastructure know-how, you can build even agentic systems from natural language—with strong security and governance built in. Give it a try.

Reference repository: https://github.com/akkoike/Agentic-SmartMeter-Operations
Feel free to use the harness in .github/ (agents, skills, instruction files, and hooks) as a reference when you set up something similar for your own projects.

Published Dec 05, 2026
Version 1.0
No CommentsBe the first to comment