AI Agents: Core Concepts

TL;DR

AI agents have 6 building blocks: LLM Brain (reasoning engine), Reasoning Loop (observe-think-act cycle), Tools (external capabilities), Memory (short and long-term context), Planning (breaking goals into steps), and Orchestration (managing execution flow). Every agent system — from simple scripts to multi-agent platforms — is a combination of these primitives.

Concept Map

Here's how the 6 building blocks connect to form a working agent:

Concept map showing the 6 building blocks of AI agents and how they interconnect: LLM Brain at center, connected to Reasoning Loop, Tools, Memory, Planning, and Orchestration
Explain Like I'm 12

Think of an AI agent like a student doing a big school project. The LLM Brain is the student's intelligence — they can read, think, and write. The Reasoning Loop is how they work: read the assignment, think about what to do, do something, check if it's right, repeat. Tools are like the calculator, dictionary, and internet — things they use to get stuff done. Memory is their notebook where they write down what they've learned and what they still need to do. Planning is when they break the big project into smaller tasks. And Orchestration is the teacher making sure everyone in the group project is working on the right part.

Cheat Sheet

ConceptWhat It DoesKey Patterns
LLM BrainGenerates reasoning, decisions, and text outputSystem prompts, temperature control, model selection
Reasoning LoopThe observe → think → act cycle that drives agent behaviorReAct, Chain-of-Thought, Reflexion
ToolsExternal capabilities the agent can invokeFunction calling, MCP, JSON Schema definitions
MemoryStores context across steps and sessionsShort-term (conversation), long-term (vector DB), episodic
PlanningBreaks complex goals into executable sub-tasksTask decomposition, plan-and-execute, tree search
OrchestrationControls execution flow, error handling, and agent coordinationSequential, parallel, supervisor, router

The Building Blocks

1. LLM Brain

The LLM is the agent's reasoning engine. It reads the current state, decides what to do next, and generates the output (text, code, or tool calls). The choice of model matters enormously:

  • Larger models (Claude Opus, GPT-4) — better at complex reasoning and planning, but slower and more expensive
  • Smaller models (Claude Haiku, GPT-4o-mini) — faster and cheaper, good for simple tool-calling tasks
  • System prompts shape the agent's personality, constraints, and behavior
# The LLM brain is configured via system prompt + model choice
import anthropic

client = anthropic.Anthropic()
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a helpful coding agent. Break tasks into steps. Use tools when needed.",
    messages=[{"role": "user", "content": "Find and fix the bug in auth.py"}]
)
Tip: The system prompt is your most powerful lever. A well-crafted system prompt can make a smaller model outperform a larger one with a vague prompt.

2. Reasoning Loop

The reasoning loop is the heartbeat of every agent. It's a cycle: observe the current state, think about what to do, act (call a tool or generate output), then observe the result and repeat. Most agents run this loop until they either complete the task or hit a stopping condition.

# Simplified agent loop (pseudocode)
def agent_loop(goal, tools, max_steps=10):
    messages = [{"role": "user", "content": goal}]

    for step in range(max_steps):
        # THINK: Ask the LLM what to do next
        response = llm.generate(messages)

        # CHECK: Did the agent finish?
        if response.stop_reason == "end_turn":
            return response.text  # Task complete

        # ACT: Execute the tool call
        tool_call = response.tool_use
        result = execute_tool(tool_call.name, tool_call.input)

        # OBSERVE: Feed the result back
        messages.append({"role": "assistant", "content": response})
        messages.append({"role": "user", "content": result})

    return "Max steps reached"
Info: The number of loop iterations is a key design decision. Too few and the agent can't complete complex tasks. Too many and you risk runaway costs or infinite loops. Most production agents use both a step limit and a token budget.

3. Tools

Tools are what make agents useful. Without tools, an agent is just a chatbot. Tools let agents interact with the real world:

Tool TypeExamplesUse Case
Code executionPython REPL, Bash shellRun scripts, install packages, test code
File I/ORead, Write, Edit filesModify codebases, create documents
Web accessHTTP requests, web searchFetch data, research, API calls
DatabaseSQL queries, vector searchQuery data, store/retrieve knowledge
CommunicationEmail, Slack, GitHubSend messages, create PRs, comment
# Tools are defined as JSON schemas that tell the LLM what's available
tools = [{
    "name": "read_file",
    "description": "Read the contents of a file at the given path",
    "input_schema": {
        "type": "object",
        "properties": {
            "path": {"type": "string", "description": "Absolute file path"}
        },
        "required": ["path"]
    }
}]
Warning: Every tool you give an agent is a potential security risk. An agent with a Bash tool can run any command. Always implement permission systems, sandboxing, and human-in-the-loop approval for dangerous operations.

4. Memory

Memory lets agents maintain context across steps and sessions. There are three types:

  • Short-term (working) memory — the conversation history within one session. Limited by the LLM's context window.
  • Long-term memory — persisted knowledge stored in files, databases, or vector stores. Survives across sessions.
  • Episodic memory — records of past task executions. Helps agents learn from experience ("last time this approach failed, try something else").
# Short-term memory = conversation messages list
messages = [
    {"role": "user", "content": "Fix the login bug"},
    {"role": "assistant", "content": "I'll read auth.py first..."},
    {"role": "tool", "content": "# contents of auth.py..."},
    # This list IS the agent's working memory
]

# Long-term memory = external storage
# Claude Code uses MEMORY.md files
# Other agents use vector databases (Pinecone, Chroma)
Tip: Context window management is one of the hardest problems in agent design. When conversations get too long, agents "forget" early steps. Strategies include summarization, sliding windows, and RAG (retrieval-augmented generation).

5. Planning

Planning is how agents break complex goals into manageable steps. Without planning, agents stumble through tasks reactively. With planning, they work systematically:

  • Task decomposition — break "build a REST API" into "design schema → create routes → add auth → write tests"
  • Plan-and-execute — create the full plan first, then execute steps one at a time
  • Adaptive planning — adjust the plan as new information emerges
# Plan-and-execute pattern
plan = llm.generate("Break this task into steps: " + goal)
# plan = ["1. Read the existing code", "2. Identify the bug", "3. Write fix", "4. Run tests"]

for step in plan:
    result = agent_loop(step, tools)
    if not result.success:
        # Re-plan based on what went wrong
        plan = llm.generate(f"Step failed: {result.error}. Revise plan: {plan}")

6. Orchestration

Orchestration controls how the agent executes — sequential steps, parallel operations, error handling, and multi-agent coordination. Key patterns:

PatternHow It WorksWhen to Use
SequentialSteps execute one after anotherSimple, ordered workflows
ParallelIndependent steps run simultaneouslyResearch tasks, multi-file edits
RouterClassify input and route to specialized handlerCustomer support triage
SupervisorOne agent manages a team of worker agentsComplex projects with subtasks
Info: Most production agents start with simple sequential orchestration and add complexity only when needed. Premature multi-agent architectures add latency, cost, and debugging difficulty.

Test Yourself

What are the 6 building blocks of an AI agent?

LLM Brain (reasoning engine), Reasoning Loop (observe-think-act cycle), Tools (external capabilities), Memory (short-term and long-term context), Planning (task decomposition), and Orchestration (execution flow control).

What's the difference between short-term and long-term memory in an agent?

Short-term memory is the conversation history within one session — it lives in the LLM's context window and is lost when the session ends. Long-term memory is persisted externally (files, vector databases) and survives across sessions. Example: Claude Code's MEMORY.md files are long-term memory.

Why is planning important for AI agents? What happens without it?

Without planning, agents work reactively — they take the next obvious action without considering the full picture. This leads to wasted steps, backtracking, and failure on complex tasks. Planning lets agents decompose goals into sub-tasks, anticipate dependencies, and work systematically. It's the difference between wandering and navigating with a map.

What security risk do tools introduce, and how do you mitigate it?

Every tool is a potential attack surface. An agent with a Bash tool can run arbitrary commands; a web tool can make unauthorized API calls. Mitigations include: permission systems (allow/deny lists), sandboxing (containers, restricted environments), human-in-the-loop approval for dangerous operations, and least-privilege principle (only give tools the agent actually needs).

When would you choose parallel orchestration over sequential?

Use parallel orchestration when steps are independent and don't depend on each other's results. Examples: researching multiple topics simultaneously, editing multiple files that don't affect each other, running tests on different modules. Use sequential when each step depends on the previous one's output.