AI Agent Architecture: How Agents Use Tools, State and Guardrails

AI Agent Architecture: How Agents Use Tools, State and Guardrails

At 9:12 a.m., an AI assistant finished a beautifully polite reply to one unhappy customer. It was supposed to leave the message as a draft. Instead, it used the company’s email tool to send it to the entire mailing list. The message began, “Hi, Derek,” which was unfortunate because 18,000 recipients were not Derek.

By lunch, the marketing team probably had another email to write. This disaster is fictional, though the mistake behind it is entirely plausible. The application gave a drafting assistant the ability to send without checking the recipient or requiring approval. A lovely apology is of limited comfort when it lands in 18,000 unintended inboxes.

Once an AI agent can use tools, its actions can affect people outside the chat window. The surrounding software has to limit what it may do and keep a trustworthy record of what actually happened. That record is part of the agent’s state, and it matters when a tool loses its connection halfway through a job. An agent that can’t tell whether an action succeeded shouldn’t simply try again. Those decisions sit at the heart of AI agent architecture.

When an Agent Is Worth the Extra Complexity

After the Derek email, it’s fair to ask why the assistant needed a Send button at all. Plenty of jobs don’t need an AI agent choosing its own next step. Regular software can send scheduled reports or look up orders by following rules the team already knows. An AI assistant can help draft a customer reply while a person stays responsible for sending it.

An agent becomes more useful when nobody knows the next step until the work begins. While investigating a bug, it might open one file, find a clue that points to another, and follow the trail. Anthropic’s engineering guidance makes a similar distinction between a fixed workflow and a task that needs to adapt.

The agent can suggest what to do next. The surrounding software decides whether it’s allowed, keeps track of what happened and checks whether the outside system completed the action. Important changes should still be reviewable by a person before they happen.

Give the agent a clear goal and limits on its time and tool use. If something stops responding, it should check what happened or ask for help. Otherwise, it might keep repeating the same work while the bill grows.

Tools Need Narrow Permissions

That distinction matters well beyond email. An AI support agent may be allowed to check an order’s delivery status but need separate approval to change its address or issue a refund. The store’s software checks the customer’s identity and the agent’s permissions before carrying out each action.

The agent needs its own account with only the access required for its job. The business should be able to turn that access off. Records should show who asked for a change and which agent carried it out, so a mistake can be traced later. Microsoft’s agent security guidance explains these security checks in more depth.

Model Context Protocol (MCP) is one way an AI application connects to tools provided by other services. It can make integrations easier to build. The business still needs to decide what each connected tool is allowed to read or change.

A tool might return a webpage that says to email customer details to an unfamiliar address. The agent opened that page to read it. Nobody authorized it to follow the page’s orders, so the software must block the message.

Keep a Record That Survives a Failed Connection

If an agent creates a support ticket, the support system is where you check whether it exists. Save what the agent requested and the ticket number once the support system confirms it. If the reply never arrives, look up the result before trying again.

Checkpointing means saving where the agent got to, so it can resume after an interruption. LangGraph documents one approach. Even with a checkpoint, the application still needs to check whether an outside action finished before the connection failed.

An idempotency key labels a request so a service can recognize it if it arrives again. When the service supports this, the label can prevent duplicate tickets after a retry. Amazon’s engineering explanation of safe retries shows where this approach helps. Otherwise, the application needs to check whether the ticket already exists before trying again.

An agent might remember a store’s return policy from last month even though the policy changed yesterday. Before acting, it needs to check the current version. The same goes for approval. Permission to make one change shouldn’t carry over if the proposed change is different.

Approvals Belong at the Point of Action

Telling an AI to ask permission before deleting a record is useful, but the software must enforce that rule. Before deleting anything, it needs to check who requested it, which record is involved and whether that exact action was approved. If the request changes, the approval needs to be checked again.

Even reading records needs permission. A support agent serving several businesses must keep each company’s customer data separate. Typing another company’s account number should never unlock its records. AWS’s guidance on tenant isolation explains this kind of protection.

Reading a public article is usually a simpler task than sending a message or changing an order. For actions that affect people or business records, the software can pause for approval and then check the details again before acting. OWASP’s agent security guidance covers these safeguards.

When a Webpage Tries to Give the Agent Orders

An agent may open a webpage while researching a question. Hidden among the page’s ordinary text could be a demand to ignore the user’s request and email private information somewhere else. The page came from an outside source. It should have no say in what the agent is allowed to do.

This attack is called prompt injection. Simon Willison describes the particularly dangerous combination of untrusted instructions, access to private data and a way to send data out. An agent might need to read outside pages and use tools for legitimate reasons, so the software has to prevent those pages from taking control.

The protection needs to work when the agent uses a tool. A webpage can provide information for an answer, but it can’t approve a payment, change an email recipient or give the agent new permissions. Test this with harmless fake instructions in a separate test environment.

Handoffs Need More Than a Summary

Sometimes one agent investigates a problem and another prepares the fix. The second needs to see which files were checked, what the evidence showed and what remains uncertain. A neat summary can leave out the detail that changes the decision. Our platform architecture overview describes how we think about keeping those records.

OpenAI’s orchestration guidance explains how agents can pass work among themselves. Using one agent is often easier to manage. Add more only when they solve a real problem, and make it clear which one is responsible for each action.

Follow a Code Change Through to the Repository

A code repository is where a project stores its files. A branch lets an agent prepare a fix without changing the main version immediately. Before writing anything, the software checks which repository and branch the user approved.

  1. Identify the requested repository and issue from a trusted source.
  2. Read the relevant code and keep links to the files that support the diagnosis.
  3. Prepare the proposed fix and choose tests that could catch anything it breaks.
  4. Check the target and permissions before writing, then verify the resulting commit or pull request in the destination system.

The real proof of a code change is the commit or pull request in the repository. If creating a branch times out, check whether it already exists before trying again. Instructions found inside a repository comment shouldn’t be allowed to make the agent copy passwords or other secrets.

Test What the Agent Did, Not What It Said

An agent might say it finished a job when the tool failed. The reverse can happen too, with the outside system completing an action but never sending confirmation. Keep a trace, a record of the requests and tool responses, so someone can check what really happened without exposing private information.

Test the awkward cases before they happen to real customers. Have a support system create a ticket and then lose the connection. When the agent resumes, check that it doesn’t create a second ticket. Change a request after approval and make sure the system asks again. Try reading data outside the test account and confirm that access is blocked.

Put harmless fake instructions in a test document the agent might read. It should treat them as untrusted content, even if they ask for more access. Limit how long the test can run and keep it away from real customer systems.

Measure how long the whole job takes, including failed lookups and any repairs a person has to make. A fast reply from the model doesn’t help much when the rest of the process gets stuck. Keep earlier failure examples in the tests so a future update doesn’t bring them back.

What Happens if the Record Changes During Approval?

An agent can sit waiting for approval while someone else updates the record it plans to change. If it uses the old proposal when approval arrives, it could overwrite newer work.

Concurrency control is a version check that helps protect newer work. Before saving a change, the software checks whether someone else has edited the record since the agent read it. If so, the old proposal stops and needs another review. An idempotency key helps prevent the same action happening twice, while this version check prevents an old update from replacing a newer one.

The software carrying out the change has to enforce those checks. An agent’s promise to be careful isn’t enough. CMX’s AI automation services cover how these controls fit into connected business systems.