02. AI Agent Fundamentals
Agent Architecture
Agent architecture is the blueprint that connects environment, perception, reasoning, memory, tools, actions, and guardrails — so an agent can pursue goals reliably.
What you will learn
- Draw a standard agent architecture and name each box
- Explain layered architecture from UI to platform
- Describe data flow for one observe–think–act cycle
- Choose among single-loop, router, and multi-agent patterns
- Answer architecture interview questions with short, solid answers
Definition
Agent architecture is the structural design of an AI agent: which components exist, how they communicate, where state lives, how tools execute, and which policies constrain actions.
A good architecture makes the observe–think–act loop implementable, testable, and securable. A poor architecture buries control flow inside opaque prompts and untyped side effects.
Frameworks (LangGraph, CrewAI, AutoGen, SDKs) are ways to express an architecture — they are not substitutes for one.
Introduction
This lesson opens Module 02 (AI Agent Fundamentals). Module 01 explained what agents are and how they work. Architecture answers: what pieces do we build and how do they fit?
You will leave with a drawable reference model, a layered stack, pattern choices, and a checklist for design reviews.
Why architecture matters
- Separates concerns so you can swap models without rewriting tools
- Makes safety enforceable at clear boundaries (tool runtime, auth)
- Enables logging and evals on each stage of the loop
- Prevents “big prompt” systems that cannot be debugged
- Supports scaling from one agent to routers or multi-agent later
Core components
Every serious agent architecture includes these building blocks, even if some are thin at v1.
- Goal / task contract — inputs, success criteria, constraints
- Perception / context builder — assembles prompts, docs, observations
- Reasoning engine — LLM or policy that proposes next steps
- Orchestrator — control loop, retries, routing, stop rules
- Memory / state store — short-term transcript; optional long-term memory
- Tool registry + runtime — schemas, execution, timeouts, results
- Guardrails — authz, budgets, validation, human approval hooks
- Observability — traces, metrics, audit logs
Layered architecture
Think in layers so ownership is clear. UI teams should not own tool credentials; model prompts should not bypass auth.
- Interface — chat UI, HTTP API, IDE plugin, webhook trigger
- Orchestration — loop, graph, retries, stop conditions
- Reasoning — model calls, planners, system prompts
- Tools/connectors — typed adapters to external systems
- Data/platform — memory DB, logs, secrets, hosting, identity
Data flow (one cycle)
Architecture becomes real when you can narrate one cycle of data movement.
- Request enters via interface with a goal payload
- Orchestrator loads state/memory and builds observation context
- Reasoning component returns a decision: reply, ask, or tool call
- If tool call: runtime validates, executes, returns observation
- Orchestrator appends results to state and checks stop rules
- Response and/or next iteration continues until done/escalate
Architecture patterns
Pick the simplest pattern that fits. Complexity should be earned by divergent roles or intents.
- Single loop — one agent, one toolset, one state object (start here)
- Router — classifier/LLM selects a specialist path or tool pack
- Multi-agent — supervisor/workers or a graph of roles with protocols
- Human-in-the-loop variant — approval node before high-impact acts
Key contracts (APIs between boxes)
Strong architectures are contract-first. Define schemas before wiring frameworks.
- Goal schema — fields, allowed tools, budgets, risk level
- Observation schema — tool name, args, result, error, latency
- Decision schema — type (reply|ask|tool|stop), payload
- Tool interface — name, JSON schema, side-effect class (read/write)
- State schema — messages, scratchpad, step count, flags
Classical vs modern LLM agent architecture
Classical agents used explicit sensors/actuators and hand-coded policies. Modern LLM agents keep the same outer shape but place a generative model in the decision seat and expose software tools as actuators.
- Same idea — closed loop with environment
- New brain — LLM proposes flexible plans and arguments
- New risk — untrusted proposals must be validated by runtime
- New ops need — tracing token use and tool side effects
Design quality checklist
- Can you draw the boxes without naming a vendor?
- Is tool execution outside the model process?
- Are stop rules in the orchestrator, not only in prose prompts?
- Can you replay a run from logs?
- Can you swap the LLM without rewriting every tool?
- Are write tools classified and approval-gated?
Program / implementation notes
Implement a thin vertical slice first: interface → orchestrator → one model → two tools → logs. Expand memory and multi-agent routing only after the slice is reliable.
- Keep orchestrator deterministic; keep model probabilistic inside it
- Put secrets in the platform layer, never in prompts
- Version prompts and tool schemas like code
- Add eval harness that asserts end-state, not only text style
- Document pattern chosen (A/B/C) and why alternatives were rejected
Advantages and limitations of explicit architecture
- Advantage: debuggable, securable, evolvable systems
- Advantage: clearer team ownership by layer
- Advantage: easier interviews and design reviews
- Limitation: more upfront design than a single chat completion
- Limitation: over-architecture for tiny demos — keep v1 thin
Key points
- Agent architecture connects environment, perception, brain, memory, tools, actions, and guardrails.
- Use layers: interface → orchestration → reasoning → tools → platform.
- Narrate one cycle of data flow to prove the design.
- Prefer single-loop; add router/multi-agent only when needed.
- Contracts/schemas between components enable tests and safety.
- Frameworks implement architecture — they do not replace it.
FAQs
Is LangGraph an architecture?
LangGraph is a framework for expressing graph/loop orchestration. Your architecture is still the component design and contracts you choose to implement with it.
Where should guardrails live?
Primarily in the orchestrator and tool runtime (validation, authz, budgets). Prompts can guide behavior but must not be the only control.
Do I need vector memory in the architecture from day one?
No. Start with short-term state/transcript. Add long-term/vector memory when cross-session knowledge is a real requirement.
Single agent or multi-agent architecture?
Default single agent. Move to multi-agent when roles, permissions, or specialization clearly diverge and justify coordination cost.
Interview questions
- What is AI agent architecture?
Answer It is the blueprint connecting perception, reasoning, memory, tools, orchestration, and guardrails so an agent can pursue goals in an environment safely.
- What are the main components of an agent?
Answer Goal contract, context builder, reasoning model, orchestrator loop, memory/state, tool runtime, guardrails, and observability.
- Explain layered agent architecture.
Answer Interface on top, then orchestration, reasoning, tools/connectors, and a platform layer for memory, logs, auth, and hosting.
- How does data flow in one agent step?
Answer Load state and observations, model proposes a decision, tool runtime may execute an action, results append to state, stop rules decide loop or finish.
- Single-loop vs multi-agent — when to use each?
Answer Use a single loop for one goal and toolset. Use multi-agent when specialized roles need separate prompts, tools, or permissions.
- Where should tool execution happen?
Answer In a dedicated runtime outside the model, with schema validation, timeouts, and least-privilege credentials.
- How do you keep architecture framework-agnostic?
Answer Define component contracts first, then map them onto LangGraph/CrewAI/SDK primitives — so you can redraw the boxes without vendor names.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Draw Environment → Agent (Perceive, Brain, Memory) → Actions and label guardrails.
- List the five layers and one responsibility under each.
- Write schemas in bullets for Decision and Tool Observation.
- Choose pattern A, B, or C for a support bot that also can refund — justify in three lines.
- Answer interview questions 1, 3, and 6 in two sentences each.