Guides

Inside an AI agent: the parts and how they connect

By Abdul Asim ·

The short answer

An AI agent architecture has six parts: a language model that makes decisions, tools that let it act, memory and state that carry context, a planning approach for multi-step work, guardrails that limit what it may do, and observability that records what it did. A control loop in your own code ties them together. The model is the smallest part of the codebase: most of a production agent is ordinary software deciding what the model may see and do.

The control loop at the centre

Every agent runs a loop that your code owns, not the model. The runtime sends the goal and context to the model, gets back either an answer or a tool request, runs the tool, appends the result and calls the model again. OpenAI's function calling and Anthropic's tool use APIs both work this way: the model returns a structured call and your application executes it.

Because the loop is yours, it is where hard limits belong: a maximum step count, a token budget, a timeout, and a defined outcome when any of them trips. This is also the main difference from a pipeline in AI, where stages run in a fixed order. An agent picks its order at run time, so the runtime around it has to be stricter, not looser.

The model layer

The model reads the goal, the tool descriptions and the history, then produces the next action. Agent work punishes weak models harder than single-turn chat, because a small slip in step two shapes every step after it. I choose models per role: a capable model for planning and tool choice, a cheaper one for narrow steps such as classification or formatting.

Ask for structured output wherever code consumes it. Both vendor docs linked above offer a strict mode that holds tool arguments to the declared JSON schema, which removes a whole class of parsing failures. Strict mode guarantees shape, not truth, so still check the values against your own data.

Tools: how the agent acts

A tool is a function with a name, a description and an input schema. The description matters as much as the code, because it is all the model knows about when to use the tool. Fewer, sharper tools beat a long menu: every extra tool is one more wrong choice available.

The Model Context Protocol standardises how applications expose tools and data to models over JSON-RPC, so one tool server can serve several agents. The specification says plainly that tools represent arbitrary code execution and that hosts must get explicit user consent before invoking one. MCP gives you a standard connector, not a permission model. Authorization still has to be enforced in the systems the tools reach.

On the ODVA security testing system, the tool decision that mattered most was scope. Testing could only run against targets the authorization data permitted, so a planning mistake could not become a test against something out of bounds.

Memory and state

Agents need three kinds of memory, and mixing them up causes most context problems:

  • Working context: the current request, tool results and plan, held in the prompt for this run. It is bounded by the context window and by cost, so summarise or drop stale tool output.
  • Long-term knowledge: documents and records the agent can search. This is a retrieval problem, and the same components of a RAG pipeline apply.
  • Task state: where a job stands, what was approved and what was produced. Keep it in a database, not in the prompt, so a crash or a pause for human review does not lose it.

On ODVA, test results and evidence go to a dedicated evidence store instead of living in the model's context. Reports are built from that stored evidence, which is what keeps the findings auditable after the run ends.

Planning patterns

How the agent structures multi-step work changes cost and reliability more than model choice usually does. Three patterns cover most systems:

PatternHow it worksStrengthRisk
Reason and actDecide one step at a time, reading each resultAdapts to surprisesCan wander or loop
Plan then executeWrite the full list of subtasks first, then run itThe plan can be checked before anything runsBrittle when early results change the picture
Reflect and retryCritique a failed attempt and keep the lesson for the next tryRecovers from its own mistakesMore calls, more cost

The primary sources are the ReAct paper for interleaving reasoning with actions, Plan-and-Solve prompting for planning subtasks up front, and Reflexion for agents that store written reflections in memory instead of updating weights.

I lean towards plan then execute whenever actions carry risk, because a written plan is something a person or a rule can inspect before execution. On ODVA that is exactly where human review sits: risky proposed tests are reviewed before they run, not after.

Guardrails and human review

Guardrails decide what the agent may do regardless of what the model wants to do. OWASP lists Excessive Agency among its top risks for LLM applications and traces it to three causes: too many functions, too many permissions and too much autonomy. Each one maps to a control in the architecture:

  • Untrusted inputs: treat retrieved text and tool output as data, never as instructions, because prompt injection arrives through exactly those channels.
  • Least privilege: give tools read-only credentials unless they must write, and enforce permissions in the downstream system rather than trusting the model.
  • Output validation: check every structured result against a schema before anything acts on it. ODVA validates findings with Pydantic.
  • Human approval: route irreversible or high-risk actions to a person, with enough context to decide quickly.

Observability and evaluation

An agent you cannot replay is an agent you cannot debug. Log every model call, tool call, argument, result, token count and latency as one trace per run. When a user reports a bad answer, the trace tells you whether retrieval, tool choice or the final generation went wrong.

Then turn traces into tests. Collect real runs with known correct outcomes and score every prompt, model or tool change against them before it ships. The LLM evaluation guide covers how to build that set so it catches regressions rather than only reporting averages.

Types of agent architecture in AI

Classic AI split agent architectures into reactive designs that respond directly to input, deliberative designs that reason over an internal model before acting, and hybrids that layer the two. Agent systems built on language models follow the same idea at a larger scale:

  • Single agent with tools: one loop and a short tool list. Right for most first versions.
  • Router: a model classifies the request and hands it to a fixed workflow. Close to a pipeline and very predictable.
  • Orchestrator and workers: one agent plans and delegates subtasks to specialised agents. Read multi-agent systems before choosing this.
  • Fast and slow loops: a tightly controlled loop acts while a separate loop reviews and improves. Paladin, my agentic trading platform, uses this split, and every live order passes a mandatory review step before it is placed.

Start with a single agent and add structure only when traces show you need it. For how these designs map to the kinds of agent they produce, see types of AI agents, and for the base definition, what is an AI agent. If you want this architecture built for one of your processes, with these controls in place from the first release, that is the scope of my custom AI agentic system engagement.

Let's talk

Let's ship yours.

AI product, automation bottleneck, RAG use case, or operational workflow. Tell me what's slowing your team down, or what revenue you're leaving on the table.

Abdul Asim, AI / LLM Engineer