Part II · Foundations

Agent Engineering

How an agent works once it runs: the loop it follows, the pattern that fits, what it sees and remembers, and how you prove what it did. Agentic AI decides where agents add value; this topic makes them work.

Part 1 of 5

How an agent runs

The loop between a request and a result, and when a workflow is better.

The agent loop

An agent is software that uses a language model to pursue a goal, choosing its own steps and calling tools, which are actions such as looking up a customer or sending a payment instruction. Whatever the product, one cycle repeats: the model proposes a step, your software checks it and runs it, and the result goes back to the model.

  1. Ask

    A person, a system or an event sets the goal.

    • The goal and the limits
    • Who it acts for
    • What it may use
  2. Propose

    The model reasons and picks the next step.

    • An answer
    • Or a tool, with its input
    • Or a plan for later steps
  3. Check and run

    Software decides whether the step may happen.

    • Identity, rights and limits
    • A person approves when needed
    • Then the tool runs
  4. Observe

    The result comes back as data for the next step.

    • The result or the error
    • Recorded in the trace
    • Input to the next round

Back to step 2, Propose, until the goal is met, a limit is reached or a person takes over.

  1. The model proposes, software acts

    The model names the tool it wants and the input it would give it. Your application decides: it runs the call only after checking who asks, what the agent may do and whether a person must approve.

    Explored in Separate reasoning from execution

    • Tool call
    • Runtime checks
    • Approval
  2. Ask for structure

    Ask for answers and tool calls in a fixed structure, like a form with named fields. Software can then validate them before anything happens, because it no longer has to guess the meaning of free text.

    • Structured output
    • Validation
  3. Results are data, not orders

    A tool result, a web page or a document is input to reason about. Whatever it says, it never adds rights or changes the goal. Text hidden in such content that tries to give the agent new instructions is called prompt injection.

    Explored in Content is data, never an instruction

    • Untrusted input
    • Prompt injection
  4. Know when to stop

    Give every run a budget for steps, time and cost, and a rule for repeated failure. At the limit the agent stops and hands over, with what it tried.

    Explored in Try and try again, but eventually stop

    • Step budget
    • Stop rule
    • Handover

Agent, workflow or both

Not every task needs an agent that decides its own steps. A workflow is a fixed sequence of steps. Dependable systems tend to be mostly workflow with agent steps inside, so the useful question is how much freedom each step needs.

  1. Known path: a workflow

    When the steps are known in advance, write them down as a workflow. It is cheaper, faster and easier to test than an agent that finds its way each time.

    Explored in Not everything needs an agent

    • Fixed steps
    • Testable
  2. Open path: an agent

    When the route has to be found case by case, let an agent choose the steps, within the tools and data it was given.

    Explored in When to use an agent

    • Open tasks
    • Bounded tools
  3. Mostly both

    A workflow carries the process and calls an agent where judgement is needed. Branches and parallel paths are explicit, so each one can be tested.

    • Agent steps
    • Branches
    • Parallel paths
  4. Pause, approve, resume

    A long task saves its state, a record of where it stands, at every checkpoint. It can wait days for an approval and continue where it stopped, without starting again or repeating an action.

    Explored in Long running agents

    • Checkpoints
    • Saved state
    • Resume
  5. Where the loop runs

    Inside your own application, on a managed agent service or in a workflow engine. Choose by who operates it, how long tasks run and where the data may go.

    Explored in Run it where it belongs

    • In the application
    • Managed service
    • Workflow engine

Part 2 of 5

Tools and patterns

Tools, retrieval, plans and teams, and how an agent checks its own work.

Tools an agent can use well

The model knows a tool only through its name, its description and its inputs, and cannot see the code behind it. If a careful new colleague would pick the wrong tool or give it the wrong input after reading the label, the model is likely to do the same.

  1. One clear job

    Give the tool a name and a description that say what it does, when to use it and when not to. Narrow tools are easier to choose and use correctly than one that does everything.

    Explored in Developers choose, and now agents do too

    • Clear name
    • Narrow scope
    • When not to use
  2. Typed in, predictable out

    The tool accepts only input of the right type and with allowed values, and it returns output in a fixed shape that the next step can read. The schema, the written description of those types and shapes, lets software check both sides.

    • Schema
    • Allowed values
    • Fixed output
  3. Fail safely

    When a call fails, the tool returns a clear error the agent can act on and leaves no half-finished change behind. Repeating the same call gives the same outcome, so a retry does no harm.

    Explored in HTTP verb

    • Clear errors
    • No partial changes
    • Safe to repeat
  4. Generated queries, read-only

    When an agent writes its own query, give it the real schema to work from and run the query with read-only rights on a copy made for that purpose.

    • Real schema
    • Read-only
    • Separate copy
  5. The model must handle tools

    Not every model produces reliable tool calls, smaller ones especially. Test this on your own tools before you choose a model.

    Explored in Choose the model per task

    • Tool-call accuracy
    • Model choice

Retrieval that checks itself

Retrieval means looking up current, permitted sources before answering, so the answer can cite them. A single search often returns passages that are old, off topic or too thin, so retrieval works best as a small loop with a set number of tries, which guarantees that it ends.

  1. Search

    Turn the question into a query.

    • Pick the right source
    • Use the real index or schema
    • Filter by rights and date
  2. Judge

    Score what came back.

    • Relevant to this question?
    • Recent, and from a trusted source?
    • Enough to answer?
  3. Improve

    Rewrite the query, or try another source.

    • Rephrase or narrow it
    • Rank the best results first
    • Within a set number of tries
  4. Answer or hand over

    Answer with sources, or say what is missing.

    • Sources and queries attached
    • Gaps stated plainly
    • A person when it stays unclear
  1. Cite what it used

    Every answer carries the sources and queries behind it, so a person can check it and an auditor can trace it.

    Explored in Trace every step

    • Sources
    • Audit trail
  2. Balanced sources

    Check that retrieval does not lean on one kind of source, and review answers for skew across groups of customers.

    Explored in Fair outcomes

    • Representative sources
    • Skew checks

Plans you can inspect

On a longer task, an agent that simply acts can travel a long way in the wrong direction before anyone notices. A plan written first as structured data can be checked, approved and followed step by step before anything has been done. Plans also change, and the reason is recorded.

  1. Break the goal down

    The goal becomes subtasks, and each one has an owner, the input it needs and a definition of done.

    • Subtasks
    • Owner
    • Definition of done
  2. A plan is data

    A structured plan can be checked by software, approved by a person and tracked step by step. Free text is harder to check and track.

    Explored in Plan mode

    • Structured plan
    • Approval
    • Progress
  3. Route each step

    A single subtask goes straight to the right specialist. Several go through a coordinator that keeps the task list and tracks progress.

    • Specialists
    • Coordinator
    • Task list
  4. Re-plan on evidence

    When a step fails or new facts arrive, the plan changes, and the change is recorded with its reason.

    • Feedback
    • Re-plan
    • Recorded

One agent or a team

Every hand-off between agents is a place where context can be lost or a mistake passed on, so start with one agent and split only when there is a reason. When you do split, each team pattern suits one kind of task and carries one risk of its own.

  1. Sequence

    Each agent works on the result of the one before.

    • Use when the order is fixed: draft, check, approve

    Watch: an early mistake travels down the line

  2. Parallel

    Agents work on parts at once; one step combines the results.

    • Use when parts are independent and speed matters

    Watch: results that contradict each other

  3. Hand-off

    The agent holding the case passes it, whole, to the specialist with the right skill.

    • Use when a request changes topic or needs a specialist

    Watch: context lost at every hand-off

  4. Group discussion

    Agents take turns in one thread; a moderator decides who speaks next.

    • Use when a decision needs several views

    Watch: endless rounds and rising cost

  5. Manager-led

    A lead agent keeps the task list, assigns the work and checks progress.

    • Use when a task is open and has many steps

    Watch: the manager becomes the bottleneck

  1. Split for a reason

    Split when one agent measurably struggles: its context, everything the model sees at a step, fills up, it picks the wrong tool, or its instructions conflict. Parallel tasks that each need a fresh context, and separate permissions or audit trails, are further reasons. How advanced a team looks is no reason.

    Explored in Control from day one

    • Context
    • Tool choice
    • Parallel work
    • Permissions
  2. Split by context, not by org chart

    An agent for every team copies the organisation chart and brings overlapping agents, conflicting rules and extra waiting time. Give each agent work that needs little from the rest and that hands back a compact result.

    • Independent research
    • Clean interface
    • Verification
  3. Fold in, one step at a time

    Often one agent with skills and a few thin tools does the work of several specialists. Procedure moves into skills, and hard limits such as approval and permissions into the tools. Fold in one subagent at a time, measured on a small end-to-end eval, and keep it only if the folded version scores worse.

    Explored in Evaluate all the time · Soul, memory & skills

    • Skills
    • Thin tools
    • Eval first
  4. Central or among peers

    One coordinator is easy to follow, but it is a single point of failure. Agents that coordinate among themselves keep working when one fails, but are harder to trace. Most teams mix both.

    • Central
    • Peer-to-peer
    • Hybrid
  5. Shared agents for shared jobs

    Escalation, notification and audit work best as small shared agents that every process can call.

    Explored in Share the platform, keep agents small

    • Shared agents
    • Reuse
  6. Across organisations

    An agent of another firm is a black box behind a protocol such as A2A, the Agent2Agent protocol, a standard way for one agent to hand work to another. It publishes a card that says what it can do. You send it a task, follow its status and receive the results, but never its reasoning.

    Explored in A2A: agent to agent

    • Agent card
    • Agent to agent
    • Long-running tasks

Check before it counts

A language model writes a wrong answer in the same fluent tone as a right one, so nothing in the output warns the reader. The check has to be designed in.

  1. Review its own work

    Before an answer counts, the agent compares it with the goal, the sources and the rules, and corrects what does not hold.

    • Self-review
    • Reflection
  2. Change the method, not only the answer

    When the same kind of mistake comes back, the agent changes how it searches or plans, and records why.

    Explored in The memory lifecycle

    • Learn from errors
    • Method
  3. Say when unsure

    Uncertainty is normal. A good agent says what it does not know and asks a question, and does not fill the gap with a guess.

    • Confidence
    • Ask
    • No guessing
  4. A second opinion is not proof

    Another agent can challenge the work. Tests, sources and people decide whether it is right.

    Explored in Cross-agent verification

    • Independent check
    • Tests

Screens, only where nothing else exists

Some systems can only be reached through their screen, because they offer no API, the interface other software uses to ask for data or actions. An agent can then operate the screen the way a person does, which is called computer use. It is slow, costly and easy to break.

  1. An interface first, then a script

    An API or a tool call beats reading a screen. Where none exists, let an agent find the way once and a script repeat it. Keep the agent for pages that change.

    Explored in Where the logic lives

    • API first
    • Explore, then script
    • Computer use
  2. Guardrails on screen

    Guardrails are checks around the model that block what is not allowed. Here the agent may visit allowed sites only, reads before it acts and checks what is on screen before it submits. A person signs in, so the agent never sees the password. Each task has a budget, and the agent keeps evidence of what it did and does not store every screenshot.

    • Allowed sites
    • Person signs in
    • Check before submit
    • Evidence

Part 3 of 5

Context engineering

What the agent sees at each step decides what it does.

From prompt to context

A prompt is the instruction you give a model. Context is wider: everything the model sees when it takes one step. The model has no other source, so the quality of a step depends on what was put in front of it, and context deserves as much design as a screen.

  1. Instructions

    Role, rules and examples.

    • What it is for
    • What it never does
    • Good and bad examples

    From the owner of the agent

  2. Knowledge

    Facts and documents for this task.

    • Retrieved passages
    • Records and data
    • Policies

    From retrieval, with rights checked

  3. Tools

    What it can call, and how.

    • Names and descriptions
    • Input and output
    • Only those this task needs

    From the tool registry

  4. History

    What has happened so far.

    • The conversation
    • Earlier results
    • Task state

    From this run and the task record

  5. Preferences

    What this person wants.

    • Language and tone
    • Standing choices
    • Earlier corrections

    From memory about this person

  1. Start from the result

    Define what a good outcome looks like, list what each step needs to get there, and build the routes by which that information arrives.

    • Result first
    • Needs per step
    • Routes
  2. Up front or on demand

    Load what every step needs. Let the agent fetch the rest when it needs it, such as a procedure, a document or a tool.

    Explored in Soul, memory & skills

    • Preloaded
    • On demand
  3. Only the tools this task needs

    Every tool description takes room and attention in the context, so choose the few tools a task needs and leave the rest out.

    • Tool selection
    • Fewer tools

For coding agents, the same idea is in Context patterns.

Keep the context clean

The context window is the amount of text a model can take in at one step, and a long task fills it quickly. Once it is full, useful material is lost or buried under old turns. Isolation also stops a side task from filling the main window with its own detail.

  1. Write it down

    Keep notes outside the window.

    • Plans, findings and decisions
    • A short record of the task state
    • Read back when needed
  2. Select

    Bring in only what this step needs.

    • The right documents
    • Relevant memories
    • A few fitting tools
  3. Compress

    Summarise what has grown long.

    • Long conversations
    • Large tool output
    • Keep decisions and open questions
  4. Isolate

    Give a subtask its own space.

    • A sub-agent with its own context
    • A sandbox for code or data
    • Only the result comes back

When context goes wrong

A weak answer can look like a weak model when the cause is what the model was given. Each failure has a recognisable cause and a fix, which makes it easier to diagnose than a general complaint that the agent answers badly.

  1. Poisoned

    A wrong fact or a hidden instruction gets in and is repeated in every later step. Validate before anything is saved, quarantine what looks suspicious and keep the source.

    Explored in Add two new ones

    • Validate
    • Quarantine
    • Source
  2. Distracted

    The history has grown so long that the model follows old turns and loses the task. The fix is to summarise it and to restate the goal.

    • Summarise
    • Restate the goal
  3. Confused

    The model faces too many tools or documents that look alike and picks the wrong one. Offer fewer tools, clearly named and chosen for this task.

    • Fewer tools
    • Clear names
  4. Clashing

    When two sources disagree and both stay in the context, the model may follow the wrong one. Remove the outdated one, prefer the authoritative source and flag the conflict.

    Explored in Data & Knowledge

    • Prune
    • Authoritative source
    • Flag
  5. Inspect without exposing

    Log what went into each step as counts, ids and fingerprints. You can then debug a step without copying customer data into logs.

    • Counts
    • Ids
    • Fingerprints

Part 4 of 5

Memory

What an agent keeps, and how it stays correct.

Kinds of memory

Without memory every conversation starts from zero, and the customer has to explain everything again. Memory removes that, but what an agent keeps can be wrong, out of date or sensitive, so it brings a duty with it.

  1. Short-term

    What this task needs now: the goal, the recent turns and the results so far. It ends with the task, unless something is kept on purpose.

    • Working memory
    • Session
  2. Long-term

    What carries over between sessions: facts, preferences and earlier outcomes.

    • Across sessions
    • Preferences
  3. People and things

    Customers, products and projects, and how they relate, so the agent knows who and what is meant.

    • Entities
    • Relations
  4. What worked, what failed

    Earlier runs and their outcomes, so the agent repeats the method that worked and avoids the one that failed.

    • Episodes
    • Lessons
  5. Who the agent is

    Its role, tone and limits, the same in every session.

    Explored in Soul

    • Persona
    • Consistency

Agentic Work sorts memory by who owns it; here it is sorted by what it does. Both views apply: Learn once, use everywhere.

The memory lifecycle

Saving every message would fill memory with items that may be wrong, outdated or planted by someone, so each memory goes through a short life, from choice to deletion.

  1. Decide

    Choose what is worth keeping.

    • A correction or a preference
    • A method that worked
    • Not every message
  2. Check

    Validate before it is saved.

    • Source and owner
    • Valid until when
    • Not a hidden instruction
  3. Store

    Keep it where it can be governed.

    • With source and date
    • Classified like other data
    • Visible to its owner
  4. Use

    Retrieve what fits the task.

    • Only what this task needs
    • Rights checked again
    • Shown with where it came from
  5. Update or forget

    Keep it current.

    • Replace what is outdated
    • Delete on request
    • Record what was removed
  1. A separate step learns

    After a task, a separate step reviews it and keeps only what is worth learning, such as a correction, a preference or a better method.

    Explored in Teach it once

    • Review
    • Learning
  2. Poisoned memory spreads

    A wrong memory shows up in every later answer. That is why it is checked before it is written, and again when it is used.

    Explored in Memory is data

    • Poisoning
    • Validation
  3. Forgetting is a feature

    Let outdated facts expire, honour deletion requests and keep a record of what was removed, without keeping the content.

    Explored in GDPR · Retention & deletion

    • Expiry
    • Right to erasure

Part 5 of 5

Production and proof

What it takes to run agents for real, and to prove what they did.

The model is the small part

A demo is a model and a prompt, and it works until real customers, real money and real data are involved. Then the question is no longer how clever the model is. The model is one part and can be swapped, while everything around it stays.

  • Identity

    Who the agent is, and for whom it acts.

    Explored in Identity & Access

  • Tools and data

    What it may reach, and through which gateway.

    Explored in Integration

  • State

    Where a long task is kept, so it can pause and resume.

    Explored in Agent, workflow or both

  • Quality

    Whether it still does the job, after every change.

    Explored in Evaluate all the time

  • The model

    Reasons and proposes the next step. It can be swapped; everything around it stays.

  • Visibility

    Every step traced, every cost counted.

    Explored in See it

  • Limits

    Budgets, rate limits and a switch to stop it.

    Explored in Stop it

  • Failure

    Retries, fallbacks and a person to hand over to.

    Explored in Typical failures and their fixes

  • Proof

    Records that show what it did, and that hold up.

    Explored in Prove what it did

Evaluate all the time

An evaluation, or eval, is a repeatable test of how well an agent does a task. It matters more for agents than for ordinary software because the same question can get different answers, and the model, the prompt and the data underneath keep changing. A run that worked yesterday says little about today.

  1. Define success

    Agree what a good outcome is.

    • With the business owner
    • Per task, not per model
    • A set of real cases
  2. Test before release

    Run the test set as a gate.

    • Quality and safety
    • Cost and speed
    • No release below the bar
  3. Check after deploy

    A short test in the live setting.

    • Tools and rights connected
    • One run, end to end
    • Roll back if it fails
  4. Watch in production

    Score real runs, continuously.

    • Samples scored
    • Latency, cost and errors
    • Ratings and silent signals
  5. Learn

    Every failure becomes a test.

    • Added to the test set
    • Cause recorded
    • Fixed before it returns
  1. Silent signals count

    People rarely rate an answer. They rephrase, repeat the question or give up. Count those as feedback too.

    Explored in Watch quality in production

    • Rephrasing
    • Repeats
    • Drop-off
  2. Compare before you switch

    Run a new model or prompt in shadow, where it answers the same requests as the current one without its answers being used, or side by side on a share of real traffic, before it takes over.

    Explored in Test before you switch · Re-evaluate after every change

    • Shadow run
    • Side by side
    • Release gate

Typical failures and their fixes

Agents tend to fail in repeating ways, so it helps to give each failure a name and a standard first response. Recognising the pattern early saves a long search for the cause.

  1. Different answers to the same question

    Reduce randomness where precision matters, sharpen the instructions or split the task into smaller steps.

    • Consistency
    • Smaller steps
  2. Stuck in a loop

    Set clear stop conditions and step budgets, and switch method after repeated failure.

    Explored in The agent loop

    • Stop conditions
    • Budgets
  3. Wrong tool, wrong arguments

    Improve tool names and descriptions, and test every tool on its own, outside the agent.

    Explored in Tools an agent can use well

    • Tool tests
    • Descriptions
  4. A team that drifts

    Give each request one owner through a routing agent, and trace every hand-off.

    Explored in One agent or a team

    • Routing
    • Tracing
  5. Errors that cascade

    One wrong output becomes the next agent’s input, across systems. Validate at every hand-off and limit how far one error can reach.

    Explored in How the threat changed

    • Validation at hand-offs
    • Limited reach

Run it at scale

A pilot runs a few tasks at a time. Across an organisation the same agent runs many at once, instances restart, systems get busy and every call has a price.

  1. Keep state outside the process

    Store task state in a shared store, so any instance can continue a task and a restart loses nothing.

    • Stateless
    • Shared state
  2. Limits that protect the rest

    Cap parallel work, slow down intake when systems are busy and retry with growing waits, so one busy agent does not take others down.

    Explored in Limits that hold

    • Parallel limits
    • Slow intake
    • Growing waits
  3. Cost levers, in order

    First the right size of model for each step, then routing by difficulty, then caching what repeats.

    Explored in Route on purpose · Know the cost

    • Right-size
    • Route
    • Cache
  4. Every tool server is a dependency

    Pin its version so it cannot change unnoticed, scope its rights to what the agent needs, validate what it returns, limit its rate and keep secrets out of it. Servers that follow MCP, the Model Context Protocol, a standard way to offer data and tools to a model, are no exception.

    Explored in Built for safe use

    • Pinned
    • Scoped
    • Validated
    • No secrets

Prove what it did

When an agent acts for a customer or moves money, someone will eventually ask what it did and whether the record can be believed. An ordinary log cannot settle that, because people and agents can change it. A signed record settles part of the question, and it helps to know which part.

A signed record shows

  • Which key signed it, and so which agent, if that key is registered to it
  • That the record has not changed since
  • Its place in the chain, so a record missing in between shows
  • Which approval it carried
  • When it was made, if a trusted clock stamped it

It does not show

  • That the action was the right one
  • That current policy allowed it
  • That the other system carried it out
  • That every action was recorded
  • Which person was behind the request
  1. Sign, chain and anchor

    Each action becomes a record: what was asked, which tool, a fingerprint of the input and output (a short code that changes when the content does), the result and the time. Each record is written in one fixed form, signed and linked to the one before, and the latest link is also kept outside the system. A changed record, a gap or a cut-off end then shows. Check a signature only with a key obtained separately, never one carried in the record. Agree how long records are kept, and who owns them.

    • Signed
    • Chained
    • Anchored
    • Retention
  2. Keys stay outside the agent

    The signing key sits in a key vault, a store built to protect secrets, outside the agent, and it is replaced on a regular schedule. If a key leaks, records it signed from the moment of the leak are untrusted, and that moment can be earlier than the day it was found.

    Explored in Non-human identities

    • Key vault
    • Rotation
    • Revocation
  3. Approval for this action only

    An approval covers one exact action, such as this payment to this account for this amount. It is used once and checked where the action runs.

    Explored in Permission becomes a mandate · AP2: the payment

    • Exact action
    • Single use
    • Checked where it runs
  4. Valid is not the same as allowed

    A signature can be valid and still be refused: the policy has changed, the key was retired, the approval expired or it belongs to another action.

    • Policy version
    • Expiry
    • Wrong action
  5. Unknown outcome, no blind retry

    When a call times out, first find out whether it ran. A payment is never sent twice because nobody checked.

    Explored in HTTP verb

    • Check first
    • Safe to repeat
    • Reconcile
  6. Records are not governance

    A perfect record of a bad decision is still a bad decision. Records support oversight; they do not replace it.

    Explored in Govern the agents

    • Oversight
    • Accountability

Questions before you build

The questions follow the order of the topic, from whether it needs an agent to whether you can stop it and prove what it did. If an answer is still vague, that part of the design is not ready to build.

  • Does it need an agent?

    Or would a workflow, a rule or a person do the job better?

  • What may it reach?

    Tools, data and rights, and who approves what.

  • What does it see?

    The context at each step, and what it may remember.

  • How do we know it works?

    Success defined, tested before release and watched after.

  • Can we stop it, and prove what it did?

    Limits, a switch to stop it and records that hold up.

Where agents add value, and in which order to build them, is in Agentic AI.

Let’s talk about the agentic enterprise.

Message me on LinkedIn with your challenge, audience and timing to explore a talk, workshop or advisory engagement.

Discuss your challenge on LinkedIn