AI Agents

How to Build an AI Agent for a Business Workflow

Hand tools laid out on a workbench in an organised workshop One job, done properly.

To build an AI agent that a business can rely on, pick one job, check that it really needs an agent, and give the model the fewest tools that get the job done. Add guardrails and a human approval step for risky actions, test it against real cases before launch, and start with a single agent.

None of that needs a research team. Most of it is decisions about the job, the permissions and the checks, and those decisions matter more than which model or framework you pick. This guide walks through the sequence we follow. If you are still getting to grips with the basics, start with what is an AI agent and come back.

AI agent vs chatbot vs automation

Before you build anything, be clear about which of these three you need, because they are different tools. OpenAI’s practical guide to building agents defines agents as systems that independently accomplish tasks on your behalf. It says that simple chatbots and single-turn language model calls, which do not use the model to control workflow execution, are not agents.

Anthropic draws a similar line in Building effective agents. Workflows follow predefined code paths. Agents dynamically direct their own processes and tool usage.

So the chatbot answers, the workflow follows a script you wrote, and the agent decides what to do next. That last ability is what makes agents useful for messy work, and it is also what makes them harder to test and control.

There is a fourth option that people forget: plain code. The Microsoft Agent Framework documentation says that if you can write a function to handle the task, you should do that instead of using an AI agent. We agree. If you want to see where agents do earn their place, our AI agent examples show real jobs.

Step 1: Pick one job and decide whether it needs an agent

Start with the job. OpenAI’s guide gives three signs that a job suits an agent, and each comes with an example.

  • Complex decision-making. The call depends on context and nuance, such as approving a refund.
  • Rules that are hard to maintain. The rulebook has grown so large and tangled that updating it is costly and error-prone, such as vendor security reviews.
  • Heavy reliance on unstructured data. The work involves reading documents or natural language, such as processing a home insurance claim.

If your job shows none of these, the guide says a deterministic solution may suffice. That is a good result. A rule-based automation is cheaper to build and easier to trust.

If the job passes, write a one-paragraph job description before anyone opens an editor. It should cover four things:

  1. Trigger. What starts the job: an email arriving, a form submitted, a record changing.
  2. Inputs. What the agent reads, and where it lives.
  3. Output. What a finished job looks like, in terms you can count.
  4. Sign-off. Who approves the result, and for which actions.

If you cannot fill in all four, the job is not ready to build. A one-week AI readiness assessment exists for exactly that situation.

Step 2: Start with the simplest pattern

Anthropic’s advice is to find the simplest solution that works and add complexity only when needed. That sometimes means a single model call with good instructions, and nothing more.

When one call is not enough, Anthropic describes five common patterns. Here they are with a business example each. The examples are ours.

PatternWhat it doesBusiness example
Prompt chainingSplits a task into a fixed series of stepsDraft a quote, then check it against the price list
RoutingSorts an input and sends it to a specialist pathSend billing questions and sales enquiries to different handlers
ParallelizationRuns parts of a task at the same timeCheck one contract for several kinds of risk at once
Orchestrator-workersOne model breaks the task up and delegatesSplit an unfamiliar request into subtasks and hand each out
Evaluator-optimizerOne model drafts, another critiques, and it repeatsRefine a customer reply until it meets a checklist

In our experience, most first agents need only the first two. Note that Anthropic’s post dates from December 2024. Its patterns still describe the design choices well, but the tooling advice in it has moved on, so treat the vendor SDKs in Step 3 and the final section as the current picture.

Step 3: Choose the model, tools and instructions

OpenAI’s guide breaks an agent into three components: the model, the tools it can use, and the instructions that tell it how to behave. Each needs a deliberate choice.

The model

Prototype with the most capable model you can access. That gives you a ceiling for how well the job can be done. Once you have tests in place (Step 6), try smaller and cheaper models and see where quality holds. Without tests, you cannot tell whether a cheaper model is good enough, so do not switch early.

The tools

OpenAI groups tools into three types:

  • Data tools let the agent read, such as querying a database or searching documents.
  • Action tools let it change something, such as sending an email or updating a record.
  • Orchestration tools let one agent call another.

Give the agent the fewest tools that do the job. Every extra tool is another way for it to go wrong, and every write action needs the checks in Steps 4 and 5.

You connect those tools to your systems in one of two ways: direct API calls, or an MCP server that wraps your systems in a standard interface. Our guide to MCP vs API explains when each fits, and best MCP servers lists ready-made ones. If your systems have no suitable connection yet, MCP server development covers building one.

The instructions

Write instructions the way you would brief a capable new hire. State the goal, the steps, what to do when information is missing, and when to stop and ask. Use your existing procedures as source material. Vague instructions produce vague behaviour.

Step 4: Guardrails and permissions

An agent that can act can also act wrongly, so this step decides how much damage a failure can do. Two entries in the OWASP Top 10 for LLM applications describe the main risks.

LLM01:2025 Prompt Injection covers user prompts or external content altering the model’s behaviour in ways you did not intend. An email the agent reads, or a web page it fetches, can carry instructions. OWASP says it is unclear whether prompt injection can be fully prevented, so design as though some will get through.

LLM06:2025 Excessive Agency is what turns an injection into damage. OWASP names three causes: excessive functionality, excessive permissions and excessive autonomy. An agent that can only read a folder cannot delete it.

The practical answer is least privilege. Give the agent its own credentials, scoped to the job, with read access wherever write access is not needed.

OpenAI recommends layering several guardrails, since no single one catches everything:

  • A relevance check that keeps the agent on topic.
  • A safety check that catches attempts to override its instructions.
  • A filter for personal data.
  • Moderation of harmful content.
  • Safeguards on each tool, rated by risk.
  • Rules-based checks, such as blocklists and length limits.
  • Validation of the output before it goes anywhere.

You will not need all seven on day one. Pick the ones that match what the agent can reach, and add more as you learn how it fails.

Step 5: Put a person in the loop where it matters

Some actions should not happen without a person agreeing. OpenAI names two triggers for human intervention: the agent exceeding a failure threshold, such as repeated failed attempts, and high-risk actions. Those are actions that are sensitive, irreversible or high-stakes, for example cancelling orders, issuing large refunds or making payments.

The agent prepares the action, a person approves it, and then it runs. That keeps most of the time saving, because reviewing is faster than doing.

The Model Context Protocol specification takes the same view for tool use. It says there SHOULD always be a human in the loop with the ability to deny tool invocations, and that applications should log tool usage for audit. You can read the wording in the MCP tools specification.

Decide which actions need approval before you build, not after. A simple test: if the action could not be undone, or would be embarrassing in front of a customer, a person signs it off. As the agent proves itself, you can loosen the rules one action at a time.

Step 6: Test it before anyone relies on it

Testing an agent is closer to evaluating a new employee than to running software tests, because the same input can produce different outputs. Anthropic’s documentation on developing tests starts with defining success criteria, and makes the following points:

  • Make criteria measurable. “Handles refund requests well” is not testable. “Routes 95% of refund requests to the correct queue” is. (The percentage here is an illustration, not a benchmark.)
  • Mirror your real work. Build test cases from the actual mix of inputs the agent will see.
  • Include edge cases. Messy, ambiguous and hostile inputs are where agents fail.
  • Grade with a different model where you can. Another model can score outputs against your criteria.
  • Favour volume over perfection. Many automatically graded cases beat a few hand-graded ones.

OpenAI’s guide makes the same point about order: set up evaluations first, to establish a baseline, and then iterate. A baseline lets you say whether a change to the instructions, the model or a tool made things better or worse.

Collect real examples from the team that does the job today. Ask them for the cases that always cause trouble, and put those in the test set first.

Step 7: Launch small, then grow

OpenAI advises starting with a single agent and moving to multiple agents only when you need to. It also recommends starting small and validating with real users. Several agents handing work to each other multiply the places something can break, so earn that complexity.

In practice, that looks like this:

  • Release to a small group, ideally the people who did the job before.
  • Keep humans on high-risk actions at the start.
  • Read the logs and the failures. Add each real failure to your test set.
  • Widen the agent’s autonomy only where the results justify it.

Compare results against the baseline from Step 6. If the agent saves time and holds quality, add the next job. If it does not, you have learned that cheaply. For the money side of this decision, our guide to AI agent cost covers platform prices, running costs and build prices.

Build it yourself or bring in help?

You have two routes: use a low-code platform, or write code with an agent SDK. Several vendors publish SDKs.

An in-house developer can build a first agent with any of these. The framework matters less than the job definition, the guardrails and the tests above.

Bring in outside help when the agent has to touch several systems, take write actions in them, or meet compliance requirements. Those are the cases where Steps 4 and 5 take most of the effort, and where a mistake is costly.

At CodeLeap, a first agent starts from £5,000 (about $6,500), at a fixed price agreed upfront. That covers one agent doing one named job. The detail of what drives cost is in our AI agent cost guide.

A sensible next step

Write the job description from Step 1: trigger, inputs, output and who signs off. If you can fill it in, you have the start of a build. If you cannot, that gap is the thing to fix first.

If you want a second opinion, our AI readiness assessment helps you pick the job and check it is ready. When you are ready to build, our AI agents and automation service scopes and prices a first agent before any work starts. Book a call and bring the job description with you.

Frequently asked questions

How do I build an AI agent for my business?

Pick one job with a clear trigger, inputs, output and owner. Check that it needs judgement, because a plain rule may do. Use the simplest design that works, give the model only the tools the job needs, add guardrails and a human approval step for risky actions, test against real cases, then launch with a single agent and grow from there.

What is the difference between an AI agent and a chatbot?

A chatbot answers questions in a conversation. An agent uses the model to control the work itself: it decides the next step, calls tools such as your CRM or inbox, and acts on your behalf. OpenAI's guide says simple chatbots and single-turn language model calls that do not control workflow execution are not agents.

Do I need to code to build an AI agent?

Not always. Microsoft Copilot Studio is a low-code route for simpler agents. For anything that spans several systems or needs custom behaviour, teams use code, typically through an agent SDK from Anthropic, OpenAI, Google or Microsoft. Either route still needs the same job definition, guardrails and testing.

How do you stop an AI agent making mistakes?

You cannot remove mistakes entirely, so you limit their cost. Give the agent least-privilege access, add guardrails on inputs, tool calls and outputs, require human approval for sensitive or irreversible actions, and test against real cases before launch. Keep logs so you can see what it did and why, and review them early on.

How long does it take to build an AI agent?

It depends on scope: how many systems the agent connects to, whether it takes actions or only answers, and how much testing the job needs. We do not quote a standard timeline. At CodeLeap a first agent is scoped and priced before work starts, so you know what you are buying before any build begins.

Want to build something like this?

Book a free 30-minute consultation and we'll help you find where automation pays off.

Book a consultation Get a free quote

Keep exploring

Back to all insights

Book a free call with Vivian

COO and co-founder · London

Request a callback

Leave your name and number and we'll call you back.