Volume 13 · Chapter 3 — AI-Native Software Architecture & Agentic Engineering Handbook
Agentic AI Design Patterns
3.1 Introduction
An AI agent is an LLM given the ability to reason, plan, use tools, and remember - so it can accomplish multi-step goals rather than answer a single prompt. This is the frontier of AI-native systems and the one that most demands careful architecture, because an agent that can take actions can also takewrongactions. The design challenge is to harness agentic capability while bounding it with constrained tools, validation, and human oversight.
3.2 Agents vs Traditional Automation
Traditional automation follows fixed, predefined steps; an agent is goal-oriented and dynamic - it decideshowto reach an objective, choosing tools and adapting to results. This flexibility is powerful for open-ended tasks but non-deterministic and harder to predict and control, which is exactly why agents need stronger guardrails than scripted automation.
3.3 The Reasoning-and-Acting Loop
The core agent pattern is a loop: given a goal, the agent reasons about what to do, calls a tool, observes the result, and repeats until done. This “reason, act, observe” cycle (often called ReAct) is what lets an agent break a problem into steps and use external capabilities - the model plans, your code executes the tools, and results feed back into the model’s next decision.
sequenceDiagram
autonumber
participant U as User (goal)
participant A as Agent (LLM)
participant T as Tools / APIs
participant H as Human (approval)
U->>A: objective
loop Reason -> Act -> Observe
A->>A: plan next step
A->>T: call tool (e.g. lookup balance)
T-->>A: result
end
A->>H: consequential action? request approval
H-->>A: approve / reject
A-->>U: result 3.4 Tool Calling
Tools (function calling) are how an agent affects the world: the model is told what functions are available and their schemas, decides to call one with arguments, and your code executes it and returns the result. This is the critical security boundary - the model proposes, your code disposes. You constrain which tools an agent may call, validate the arguments, and enforce authorization in the tool implementation, never trusting the model’s request blindly.
// The agent can only call tools you expose, and each tool enforces its own authorization.
[Description("Get the balance for an account the CURRENT USER owns.")]
public async Task<decimal> GetBalance(
[Description("account id")] Guid accountId, CancellationToken ct)
{
// Authorization enforced here in code - never trust the model to respect ownership.
if (!await _authz.UserOwnsAsync(_currentUser, accountId, ct))
throw new UnauthorizedAccessException();
return await _accounts.GetBalanceAsync(accountId, ct);
}
3.5 Multi-Agent Systems
Complex problems can be split among specialized agents - a planner, a researcher, a coder, a reviewer - that collaborate, with an orchestrator delegating tasks and aggregating results. Multi-agent designs can tackle broader problems but add coordination complexity, cost, and new failure modes, so they are justified only when a single agent genuinely cannot do the job.
3.6 Memory and Human-in-the-Loop
Agents use short-term memory (the conversation/context) and long-term memory (persisted knowledge, preferences, prior results, often in a vector store) to maintain continuity. Crucially, consequential actions route through human-in-the-loop checkpoints: the agent proposes, a human approves. Risk-based automation - auto-approving low-risk actions, requiring approval for high-risk ones - balances autonomy against safety.
How do you design a production-ready, safe AI agent?
I design the agent to be capable but bounded, treating “it can take actions” as the central risk. First, clear scope: the agent has a well-defined objective and a constrained set of tools it may use - only the functions it genuinely needs - because every tool is a capability and an attack surface. Second, tool safety as the security boundary: the model proposes a tool call, but my code disposes - each tool validates its arguments and enforces authorization in its implementation (the agent asks to read an account, but the tool checks the current user actually owns it), so the model is never trusted to respect permissions. Third, human-in-the-loop for consequential actions: low-risk, easily-reversible actions may run automatically, but anything with real impact - moving money, deleting data, external communications - requires human approval, using risk-based automation to balance autonomy and safety. Fourth, guardrails against the model’s failure modes: I treat inputs and any retrieved content as untrusted to resist prompt injection (which is especially dangerous for agents because it can hijack tool use), validate the agent’s outputs and actions, and bound the loop (step limits, timeouts, cost caps) so a confused agent cannot run away. Fifth, memory managed deliberately - short-term context and long-term store - without leaking data across users or sessions. Sixth, full observability and audit: every reasoning step, tool call, and action is logged so I can trace, debug, and prove what the agent did, which is essential for trust and compliance. And I evaluate the agent’s behavior continuously rather than assuming reliability. The unifying principle is that an agent’s power to act must be matched by constraints on what it can do, validation of what it proposes, human oversight for high-stakes steps, and complete auditability - safety is engineered around the agent, because the agent itself is non- deterministic and manipulable.
Why is tool calling the critical security boundary in an agent, and how do you secure it?
Tool calling is the critical boundary because it is where the agent stops merely generating text and starts affecting the real world - querying databases, calling APIs, moving money, sending messages. As long as an agent only produces text, its mistakes and manipulations are contained; the moment it can invoke tools, a hallucination, a bad plan, or a prompt-injection attack can translate into a real, possibly irreversible action. So the tools are where a compromised or confused agent does damage, which makes them the place to concentrate security. The core principle is that the model proposes and your code disposes: the LLM decides it wants to call a function with certain arguments, but that request is untrusted input to your code, not a command to obey. I secure it several ways. I expose only the minimal set of tools the agent needs, so its capabilities are least-privilege. Each tool validates its arguments rigorously (types, ranges, allow-lists) because the model may produce malformed or malicious inputs. Critically, each tool enforces authorization in its own implementation against the actual user’s identity and permissions - the agent asking to read account X does not mean it may; the tool checks the current user owns account X - so authorization lives in code, never in a prompt instruction the model could ignore or be tricked past. Consequential tools require human approval. I treat prompt injection as a live threat, since injected instructions (from user input or retrieved documents) commonly aim to make the agent misuse tools, so I never let model output directly authorize a sensitive action, and I log every tool call for audit. In short, I assume the agent can be wrong or manipulated and place the real controls - least-privilege tools, argument validation, code-enforced authorization, approvals, and logging - at the tool boundary, because that is the line between harmless text and real-world effect.
When is a multi-agent design justified over a single agent, and what are its costs?
A multi-agent design is justified when a problem genuinely benefits from decomposition into specialized roles that a single agent cannot handle well - for example a workflow that needs distinct expertise or distinct system prompts and tools at each stage (a planner, a researcher with search tools, a coder, and a separate reviewer that critiques the coder’s output), or where parallel exploration by differently- configured agents improves results, or where separation of duties itself is valuable (one agent proposes, an independent one validates). Splitting responsibilities can make each agent simpler and more focused, improve quality through specialization and cross-checking, and mirror how a human team divides work. But the costs are real and often underestimated, so I do not reach for it by default. Coordination is hard: you need an orchestrator to delegate tasks, pass context between agents, and aggregate results, and that introduces new failure modes - agents miscommunicating, looping, or disagreeing. Cost and latency multiply because each agent is its own set of LLM calls, so a multi-agent system can be several times more expensive and slower than a single well-designed agent. Debugging and observability get harder because behavior emerges from multiple interacting non-deterministic components. And the surface for errors and prompt injection grows with each agent and tool. So my rule is to start with a single, well-scoped agent with good tools and only move to multi-agent when a single agent demonstrably cannot do the job - when the task truly requires distinct specialized roles, independent review, or parallelism that one agent cannot provide - and even then I keep the number of agents minimal, define their interfaces and orchestration tightly, and invest in observability across the whole system. The judgment being tested is resisting architectural over-complexity: multi-agent is powerful but expensive and fragile, so it must earn its place against a simpler single-agent baseline.
3.7 Banking Enterprise Scenario
A bank’s customer-service agent runs a reason-act-observe loop with a minimal set of tools - look up a balance, fetch a transaction, raise a support ticket - each enforcing authorization in code against the authenticated customer, so the agent can never reach another customer’s data even if manipulated. Read-only actions run automatically; anything consequential (initiating a payment, changing account settings) requires human approval via a checkpoint. Short-term context handles the conversation while a vector store holds relevant policy knowledge, inputs and retrieved content are treated as untrusted to resist prompt injection, the loop is bounded by step and cost limits, and every reasoning step and tool call is logged for audit. The agent is capable but tightly bounded.
Chapter Revision Notes
- An agent reasons, plans, uses tools, and remembers to pursue multi-step goals.
- Agents are dynamic and non-deterministic - they need stronger guardrails than scripted automation.
- The reason-act-observe loop plans, calls tools, and feeds results back.
- Tool calling is the security boundary: model proposes, code disposes - validate and authorize in the tool.
- Route consequential actions through human-in-the-loop; use risk-based automation.
- Reserve multi-agent designs for problems a single well-scoped agent cannot handle.