Engineering · 11 min read

Published

AI agents: beyond the basics

What it takes for an agent that works in a demo to hold up in production as well, and what you should ask the supplier to show before it is allowed to run with no one watching.

In AI agents: the basics we described what an agent is: it works towards a goal, chooses the steps to get there itself and can only use the tools that a framework of ordinary code gives it. The next question is what it takes for such an agent to cope with everyday work when no one is sitting beside it.

We will stick to one example: a wholesaler where an agent handles returns. It reads the customer's email and attached images, retrieves the order from the ERP system, checks the return terms and puts a proposed credit in the approval queue. That is where a human takes over.

1. The demo shows the best case

In the demo, someone has picked out the returns: the order number is correct and the image shows the damage. The person demonstrating the agent follows every step and can stop it if anything looks odd.

An ordinary Tuesday in production looks different. One customer writes the invoice number where the order number should be. Another replies in an old thread about a completely different order. One image is a screenshot of a screenshot. The ERP system is down for half an hour for an update. No one is watching, and an error that would have been caught straight away in the demo can be repeated in every return that comes in, until someone in finance wonders why the credits do not add up.

The model is the same in both cases. The difference lies in the code and the routines around it.

2. Before anything reaches the model

The first safeguard is ordinary code that checks what comes in. Does the order number exist in the ERP system? Does the order belong to the same customer the email came from? Can the attachment be opened? A return that fails the checks goes straight to a case handler with the reason stated, for example that the order number is missing. The model never gets to see it.

The email and the images are also written by someone outside the company. We assume that an agent can be tricked by content it reads. OWASP puts exactly that risk, prompt injection, first on its list of security risks in applications built on language models. The attack can come indirectly, through files and web pages the model reads, and the instructions can be hidden in an image sent along with harmless text. According to OWASP it is unclear whether there is any reliable way to prevent the attack at all, so what can be controlled is what a successful attack can lead to.

So the content of the email is treated as data, never as instructions, and an agent that has read untrusted text must not be able to trigger payments or pass data on. In the example, the agent can put proposals in the approval queue, but it has no tool that issues credits, makes payments or passes customer details on.

3. While the agent is working

Three things can go wrong during a run: a system does not respond, the agent cannot decide the case, or the run is interrupted. What happens then is decided before the agent goes into production.

When the ERP system does not respond, the error is usually temporary. The agent waits and tries again, waiting longer after each attempt, up to a maximum number of attempts. If the system replies that the order does not exist, asking again will not help, and the case goes to a case handler. Every call that changes something, such as a proposal in the approval queue, carries a unique key. If the same call arrives twice, the receiver rejects the second one, so a retry never produces two credits for the same return.

When the agent cannot decide a case, it hands it over to a case handler, together with what it managed to find out and the question it could not answer. If it guesses instead, the result is a credit, calculated on the wrong order, that looks just as certain as all the others. It is only discovered when the customer gets in touch or at the next reconciliation. The principle applies to the whole workflow: ordinary code where that is enough, a model where one is needed, a human where there is ambiguity, accountability or consequences that cannot be undone.

If the overnight run is interrupted halfway through, it must be able to continue. The agent saves its state after each completed return, outside the model, so that a restart begins at the next unprocessed return and no return is handled twice.

On top of that comes a cap on each run: on model calls, on writes to the ERP system and on total time. Otherwise an agent that gets stuck in a loop keeps making calls until someone sees the invoice from the model provider. Someone should get a warning before the cap is reached, and at the cap the run stops. The caps are set per workflow in the configuration.

4. Afterwards: the log must answer questions

The question often comes weeks later: why did this customer get a full credit for a return that should have given half? The log must be able to answer it without anyone having to guess.

That means every action the agent takes is logged and traceable. For each return it must be possible to see what came in, what the agent retrieved and from which system, which version of the return terms and which model version were used, what the agent proposed and who approved it. The versions are needed because both the rules and the model change over time. The log is structured so that it can be searched, it is kept on your side and it can be read without the developer's help.

5. Between runs: what changes

The agent changes even when you do not touch it, because the model underneath has a best-before date. In Microsoft Foundry, a generally available model has its retirement date set at launch, 18 months ahead in the standard case, and the date cannot be pushed back. Deployments of the types Global Standard, Data Zone Standard and Standard are automatically upgraded to a replacement model when the model version is retired, unless the customer has configured otherwise. Anyone who turns the upgrade off instead has a deployment that stops working on that same day. Provisioned deployments are moved by hand. A notification goes out at least 60 days in advance. Microsoft is only one example, and the same question applies wherever your model runs.

The switch becomes manageable with a test set of real returns from your business: the common ones, the exceptions that actually occur and a few where the right answer is for the agent to hand over. Each case has an expected result. The test set is run on every change, whether it concerns the code, the instructions to the model, a rule or the model version, and a worse result stops the release. A new model version can then be tried against your own cases before it takes over. We describe how outcome and path are measured separately in The model is the easy part.

The changes you make yourselves concern rules more often than code: how many days after delivery a return may come in, or the amount above which a case always goes to a case handler. If that kind of thing sits in the instructions to the model, every change means searching through a long text. In production the rules sit in a table that the process owner maintains, and the instructions only say how the agent should use them.

Prompts, rules and model versions are handled as code changes. They are version-controlled, run against the test set and go into production only once you have approved the release. The history shows who changed what, and a change that gave worse results can be rolled back.

We also work with shadow mode before autonomy. The agent first runs alongside the existing work without changing anything, and its proposals are compared with what the case handlers did. Every discrepancy becomes a new test case. After that the agent may act with every action reviewed, and it gets more independence step by step.

6. What the Cybersecurity Act adds

The Swedish Cybersecurity Act (2025:1506) has applied since 15 January 2026 and requires appropriate and proportionate security measures based on risk. Under Chapter 2, Section 3, the measures must cover at least ten areas. Four of them directly concern an agent in production: incident handling (point 2), continuity management and crisis management (point 3), security in the acquisition, development and maintenance of network and information systems (point 5) and policies and procedures for assessing the effectiveness of the security measures (point 6).

As we read it, retries, saved state and defined responses to errors belong to continuity, version control and approval per release to development and maintenance, the test set to the assessment of whether the safeguards work, and the log to incident handling.

Incident handling comes with deadlines. A significant incident must be reported to the National Cyber Security Centre (NCSC) at the National Defence Radio Establishment (FRA) as soon as possible and no later than 24 hours after you became aware of it, followed by an incident notification within 72 hours and a final report within one month. The Act's definition of a significant incident:

"An incident shall be considered significant if it has caused or is capable of causing severe operational disruption of the service provided or financial loss for the entity concerned, or if it has affected or is capable of affecting other natural or legal persons by causing considerable damage." (Chapter 2, Section 5, second paragraph; our translation)

You make that assessment yourselves. If an agent with write permissions in your systems is involved in an event that may be significant, you need to be able to say within 24 hours what it did, with which inputs, in which systems and when. A log that only the developer can read, or that exists only at the supplier, is not enough at that point.

Under the regulations on security measures (MCFFS 2026:11, Chapter 1, Section 1 and Chapter 4, Section 21), the organisation must log relevant security events in order to be able to investigate shortcomings in its cybersecurity, provided it is covered by the Act and does not operate solely in the five sectors the regulations exempt. The general advice says that the logs should show what happened, which user and which system first recorded the event, which information and which systems were affected, and when. The section concerns security logging, but an agent's log needs to be able to answer the same questions.

If a supplier builds the agent for you, then since 1 October 2026 you must ensure that the supplier meets the security requirements of the regulations in the parts the supplier is responsible for, provided you are covered by the Act and do not operate solely in the five sectors the regulations exempt. Before entering into the contract, you must then assess whether the supplier can meet the cybersecurity requirements that have been set, for the entire term of the contract (MCFFS 2026:11, Chapter 1, Section 1 and Chapter 4, Section 1). We describe what the contract should contain in What the Swedish Cybersecurity Act requires of your suppliers. What is appropriate and proportionate for your particular agent is decided by your own risk assessment.

7. Ask to see it in operation

Test the agent as you would in a demo, but choose the cases yourselves. Ask whoever built the agent to show the following in the environment where it will run:

  1. A return with an order number that does not exist. Where does it end up, and with what reason?
  2. An email with an instruction to the agent in the text. Which tools does it still have afterwards?
  3. An outage in the ERP system in the middle of a run. Does the run continue where it left off, and is anything duplicated?
  4. A case the agent cannot decide. What does the case handler who takes over receive?
  5. The caps for a run. Where are they set, and who gets a warning before they are reached?
  6. A case from last week. Can you see what the agent did, with which rules and which model version, without the developer's help?
  7. The model version's retirement date. What happens to the deployment on that day, and when was the test set last run against a new version?
  8. A changed return rule. Who may change it, does the change show up in the history, and is the test set run before it takes effect?
  9. The results from shadow mode. How did the agent's proposals differ from the case handlers', and did the discrepancies become test cases?

Write in anything that cannot be shown today as a condition for the agent going into production.

Sources

  1. Swedish Cybersecurity Act (Cybersäkerhetslag (2025:1506)) Chapter 2, Section 3, second paragraph, points 2, 3, 5 and 6; Chapter 2, Section 5, first paragraph (24 hours) and second paragraph (significant incident); Chapter 2, Section 6 (72 hours); Chapter 2, Section 8 (final report within one month); transitional provisions, point 1
  2. Swedish Cybersecurity Ordinance (Cybersäkerhetsförordning (2025:1507)) Section 6 (incident reports are made to the CSIRT unit) and Section 31 (the National Defence Radio Establishment is the CSIRT unit)
  3. MCFFS 2026:11, regulations and general advice on security measures and management training for essential and important entities (föreskrifter och allmänna råd om säkerhetsåtgärder och ledningens utbildning för väsentliga och viktiga verksamhetsutövare) Chapter 4, Section 1, second and third paragraphs (p. 12); Chapter 4, Section 21 with general advice (p. 21); entry into force 1 October 2026
  4. Microsoft Learn, Foundry Models lifecycle and support policy The sections Lifecycle timeline commitments, Automatic upgrades, Notifications and Frequently asked questions (versionUpgradeOption, that retirement dates cannot be extended); page updated 24 July 2026
  5. OWASP Top 10 for LLM Applications 2025, LLM01:2025 Prompt Injection The section Indirect Prompt Injections with the paragraph on multimodal models, and Prevention and Mitigation Strategies (the introduction and points 4 and 6)
  6. Anthropic, Building effective agents The section When (and when not) to use agents, published 19 December 2024

Would you rather have someone do the maths on your own workflow than read about it?

Book 20 minutes

More articles.

See all articles
Engineering

AI agents: the basics

10 min read

What an AI agent is, what surrounds the model, where the permissions should sit and what the agent must never be able to do, whatever it reads.

Engineering

The model is the easy part

11 min read

What decides whether an AI agent holds up in production once the model has been chosen, and which questions show whether a supplier has done that work.