Building always-on agents on Azure: from the Claude blueprint to a Microsoft architecture.

This post comes after a talk on this subject I had for AI Lab.

Most agents wait for you to ask. An always-on agent keeps working when you are not there: it reacts to events, follows up on its own and speaks up only when something matters.

In November 2026 Anthropic described how to build one in Building always-on agents by William Hu, on the Claude blog (https://claude.com/resources/articles/building-always-on-agents). The article breaks the problem into five building blocks that have nothing to do with the model itself.

This post walks through those five blocks and then shows how to build them on Azure: managed services and low-code where they are enough, and code (.NET in our case) only where it is really needed. The running example is a Business Central agent that follows up open purchase orders.

The idea in one picture.

An always-on agent is not a new kind of agent. It is the same agent loop, wrapped in a few pieces that decide when it wakes up, what it remembers and how it reports back. It sleeps most of the time and wakes for short runs: it receives an event, does its work and saves what it learned for the next run.

The Anthropic’s five building blocks.

1. Event inbox

Every trigger, whether a webhook, a schedule or a user message, is written to one durable list before anything runs. A worker picks the events up, one worker per user, so runs never compete and no event gets lost.

2. Timers

What the agent must do later lives in its own store: follow-ups it sets for itself and schedules the user sets. A scheduler turns due timers into inbox events, so the agent can act on its own without ever skipping the inbox.

3. Memory

Every run starts from scratch, so whatever must survive is kept outside the worker. A few files load on every run; notes and progress are read only when needed.

4. Permissions

An agent that works alone needs limits. Credentials stay in a proxy outside the agent, a classifier stops risky actions, and anything that needs a person becomes a deferred tool call that waits for approval.

5. Outbox

The user sees outcomes, not reasoning. A run ends quietly, sends a message or asks a question, and messages go through an outbox where a dispatcher paces delivery.

One architecture on Azure.

Here is the whole design. Azure services do the heavy lifting, Logic Apps covers the connections, and .NET is used only for the parts that need real code. No agent framework is involved.

  • Events enter a Service Bus queue that keeps one lane per user. Service Bus calls this lane a session. Duplicate detection drops an event that arrives twice.
  • A Function is the run worker. It loads memory from Cosmos DB, runs the agent loop against a Foundry model and calls tools through API Management.
  • The scheduler, a timer-triggered Function, reads due timers from Cosmos DB and drops them into the same queue.
  • Everything the agent wants to say goes through an outbox queue to Teams, and the same Logic Apps workflow writes the buyer’s answer straight back to the inbox. Vendor emails arrive through a Logic Apps workflow.

Anthropic’s pattern suggests a durable list such as a database table for the inbox. Service Bus is our choice because it gives the one-lane-per-user rule, retries and duplicate detection out of the box. In total there are three Functions: the scheduler, the run worker and the outbox dispatcher. Business Central never calls the agent: the agent reads and writes Business Central only through the gateway.

Low-code option: Logic Apps can replace some of the glue. Its connectors can bring events from other systems without custom handlers, and this design uses it twice: to receive vendor emails and to post the Teams card.

Code or low-code?

The rule is simple: use configuration or low-code when a piece only moves data between systems, and write code when a piece makes decisions or must be tested in detail.

PieceBuilt withWhy
Inbox, retries, duplicatesService Bus configurationSessions and duplicate detection are settings, not code
Vendor emails inLogic Apps (Outlook trigger)A connector already does it
Teams cards, buyer answers, vendor emailsLogic Apps (Teams and Outlook connectors)One action posts the card and waits; a Service Bus action puts the answer in the inbox
Tokens for Business CentralAPI Management policiesCredential manager handles OAuth for us
Memory and timersCosmos DBA managed store, no code beyond reads and writes
Scheduler, dispatcherSmall Functions (.NET)A few lines each; they could also be Logic Apps steps
Agent loop, risk policy, tools.NETThe decisions live here, so they need tests
Safety checksFoundry (Decision-1.1, Content Safety)Managed models called from the loop

Why Cosmos DB, and why API Management?

Two services are easy to misread in this design, so here is what each one is for.

Cosmos DB: the agent’s memory between runs.

Service Bus carries events, but it forgets a message once it is handled. The worker is also stateless: when a run ends, everything in its memory is gone. The agent still has to know what it did yesterday, which timers are waiting and where an approval stopped. Cosmos DB is the place where all of that is written down. It stores simple JSON documents, reads them fast by user ID and needs no schema work, so you can start with the serverless mode and pay only for what you use.

ContainerWhat it holdsWhy the agent needs it
eventsEvery event that arrivedSpot duplicates and audit what happened
timersFollow-ups and deadlines with a due timeWake the agent later, even after a restart
memoryInstructions, notes and progressRemember across runs without long prompts
conversationsThe conversation of a run and any pending tool callResume exactly where an approval stopped
outboxMessages waiting to be sent, and those already sentPace messages and never send twice

API Management: the gateway that holds the keys.

Business Central needs an OAuth token for every call. If the agent held that token, it would end up in code, logs or prompts, and a model could be tricked into leaking it. Instead the agent calls a gateway URL using only its managed identity, an identity Azure gives the Function so it needs no password. The gateway checks that identity on every call. API Management has a credential manager that stores the connection to Business Central, fetches the token, renews it when it expires and attaches it to the outgoing call. Business Central sees a normal authorised request, and the agent never sees a secret. Use the client credentials flow, where a Business Central app registration acts as a service, so the agent never depends on a person signing in again.

The gateway brings three more benefits. It exposes only the endpoints your tools need, so the agent cannot reach anything else. It logs and rate-limits every call in one place. And you can change the credentials or the Business Central environment without touching the agent code.

The inbox in detail.

Every source writes an event to a Service Bus queue with sessions enabled. Set the session ID to the user ID: Service Bus then keeps one active worker per user and delivers that user’s events in order. Give every event a message ID that stays the same when the event repeats, for example the timer ID plus its due time, and turn on duplicate detection when you create the queue, so the copy is dropped. Detection only covers a time window, so the worker must also be idempotent: safe to run twice on the same event. Use the Standard tier, because Basic has no sessions or duplicate detection.

Failed messages are retried and then land in the dead-letter queue, a side queue for messages that keep failing, where an alert picks them up.

Timers in detail.

Keep timers in a Cosmos DB container, one document per timer with a due time and the user ID. A timer-triggered Function runs on a short schedule, queries the due timers and sends each one to the inbox as a normal event, then marks it as fired.

Three jobs use timers: follow-ups the agent sets for itself, approval deadlines and recurring work such as the daily review of open orders and the nightly tidy-up of the agent’s notes.

Why timers are kept apart from the inbox?

Anthropic’s pattern keeps timers separate on purpose. A timer is not an event yet: it is a promise to create one later, and promises change. A buyer answers before the approval deadline, so the deadline must be cancelled; a vendor gives a new date, so a follow-up must move. A message already in a queue is hard to list, change or cancel. A timer in Cosmos DB is just a document that says wake me at this time for this task, easy to read, edit or delete until it is due. Cosmos DB does not run anything: every minute the scheduler turns due timers into ordinary inbox events and marks them as fired.

A timer document looks like this, for example:

The run worker.

The run worker is a .NET Function triggered by the inbox, one user’s lane at a time and one event at a time. It confirms (settles) the message only after the run has saved its state, so a crash means a retry, not a lost event. Two settings in host.json matter: maxConcurrentSessions, how many users run at the same time on each instance, and maxAutoLockRenewalDuration, which must cover your longest run so the lane stays locked while the agent works.

The agent loop is a plain class. It calls a Foundry model through the Azure OpenAI .NET client with managed identity, sends the messages and the tool definitions, runs the tools the model asks for and repeats until the model is done. The code is split into a few shared libraries: the core loop, the infrastructure (Cosmos DB, Service Bus, the model client) and one class per tool.

Memory in detail.

Use Cosmos DB with the user ID as partition key (the field Cosmos DB uses to group data), in separate containers for events, timers, memory, conversations and outbox. Transcripts go to Blob Storage. The memory itself holds three things: standing instructions, notes about what the agent learned that no other system knows, and progress on work in flight. Past messages, the fourth kind the article lists, live in the conversations container and the transcripts.

Store pointers, not copies. Keep a purchase order number, not the purchase order, and read fresh data through a tool when you need it. An optional scheduled run can reread the notes now and then and tidy them up, which the article calls dreaming.

Outbox in detail.

The agent never posts to Teams itself. It has one tool, send_message, that writes to the outbox queue; the outbox container in Cosmos DB records what was sent. A dispatcher Function reads the queue, applies pacing (a maximum number of messages per user per period, and quiet hours) and calls the Logic Apps workflow. Silence is a valid ending for a run. Each message carries a key, so the same alert is never sent twice, and several small updates can be merged into one digest. Start quiet, then loosen the rules with evals: replay real past runs and check which messages were worth sending.

Observability.

Send telemetry from every Function to Application Insights, with one correlation ID (a shared tag that ties the logs together) per event across inbox, run and outbox. Track tokens and duration per run, messages sent per user and the dead-letter count. Alert on dead-letters and on token spikes.

Permissions: the agent never holds a token.

The gateway keeps tokens away from the agent, as explained above. The other half of permissions is deciding which calls may run on their own, and that takes three layers.

First, give every tool a risk level in a small table: read-only tools just run, a standard reminder is medium risk and runs on its own up to a set number per order, and changing a date in Business Central or writing a free-text email to a vendor always needs the buyer’s approval. Thresholds and deadlines live in configuration, not in code.

Second, medium-risk calls get an extra check. The worker sends the proposed call, its arguments and the buyer’s standing rules to Microsoft-Decision-1.1, a generally available decision model in Foundry, with one question: allow, block or ask the buyer? It returns a probability for each option instead of an explanation, so log the numbers with the run ID. If allow is above your allow threshold the call runs, if block is above the block threshold it is refused, and otherwise the buyer is asked. High-risk tools skip this check and always go to the buyer.

Third, Content Safety prompt shields, a filter that spots instructions hidden in text, check every vendor email before the model reads it.

Approvals without blocking a worker.

When the agent wants to do something risky, the run saves its state, asks the buyer in Teams and ends. The answer comes back as a new event, and the next run continues from the saved state. Nothing waits in memory.

Low-code option: The Teams card with Approve and Reject is one Logic Apps action, Post adaptive card and wait for a response, so you write no bot code.

The run saves the conversation and the pending tool call in Cosmos DB before it ends. The card shows what the agent wants to do, why and what it changes, with Approve and Reject. A card takes one submission, so set its update message to show the result. When the buyer answers, the same workflow writes an approval event straight to the inbox with the Service Bus connector, using the buyer as session and the request ID as message ID. If the deadline timer fires first, a timeout event arrives instead. Give the wait action a timeout too, and let the worker ignore an answer that arrives after the request has timed out. The next run loads the saved conversation and either executes the pending call or tells the model it was rejected.

Where low-code fits?

Logic Apps suits the edges of this architecture: triggers, connectors and Teams. Keep the agent loop, the memory and the risk checks in code, where you can test them. Logic Apps also has agent workflows that can run the whole loop for simple integration scenarios. Know the limits: a tool can contain only actions, with no control flow, and Microsoft suggests about 10 tools per agent. Memory across runs still needs an external store.

Where Foundry Agent Service could fit?

Foundry Agent Service is Microsoft’s managed service for running agents. In this architecture it can replace one box only: the brain inside the run worker.

Today that brain is a loop we write ourselves. It sends the conversation to the model, runs the tools the model asks for, repeats until the work is done and saves the conversation and the notes in Cosmos DB. Foundry Agent Service can do that job for us. It keeps the conversation, calls the tools, records a trace of every step, applies safety guardrails and gives the agent its own identity in Microsoft Entra ID.

Why you would use it:

  • You write and maintain less code in the most delicate part of the system.
  • Tracing and guardrails come ready, and we would otherwise build them.
  • The agent has its own identity, so it is easier to see and audit what it is allowed to do.

What stays ours: the inbox, the timers, the outbox, the one-lane-per-user rule and the approvals. Foundry Agent Service does not provide any of them. The Function still receives the event and would simply call the agent for each run.

Why this design does not use it yet: its memory is still in preview, and a memory store holds at most 100 scopes, roughly one per user, so a larger team means splitting users across stores, and we want to control exactly where state is saved because a deferred approval depends on it. The choice is easy to reverse later: the agent loop lives in one class, so moving to Foundry Agent Service changes one box and leaves the architecture as it is.

Example: a Business Central purchase follow-up agent.

Business Central already knows what to buy. Reorder points, the planning worksheet and the requisition worksheet calculate it, and no AI is needed for that. What Business Central does not do is chase the vendors afterwards. Buyers spend hours on it: finding orders that nobody confirmed, writing reminders, reading replies written in every style and language, and updating dates by hand. That is the job of this agent. It suits a model well, because the hard part is reading and writing free text, not calculating.

Why this needs an agent and not an algorithm?

  • Vendor replies are free text, in any language, often with the real answer in an attachment.
  • The agent has to match a reply to the right order and lines, and to the customers waiting for those goods.
  • It has to judge whether a change matters. A two-day delay on stock items can pass quietly; the same delay on goods a customer needs next week cannot.

Three ways the agent wakes up:

  • Daily review timer. Each morning the agent checks the buyer’s open purchase orders: not yet confirmed (no promised receipt date), close to the expected receipt date, or already late.
  • Vendor email. A Logic Apps workflow with the Office 365 Outlook trigger watches the purchasing mailbox and writes each new email to the inbox as an event. This is the low-code entry point of the design.
  • Buyer message. The buyer answers a card or asks a question in Teams.

The agent also sets its own follow-up timers, for example to send a reminder if a vendor has not answered within three days.

What the agent remembers:

  • Instructions: how long to wait before a reminder, which tone to use with each vendor, and which delays are critical, for example on goods tied to a sales order with a firm date.
  • Notes: what it learned about each vendor that Business Central does not hold, for example that one vendor always answers in German or confirms only after a second reminder.
  • Progress: one entry per order it is chasing, with the reminders sent, the last reply and any open question. The order number is the pointer, never a copy of the order.

Its tools:

ToolWhat it doesRiskApproval
GetOpenPurchaseOrdersReads open orders and their lines, with promised and expected receipt datesRead-onlyNo
GetLinkedSalesOrdersReads which sales orders wait for a purchase orderRead-onlyNo
ReadVendorEmailReads the email behind an event, attachments included as textRead-onlyNo
ReadNoteReads a note or progress entry from memoryRead-onlyNo
SaveProgressSaves progress and notesLowNo
SetFollowUpCreates or cancels a follow-up timerLowNo
SendReminderSends a standard reminder to a vendorMediumOnly beyond the set number per order
SetPromisedReceiptDateWrites the date the vendor promised on an order lineHighAlways
SplitOrderLineSplits a line in two when the vendor ships in partsHighAlways
SendVendorMessageSends a free-text email to a vendorHighAlways

Two details of Business Central shape these tools. The date a vendor promises belongs in the Promised Receipt Date field of the order line; the Expected Receipt Date is calculated by Business Central from it, so the agent never writes it directly. And an order counts as not confirmed when its lines have no promised receipt date yet. The standard API v2.0 exposes purchase orders and their lines, but on the lines only the expected receipt date. So a small extension publishes custom API pages for three things: the promised receipt date, splitting a line, and the link to the sales orders waiting for the goods. Every call goes through the gateway. Emails to vendors leave like any other message: through the outbox, the dispatcher and the Logic Apps workflow.

One follow-up, step by step:

  1. Timer fires. The buyer’s daily review timer comes due and the scheduler writes an event to the inbox.
  2. Order found. The first run reads the open orders through the gateway and finds an order that still has no promised receipt date five days after it was sent.
  3. Reminder sent. A standard reminder is medium risk and within the limit, so it goes out through the outbox. The agent sets a follow-up timer for three days later, saves its progress and ends.
  4. Vendor replies. Two days later the vendor writes that part of the order ships next Friday and the rest in three weeks. The Logic Apps workflow puts the email in the inbox, and the follow-up timer is cancelled.
  5. Reply understood. A second run reads the email, matches it to the order and its lines, and checks the linked sales orders: one customer needs part of the goods next week.
  6. Ask the buyer. Changing dates in Business Central is high risk. The run saves its conversation, sends an approval card to Teams, sets a deadline timer and ends.
  7. Buyer approves. The answer returns to the inbox as a new event.
  8. Line split, dates set. A third run splits the order line in two, one line per shipment, and sets the promised receipt date on each. Business Central recalculates the expected receipt dates, and the agent notes the partial shipment in its progress.
  9. Stay quiet. No further message. The agent speaks again only if the vendor misses the new dates.

What the buyer sees:

One card in Teams for step 6, with the vendor, the order, the new dates and the customer affected in one sentence, and two buttons, Approve and Reject. When several orders are at risk, a short daily digest instead of one message each. The buyer never sees the reminders that worked.

When things go wrong:

  • The same email arrives twice: its message ID becomes the event’s message ID, so Service Bus drops the copy.
  • An email matches no order: the agent asks the buyer which order it belongs to and saves the answer as a note.
  • The vendor never answers: after the set number of reminders, the agent hands the order to the buyer.
  • An email tries to give the agent orders: prompt shields screen it, and the agent treats every email as data, never as instructions.
  • Business Central is slow or throttles: the run fails, the message returns to the queue and is retried. After repeated failures it goes to the dead-letter queue and raises an alert.

Under the hood:

The sketches below show each block of the example in plain C#. They are simplified to show the shape of the code: error handling, logging and configuration are left out, and names are illustrative.

Email intake (Logic Apps):

The only low-code piece on the way in. It does no reasoning: it only turns an email into an event.

The Service Bus action in the workflow sets three values:

Scheduler:

A timer Function that turns due timers into events. It never calls the agent.

Run worker:

One message at a time per buyer. The message is settled only after the state is saved.

Agent loop and risk policy.

The model proposes tool calls; the code decides what actually runs:

A deferred approval:

What deferred means in practice: nothing waits in memory.

When the answer arrives, the next run loads the conversation by requestId. If the request already timed out, the answer is ignored; otherwise the pending call runs or the model is told it was rejected.

One tool: SetPromisedReceiptDate

Every tool is a small class that calls the gateway, never Business Central directly.

The gateway client has no secret: it authenticates with the Function’s managed identity, and API Management adds the Business Central token. Before you go live, check how your company handles released orders: depending on the fields involved, Business Central may require the order to be reopened before its lines change, and the custom API page is the right place to handle that.

Performance and scalability.

Nobody waits on a screen for a run, so the questions are throughput, order and cost, not response time. The only human-paced step is the approval in Teams.

How it scales:

  • One lane per user. Service Bus sessions let many users run at the same time while each user’s events are handled one at a time. The number of lanes in parallel follows the number of active users, capped by the concurrent sessions setting and by how many instances the Functions plan starts. Flex Consumption adds instances as messages arrive.
  • Stateless workers. Everything a run needs is loaded from Cosmos DB, so any instance can serve any lane, and a crashed instance costs only a retry.
  • Partition by user. Cosmos DB reads and writes touch one partition, so one user does not slow the others.

Where the real limits are?

The Azure services scale easily. The limits that you will hit first are the ones shared by all users.

LimitWhat happensWhat to do
Model quota (tokens per minute)Calls are throttledRetry with backoff, keep the context lean, use a smaller model for simple runs, set a token budget per run
Business Central API limitsRequests are throttledSet the gateway rate limit below the Business Central limit, read only the fields you need, reuse stable reads inside a run
One very busy userTheir lane gets longKeep runs short and drop repeated events
Cosmos DB throughputRequests are throttledKeep documents small, start serverless and move to provisioned throughput when the load is steady
Service Bus throughputMessages queue upMove to the Premium tier when you need isolation or higher volume

Check the quotas of your subscription and region before go-live, because they differ and change.

In the follow-up agent, two choices follow from these limits:

  • Stagger the daily review. If every buyer’s review timer fires at the same minute, all runs hit the model and Business Central together. Give each buyer a slightly different due time.
  • Review in slices. A buyer with many open orders does not get one huge run. The review reads orders in groups, saves progress after each group and continues in the next run, so each run stays short and inside the token budget.

Keep runs cheap and fast:

  • Load only the instructions on every run, and read notes on demand.
  • Let read tools return only the fields the agent needs.
  • Put a limit on tool calls and tokens per run, so a confused run ends cleanly.
  • Make every step idempotent, so a retry never sends the same reminder twice.

Measure before you tune:

Track the run duration, the age of the oldest message in each queue, the tokens per run and the number of throttled calls. An alert on message age tells you early that the system is falling behind. Before go-live, replay a day of real events against a test environment and watch which limit you reach first.

Do you always need all this?

A fair question at this point: Business Central now has an Agent SDK for AL, and Logic Apps has its own agent loop. Don’t they already follow Anthropic’s pattern? Partly, yes. The five building blocks are not a design you must rebuild every time; they are a checklist. The real question is how many of them a platform already gives you, and what it costs to add the rest.

Building blockAgent SDK in ALLogic Apps agent loopThis architecture
InboxYes: tasks wait in a queue, created from actions, business events or emailsPartly: a trigger starts a run, but there is no per-user order or duplicate checkYes
TimersNot built in: add them with the job queuePartly: recurrence triggers, no follow-ups the agent sets itselfYes
Memory across runsPartly: instructions and the task’s messages, no shared notesNo: history lives inside one runYes
PermissionsYes, and strong: the agent is a BC user with its own permission setsPartly: connections and managed identityYes
ApprovalsYes: user intervention pauses the taskYes: a Teams card, while the run waitsYes, without a waiting run
Outbox and pacingNot built inNot built inYes

Two more things matter. An AL agent works inside Business Central through its user interface, which is ideal when the work lives there and less so when the core of the job is elsewhere, such as vendor emails. A Logic Apps agent loop is great for short, single-event jobs, but its tools are actions only, without control flow, and Microsoft suggests about ten of them at most.

So the rule of thumb is simple:

  • The work stays inside Business Central and tasks are short: use the Agent SDK in AL.
  • One event, one short job across a few services: use a Logic Apps agent loop.
  • The work lasts days, crosses several systems, needs memory and fine control over risk and messages: that is when the architecture in this post pays off.

The example in this post is the third case: replies arrive by email, a follow-up can last weeks, and the agent must remember each vendor and each order. The options are not exclusive either. An AL agent could be one of the tools this architecture calls, and Logic Apps already runs its edges.

Conclusion and key takeaways.

An always-on agent is a small loop with good plumbing around it, and every piece of that plumbing already exists on Azure.

  • Events wake the agent; nothing runs in between.
  • State lives outside the run, so a crash costs only a retry.
  • The agent never holds a secret, and risky actions wait for a person.
  • Use AI for text and judgment, not for what Business Central already calculates.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.