6.2.1 · D1AI Agents & Tool Use

Foundations — Agent architectures and reasoning loops

3,369 words15 min readBack to topic

This page assumes you have seen none of the notation. We build each symbol in order, anchor it to a picture, and say why the topic cannot live without it. Start reading at line one.

Parent: Agent architectures and reasoning loops.


0. The mental picture we keep returning to

Everything below is a label on one of the boxes in this diagram. Keep it in your eye.

Figure — Agent architectures and reasoning loops

What figure s01 shows: four labelled boxes arranged in a ring — Observe (magenta, holding the state ), Reason (violet, choosing an action ), Act (orange, running the action), and Update (navy, producing the next state ). Curved arrows run box-to-box in a clockwise cycle, and in the middle the note " (stamp next turn)" reminds you the crank counter ticks up on every full loop.

The agent is a crank you turn again and again. One full turn = observe, then reason, then act, then update. The parent note calls one turn a cycle or a step. We now name each part of the machine.


1. The subscript — "which turn are we on?"

The picture: in figure s01, imagine a tiny number stamped on the crank each time you pull it: turn 1, turn 2, turn 3. That stamp is .

Why the topic needs it: the loop repeats, so the same quantity (the state, the context) exists in many versions — one per turn. Without a counter we could not say "the state before this turn" versus "the state after". The whole idea of a loop is "the new thing depends on the old thing", and vs is how we write "old" and "new".


2. State — the symbol

The picture: in figure s02 the state is the whole scroll of paper the agent is holding — every note written on it so far.

Why the topic needs it: a decision has to be about something. The state is that something. When the parent writes

it is saying: "the starting picture , after observing, becomes an updated picture ." The arrow with a word on top means "turns into, by doing that word".


3. Action — the symbol

The picture: the single card the agent plays face-up from its hand (figure s02, right side). Exactly one per turn.

Why the topic needs it: thinking alone changes nothing in the world. The action is the only part that reaches outside the agent. The parent's phrase "tool call or response" is the two flavours of : either poke the outside world, or stop and answer.


4. Observation — the symbol

The picture: the reply slip that slides back through the slot after you post an action (figure s01, "Act → Observe" arrow).

Why the topic needs it: this is how the loop learns anything new. Without , every turn would think about the same stale state forever. The observation is the fresh fact that makes the next state different from this one.


5. Thought — the symbol

The picture: in figure s02, before the agent plays the action card it scribbles a sticky note ("what should I do next?") and clips it onto the scroll. That sticky note is .

Why the topic needs it: the ReAct pattern (see Chain-of-Thought Prompting) forces the model to speak its reasoning aloud before acting. So one turn actually produces three text pieces in order: a thought, then the action it implies, then the observation that comes back. Written with the turn counter these are — the same and from Sections 3–4, now paired with the reasoning that chose them. Keep this trio in mind; Section 8 glues a whole history of them together.


6. A function — the symbol

The picture: a vending machine — coin in, snack out (figure s03).

Why the topic needs it, and why this tool: the parent writes things like We use function notation instead of prose because it answers one precise question: "the output depends on exactly these inputs, and nothing hidden." A simple reflex agent's takes only the current percept — that single-input picture is why it has no memory. A goal-based agent's takes more inputs. The notation makes the difference visible at a glance.


7. Two arrow symbols — telling from by their heads

The picture: figure s01 shows the long labelled transition arrows going round the loop ("observe", "reason", "act", "update"). Figure s04 shows a short bare flow arrow: a pipe pouring a fact into the memory bucket.

Why the topic needs both: the loop transitions between states; memory stores facts. Two jobs, so we keep two visibly different arrows — the transition arrow is longer and always dressed with a word, the flow arrow is short and naked.


8. The summation sign — "glue all the turns together"

The picture: figure s04 — a stack of index cards, one per past turn, clipped into one thick bundle.

Why the topic needs it, and why this tool: the ReAct prompt is Read left to right: start with the fixed brief , then glue on every past turn's trio (the from Sections 3–5), and finally add the bare word "Thought:" as a cue that tells the model "your turn — reason next." Here "+" is not arithmetic — it's concatenation, gluing text end to end. We use because there are a variable number of past turns (it grows every loop), and is the compact way to say "all of them, however many there are". Writing them out one by one is impossible when the count keeps changing.


9. — "which choice wins?"

The picture: figure s03 — several actions on a shelf, each with a score tag; is the hand pointing at the highest-scoring one.

Why the topic needs it, and why this tool: a goal-based agent must pick an action. We write In words: "look at every possible action , score each with , and keep the action with the top score." We choose (and not plain ) because we want the action itself, not its score. would hand us the number; hands us the move to make. An agent needs the move.

All cases covered:

  • If two actions tie for the highest score, picks one (implementations break ties by order or randomly) — the agent still acts, never freezes.
  • If every action scores zero (goal unreachable this turn), still returns some ; a well-built agent then checks its terminate condition instead of looping forever.

10. The reward — the RL cousin of the score

The picture: imagine, in figure s01, that the reply slip coming back on the "observe" arrow carries two things: the observation (the facts) and a score stamp (a thumbs-up or thumbs-down on the last action).

Why we mention it here: the parent says the vocabulary "comes straight from" reinforcement learning — and RL's native loop is actually (state, action, reward, next state). Agent architectures borrow the state/action/observation skeleton but usually run without a numeric : an LM agent judges success from the observation text, not from an environment-supplied reward. Knowing exists tells you what agent loops leave out — and why RL-trained agents (that do use ) can learn better action choices over time, while a plain ReAct agent cannot.


11. top- and similarity — the memory-recall symbols

The picture: figure s04, lower half — a query magnet pulls the nearest cards out of a filing drawer.

Why the topic needs it: long-term memory can hold thousands of facts, but the context window (next symbol) is small. So we retrieve only the most relevant. Choosing (say 5) is choosing how much to remember at once — a tuning knob, not a fixed law. See Retrieval-Augmented Generation.


12. The set braces — "a bag of named things"

Why the topic needs it: the parent writes This just says "memory comes in these three named kinds" — nothing is being added or multiplied; the braces are a labelled bag.


13. The context window — a length limit, not a symbol

The picture: the scroll from figure s02 has a maximum length; past that, old writing falls off the top.

Why the topic needs it: it's why short-term memory can't just grow forever, and why long-term memory + top- retrieval exist at all. See LM Context Windows for the full story, and Retrieval-Augmented Generation for how retrieval sidesteps the limit.


How these feed the topic

Each short node label is spelled out in the legend directly below the diagram — read them together.

time index t

state s

action a

observation o

thought

reasoning engine

function f

argmax picks action

goal score function

reward r from RL

sum glues past turns

ReAct prompt context

instruction I

set braces name memory kinds

memory system

similarity and top k

context window limit

reasoning loop

Read it top-down: the counter lets state, action, observation take turns; the function and argmax (fed by the goal score) live inside the reasoning engine that chooses the action; the sum, the instruction , and the thoughts build the ReAct prompt; set braces, similarity, top-k, and the window organise memory, which flows back into the state; reward is the RL-only extra that a plain agent leaves out. Together they form the loop.


The strategies for choosing each get their own note: Chain-of-Thought Prompting, Tool Use and Function Calling, Prompt Engineering, Reinforcement Learning Basics (the vocabulary comes straight from here), and Multi-Agent Systems.


Equipment checklist

Cover the right side and answer aloud. If any fails, re-read that section.

What does the lowered in mean?
Which turn of the loop we are on — an index, never multiplication.
What is the state in plain words?
Everything the agent currently knows: conversation so far plus memory.
What is an action ?
The single thing the agent does this turn — a tool call or a final response.
What is an observation , and why is it essential?
What comes back after the action; it's the only fresh fact that makes the next state differ from this one.
What is and how does it relate to and ?
The agent's private reasoning note on turn ; it produces the action, so each turn yields the trio (Thought, Action, Observation).
What does mean and why use it?
A machine turning input into output; it names exactly which inputs the output depends on (e.g. reflex agent depends only on the current percept).
How do you tell a transition arrow from a flow arrow?
Transition = long arrow with a word on top ("becomes"); flow = short bare arrow ("is sent into").
What is the instruction in the ReAct prompt?
The fixed top-of-prompt brief — task description and rules — set once and unchanged every turn.
What does do in the ReAct prompt, and is "+" arithmetic there?
Glues together all past (Thought, Action, Observation) turns; "+" is string concatenation, not addition.
What does return?
A number rating how much action advances the goal; higher = closer.
Why instead of ?
We want the winning action itself, not its score.
How does the reward differ from ?
is external feedback from the environment after acting; is a score the agent computes itself to plan. RL loops use ; plain agents usually omit it.
What do similarity and top- do together?
Score each stored fact's closeness to the query, then keep only the most relevant.
What do the braces in mean?
A named bag listing the three kinds of memory — nothing is added.
Why does a context window force long-term memory to exist?
The window caps how much state fits at once, so older or bulk knowledge must be stored outside and retrieved.