Introduction to Agents & the Training Ladder

Agentic AI · L-Intro

What an agent is, how a language model produces text (probabilistically), the training ladder, and a modular agent architecture we will build on for the whole term.

Prerequisite: the recap Probability.

Learning Objectives

After this lecture you can:

  1. Apply the chain rule of probability and Markov chains to token sequences.
  2. State the language-modelling objective (chain rule) and why it is autoregressive.
  3. Distinguish a chatbot from an agent.
  4. Explain the training ladder: base → aligned → tool-calling.
  5. Identify the core components of an agent: model, agent loop, tool calls, planning capabilities, and memory.
  6. Describe the agent's core and its boundary components, and name the trust boundary.

Overview

An agent is a language model placed in a loop by a runtime. Each of the four parts answers one question:

Part The question it answers Sections
I · Language Models What is a language model, stated as a probability distribution over token sequences? Tokens & the Vocabulary · The Chain Rule of Probability · Markov Chains & the Markov Assumption · From Probability to Neural Language Models
II · The Training Ladder Which training stages turn a next-token predictor into a model an agent can use? Working definition of an AI Agent · Value Alignment Problem · The Training Ladder · Alignment: Base Model → Chatbot · The Pipeline Stages Behind the Rungs
III · The Agent Loop What does the runtime add around the model so that the model's output becomes action? Chatbot → Agent · Loops · Planning: Reactive vs. Deliberate · Structured Tool Calls (JSON)) · Memory · Proactivity · Core Capabilities of an Agent · Chatbot vs Agent — The Full Picture
IV · Agent Architecture How do agents built on the same loop differ — in what the system around the model does, what fills the context, and where the boundaries lie? Agent Capability Levels · Context Engineering — A First Look · Limits & Responsible Use ⚖️ · Agent Control and Its Boundaries · Practice Framing: Model + Harness, Workflows vs. Agents

Part I — Language Models

A language model is a probability distribution over token sequences. The probability that this part uses — sample space, random variables, joint, marginal and conditional distributions, conditional independence — is a prerequisite of the lecture, recapped in Probability.

Tokens & the Vocabulary

Token: the atomic unit of text a language model reads and produces (Jurafsky & Martin, 2026, ch. 2)

  • roughly a word or a word-piece (subword).
  • E.g. "tokenization" might split into "token" + "ization".
  • Note: Tokens are not always whole words.

Vocabulary $V$: the fixed, finite set of all tokens the model knows (typically ~50k–200k).

Every prompt and every reply is a sequence of tokens from $V$.

How text is split into tokens (tokenization) is covered in → L-Att.

Token-Notation

$W_t$ (capital) is the token at position $t$ as a random variable over $V$; a concrete (generic) token is lowercase $w_t$. Write $W_{1:T} := (W_1, W_2, \dots, W_T)$ for the random variable of sequence of $T$ tokens.

A concrete text is a token sequence

$$w_{1:T} = w_1 w_2 w_3 \dots w_T$$ (each $w_t \in V$).

The Chain Rule of Probability

Notation: $W_{1:t-1}$ is the prefix (token sequence) before position $t$.

Any joint factorises into conditionals: $$ P(W_{1:T}) = P(W_1)\,P(W_2\mid W_1)\cdots P(W_T\mid W_{1:T-1}) = \prod_{t=1}^{T} P(W_t\mid W_{1:t-1})$$

The identity behind language modelling:

  • model only the next-token conditional,
  • multiply to score any sequence.

Markov Chains & the Markov Assumption

A sequence is a (first-order) Markov chain if the next state (here token) depends only on the current: $$ P(W_t\mid W_{1:t-1}) = P(W_t\mid W_{t-1}), $$ captured by a transition matrix $P_{ij}=P(W_t{=}j\mid W_{t-1}{=}i)$, where the indices $i,j$ label the vocabulary tokens ($W_t{=}j$ means "$W_t$ is the $j$-th token"; a generic token value is $w_t$).

As conditional independence. The Markov assumption says that given the present $W_{t-1}$, the next token $W_t$ is independent of the older past $W_{1:t-2}$ — i.e. $W_t \perp W_{1:t-2}\mid W_{t-1}$ (cf. Conditional Independence above). In the bigram model the total probability is: $$P(W_{1:T}) = P(W_1) \prod_{t=2}^T P(W_t \mid W_{t-1})$$

  • $n$-gram LMs (Jurafsky & Martin, 2026, §3.1) assume a fixed window of the last $n-1$ tokens: $P(W_t\mid W_{1:t-1}) \approx P(W_t\mid W_{t-n+1:\,t-1})$ — cheap but forgetful (a bigram, $n{=}2$, is the first-order case above).
  • Modern LLMs drop the assumption: they condition on the full history $W_{1:t-1}$, up to the length of the context window.
In [1]:
# A first-order Markov (bigram) language model, estimated by counting.
from collections import Counter, defaultdict
import numpy as np

text = "the cat sat on the mat . the cat ate the fish . the dog sat on the log .".split()

# Count bigram transitions: P(next_token | prev_token)
counts = defaultdict(Counter)
for prev_token, next_token in zip(text[:-1], text[1:]):
    counts[prev_token][next_token] += 1


def get_conditional_dist(prev_token: str) -> dict[str, float]:
    token_counts = counts[prev_token]
    total_count = sum(token_counts.values())
    return {word: count / total_count for word, count in token_counts.items()}


print("P(next | 'the') =", get_conditional_dist("the"))
print("P(next | 'cat') =", get_conditional_dist("cat"))

# Sample a sequence using the Markov conditionals
rng = np.random.default_rng(seed=0)
current_token = "the"
generated_sequence = ["the"]

for _ in range(8):
    dist = get_conditional_dist(current_token)
    if not dist:
        break
    words, probabilities = list(dist.keys()), list(dist.values())
    current_token = rng.choice(words, p=probabilities)
    generated_sequence.append(current_token)

print("Sampled text:", " ".join(generated_sequence))
P(next | 'the') = {'cat': 0.3333333333333333, 'mat': 0.16666666666666666, 'fish': 0.16666666666666666, 'dog': 0.16666666666666666, 'log': 0.16666666666666666}
P(next | 'cat') = {'sat': 0.5, 'ate': 0.5}
Sampled text: the fish . the cat ate the fish .

The sampled text loses coherence after a few tokens, because the bigram model conditions each token on its predecessor alone.

From Probability to Neural Language Models

So far the model is just an abstract distribution $P(W_t \mid W_{1:t-1})$. In modern LLMs this conditional is computed by a neural network — a Transformer — trained on huge text corpora. Its internals (tokenization, attention, positional encoding, the context window, and the KV-cache) are the subject of Inside the Model.

For now we only need the interface: prompt in → a probability distribution over the next token out.

Generation repeats this step: each sampled token is appended to the input, and the model is called again. The vocabulary contains an end token. The program that calls the model stops the repetition when the end token is sampled, or when a set limit on the number of generated tokens is reached.

Part II — The Training Ladder

An agent needs a model that follows instructions and requests tools, and a base model does neither: two training stages beyond next-token prediction install these capabilities.

Working definition of an AI Agent

An AI agent is an aligned LLM (large language model) placed in a loop where it can use tools to act and observe the results, keeps memory across steps, and works toward a goal — often proactively — instead of only replying once.

Compactly: Agent = aligned LLM + tools + memory (+ planning & proactivity), run in a loop.

Intelligence as Rationality (Russell & Norvig, 2021)

The standard AI-Book of Russell & Norvig (2021) defines intelligence as rationality—doing the right thing. What counts as the right thing is defined by the objective that we provide to the agent, e.g. to maximize an expected performance measure given percepts and prior knowledge.

Rational agent (Russell & Norvig, 2021, §1.1.4). A rational agent is one that acts so as to achieve the best outcome or, when there is uncertainty, the best expected outcome — i.e. it selects the action expected to maximise its performance measure, given its percepts and prior knowledge (R&N, §2.2).

Value Alignment Problem

"The problem of achieving agreement between our true preferences and the objective we put into the machine is called the value alignment problem: the values or objectives put into the machine must be aligned with those of the human." (Russell & Norvig, 2021, §1.1.5, p. 23)

The Training Ladder: Base → Aligned Chat Model → Aligned Tool-Calling Model

Training on large corpora results in a base model (aka foundation model):

  • it predicts the next token.
  • a document completer, not a helper.

Two further training stages turn the base model into a model which can be used for an agent:

  • Aligned chat model (for a chatbot): fine-tuned to follow instructions.
  • Aligned tool-calling model (for an agent): fine-tuned to request tools.

Note. The chain rule $P(W_{1:T})=\prod_t P(W_t\mid W_{1:t-1})$ is just the autoregressive factorization — it holds for every rung (base, aligned, tool-calling). Alignment doesn't change the maths; it reshapes the learned conditional $P(W_t\mid W_{1:t-1})$ itself, shifting probability mass toward helpful, instruction-following continuations.

Alignment: Base Model → Chatbot

A base model is trained to predict the next token, not to follow the user's instruction (Ouyang et al., 2022, §1; the base model itself: Brown et al., 2020). The two objectives give different outputs:

Example. Ask a base model "What is the distance from Earth to the Moon?" and a very typical continuation is more questions — "What is the distance from Earth to the Sun? To Venus? …" — because on the web a question is often followed by more questions. Answering is just one possible completion, not a preferred one.

Supervised Fine-Tuning and Preference Optimization

Alignment is the fine-tuning of a base model so that it follows instructions and behaves as a helpful chatbot (Jurafsky & Martin, 2026, ch. 8):

  • SFT (supervised fine-tuning): train on many (instruction, good answer) pairs → the model learns to follow instructions.
  • Preference optimization (RLHF / RLAIF / DPO): score candidate answers by preference — human comparisons in RLHF (Bai et al., 2022b, with separate comparison data for helpfulness and harmlessness), or a model's comparisons for part of the objective in RLAIF (Bai et al., 2022a, who keep human labels for helpfulness and generate only the harmlessness ones) — and tune toward the preferred ones → helpful, honest, harmless (the HHH criteria; Askell et al., 2021 — adopted by InstructGPT, Ouyang et al., 2022). (RLHF = Reinforcement Learning from Human Feedback; RLAIF = Reinforcement Learning from AI Feedback; DPO = Direct Preference Optimization.)
  • + chat template (system / user / assistant roles).

Result: an aligned chat model = a chatbot — reactive and talk-only.

The Pipeline Stages Behind the Rungs

The three rungs say what a model can do. The field's own vocabulary for when each capability is installed has meanwhile settled on three named stages (Tu et al., 2025):

  • Pre-training — next-token prediction on web-scale corpora. Produces the base model.
  • Mid-training — the same next-token objective on a curated blend (high-quality domain data, QA pairs, CoT traces, instruction and tool-use data) under a decaying learning rate. It amplifies targeted capabilities — mathematics, reasoning, coding, tool use, long context, multilinguality — while a reserved share of general data preserves what pre-training built.
  • Post-training — a different objective: SFT and RL on alignment data (instruction tuning, preference optimization, RL with verifiable rewards, tool-calling and structured-output SFT, safety).

Part III — The Agent Loop

A tool-calling model only proposes actions; the runtime turns it into an agent by running it in a loop that executes each requested tool call and returns the observation to the model.

Chatbot → Agent

Unlike single-turn chatbots that process one input and pause, an AI agent runs in a continuous loop:

  • Observes: Receives user messages, tool outputs, or sensor data.
  • Reasons: Evaluates current progress and plans the next move.
  • Acts: Triggers APIs, runs code, or calls tools.

It repeats this sequence until it completes the goal or requests human assistance.

Structural challenges

Transitioning from a simple chatbot to an autonomous agent exposes key challenges that a single LLM call cannot solve alone:

  • Persistence: Maintaining long-term context, history, and failure logs across turns and days.
  • Grounding: Connecting to real-world, up-to-date knowledge sources.
  • Action: Interfacing directly with tools, databases, and APIs.
  • Coordination: Enabling multi-agent collaboration, delegation, and reasoning for high-complexity tasks.
  • Safety: Applying robust guardrails, human oversight, and fail-safes during uncertain operations.

The Runtime — What Executes the Tools

The runtime is the program that hosts the agent loop: every part of the agent that is neither the model nor the inference engine, the program that loads the weights of the model and computes its output tokens (Ollama, llama.cpp, vLLM; behind a hosted API it is operated by the provider). Its jobs:

  • Advertise the available tools (names, arguments, schemas) to the model.
  • Parse the model's tool-call request and execute the actual function.
  • Feed the result back to the model and drive the loop.
  • Enforce policy — the model only requests; the runtime decides and executes.

This is the tool gateway + agent loop of the agent architecture (Agent Control and Its Boundaries). The model cannot act on its own, so the component of the runtime that executes a tool call, the tool gateway, is the trust boundary.

Talking to a Model: Messages & the System Prompt

The model is called with a list of role-tagged messages, not a single string:

  • system-prompt: standing instructions / persona, sent first; sets how the model should behave (tone, rules, role). Treated as higher priority than user text — a behaviour learned during alignment (the chat template), not a hard guarantee (cf. prompt injection).
  • user: the human's input.
  • assistant: the model's replies (and, later, its tool-call requests).
  • for agents additionally tool (see below): results handed back from a tool.

Chat-Completions API Format:

[
    {"role": "system", "content": "You are a terse assistant; answer in one sentence."},
    {"role": "user",   "content": "What is a token?"},
    ...
]

The system prompt is your main knob for behaviour — you'll change it in the lab.

The system prompt can also be found by search. With the weights frozen, candidate prompts are generated, scored with a metric on example inputs, and the better ones kept — automatic prompt optimization. The candidates come from bootstrapped demonstrations (Khattab et al. (2024)), from crossover and mutation of a population of prompts carried out by an LLM (Guo et al. (2024)), or from an LLM that reads execution traces and the evaluator's feedback and rewrites the instruction (Agrawal et al. (2026)). It optimizes the same objective as fine-tuning, over the prompt instead of the weights — which is the mechanism behind Level 2's self-improvement below.

Statelessness

The model does not remember previous turns. On every new turn, the runtime re-sends the entire array of history messages (system, user, assistant, tool). If you leave past messages out, the model forgets them instantly.

Tools

A tool is a function/capability the runtime exposes to the model — a way to act on or observe the world beyond generating text:

  • read/write a file, run code, query a database
  • search the web, call an API, send a message

Tool-Calling Training

Tool-calling training (also called function-calling training) is the fine-tuning step in which a model learns when a tool is needed and how to request one. During instruction tuning (SFT) and the reinforcement-learning phase the model is exposed to special chat formats, so that it learns to stop generating text and to emit a structured tool request.

Loops

The agent loop is the repetition of three steps — the model requests a tool call, the runtime executes the call, the model reads the result — until the task is done. Over the coming lectures, you'll learn different decision strategies to power this loop.

Written with the deliberation factored out, the loop commits to nothing — it is the classical agent program (Russell & Norvig, 2021, §2.4): a persistent internal state, updated from percepts, with one action selected per cycle.

$$ \begin{array}{l} \textbf{Agent-Loop}(\textit{goal}) \\ \hline \textbf{Input: } \textit{goal} \text{; a runtime providing the tools; a step budget } B \\ \textbf{Output: } \text{the result} \\ \hline 1: \quad \textit{state} \gets \text{Init}(\textit{goal}) \\ 2: \quad \textbf{while } \neg\,\text{Done}(\textit{state}) \textbf{ and } \text{steps} < B \textbf{ do} \\ 3: \quad \qquad a \gets \text{Decide}(\textit{state}) \qquad \text{// the only line a strategy changes} \\ 4: \quad \qquad o \gets \text{Execute}(a) \qquad \text{// the runtime acts; the model never does} \\ 5: \quad \qquad \textit{state} \gets \text{Update}(\textit{state}, a, o) \\ 6: \quad \textbf{return } \text{Result}(\textit{state}) \\ \hline \end{array} $$

where:

  • $a$: Action
  • $o$: Observation
  • $state$: for an LLM-agent this is the context.

Three names carry everything a deliberation strategy decides:

  • what $state$ is,
  • how $Decide$ picks, and
  • what makes $\text{Done}$ true.

Line 4 is the trust boundary. The step budget $B$ is there because line 3 may never choose to stop.

Planning: Reactive vs. Deliberate

Planning is the selection of the sequence of actions that leads to a goal; the planning paradigms differ in when that sequence is fixed — one action at a time, or as a plan before the first action.

  • Implicit Planning (ReAct - Reasoning and Acting)(Yao et al., 2023) The model emits an action, receives an observation, and chooses the next step. Simple, but vulnerable to local minima and compounding errors.
  • Explicit Plan Generation: The LLM breaks a complex goal into a structured DAG (Directed Acyclic Graph) (e.g. JSON) or plan file before executing.
  • Search-based Planning: Treats planning as a tree search over multiple potential execution paths. The model branches into multiple candidate actions at each step, evaluates intermediate progress via a self-critique/reward heuristic, and uses search algorithms like Breadth-First Search (BFS) to explore, backtrack, and select the optimal trajectory.

Structured Tool Calls (JSON)

The model requests a tool by emitting a structured tool call. Commonly a JSON object naming the tool and its arguments, matching a schema the runtime advertised (JSON is the native format; some systems use other encodings):

{ "name": "read_file", "arguments": { "path": "notes.md" } }

Note: Some model provider (e.g. OpenAI) emit an escaped JSON string in arguments.

Memory

Memory is the information that the runtime stores and places back into the context, so that an agent can use it across turns and across restarts:

  • Short-term: the running conversation (the context sent each turn).
  • Long-term: Facts and preferences are persisted to storage as text files. To find them later, they are indexed using embeddings (vectors). The system retrieves the correct text file via semantic similarity and feeds that text into the LLM as its long-term memory.

Because the model is stateless (Statelessness), memory must be managed by the runtime — stored, retrieved, and, when it grows too large, summarised (compaction). (Details: retrieval and compaction, later in the course.)

Proactivity

Proactivity is the ability of an agent to start a run without a new user message; the event that starts the run then comes from the runtime:

  • A heartbeat daemon wakes the agent on a timer (e.g. every few minutes).
  • On each tick it may check for new information and decide to act — remind you, fetch news, follow up on a task.

Sometimes agents without proactivity are called assistants.

Core Capabilities of an Agent

Four capabilities turn a static language model into an autonomous actor — each with a concrete algorithmic form:

Capability What it provides Mathematical / algorithmic form Course
Tools hands — interact with the outside world function schemas & an execution API → L-ReAct
Memory a past — context survives across turns / time vector spaces $\mathbb{R}^d$, KV-cache, JSONL logs → L-Embed, → L-Att, → L-RAG, → L-Memory
explicit Planning (optional) a future — decompose goals, search trajectories, replan plan schemas, DAGs, $A^*$ search, MDP policy → L-Decomp, → L-ToT, → L-MDP
Proactivity (optional) initiative — act unprompted on timers / events heartbeat daemons, background schedulers → L-Orch

Chatbot vs Agent — The Full Picture

Putting the pieces together:

Capability Chatbot Agent
Converse ✅ ✅
Call tools (act) ❌ ✅
Multi-step loop ❌ ✅
Memory across turns limited ✅
Plan / decompose (goals → sub-tasks) ❌ ✅ (often)
Act unprompted (proactivity) ❌ ✅ (often)

Part IV — Agent Architecture

Agents built on the same loop differ in how much the system around the model does: which capabilities it adds, what it places in the context, and which component holds the control and the trust boundary.

Agent Capability Levels

Beyond the training ladder (how the model is made), agents differ in how much the system around the model does. A useful capability ladder (Gulli, 2025):

  • Level 0 — Core reasoning engine: a standalone, stateless LLM — no tools, memory, or live data. (Part I above; model internals come later in the course.)
  • Level 1 — Connected problem-solver: model + tools — gather & process external info over multiple steps (web search, RAG, specialised APIs for accuracy) via a ReAct / function-calling loop.
  • Level 2 — Strategic problem-solver: multi-step planning plus context engineering, the selection of what enters the context at each step. Also self-reflection (Tree-of-Thoughts, Plan-and-Solve), proactive / continuous operation, and self-improvement (refining its own prompts/context).
  • Level 3 — Collaborative multi-agent systems: a team of specialists (division of labour, like an organisation) that delegate, negotiate, or run under a supervisor.

Context Engineering — A First Look

An LLM only "knows" what is in its context for this call (it is stateless, Statelessness). Context engineering is the discipline of deciding what to put there: selecting, packaging and trimming the most relevant information — the system prompt, tool descriptions, retrieved documents, tool outputs, memory / interaction history, and implicit data (user identity, session & environment state) — so the model's limited attention is spent on what matters.

  • Too little context → the model lacks the facts it needs.
  • Too much → it drowns in noise, and every token costs latency and money.

Context Richness and Context Budget

Output quality often depends more on the context you assemble than on the model itself (Gulli, 2025) — a strong model still underperforms with a poor informational environment. The finite window is why the agent system must also select, not only add.

Prompt engineering vs. context engineering.

  • Prompt engineering is the narrower sibling: crafting the wording and structure of a single instruction — role, examples (few-shot), output format, "think step by step" — to steer one call.
  • Context engineering is the broader discipline: it concerns the whole context across all steps of a run, not the wording of one instruction.

Context engineering is the job of the agent runtime and its developer. The context is assembled automatically at each call, around the user's message; the end-user only states the request.

Limits & Responsible Use ⚖️

Agents are powerful but not infallible — keep the limits in view from day one:

  • Hallucination. An LLM samples plausible tokens, not verified facts — so it can state wrong things fluently and confidently. (mitigated by grounding / guardrails, measured by factuality evaluation.)
  • Non-determinism. Sampling makes outputs vary run-to-run; repeatability needs low temperature and care.
  • Where agents fail. Errors compound over multi-step tasks, tools can be misused, and autonomy raises the safety/ethics stakes.

Agent Control and Its Boundaries

One component holds the control and every dependency on something outside the runtime is reached through a component of its own — a common, representative division, though simple agents discharge several of these duties in one place:

The runtimerequestanswercontexttext / tool-call requestrequested callobservationInference engineModel (LLM) — the weightsChannels — chat UI · CLI ·messaging · APIAPI gateway — the frontdoorauthentication · sessionrouting · rate limitingAgent Controlthe agent loop · sessionmemoryModel proxy/LLM Gatewayprovider routing · keys ·cost · cachingTool gateway — the trustboundaryallowlist · approval · toolexecutionTools and effects — files ·shell · HTTP · otherservices
  • Agent Control. It holds the control flow: it calls the model, reads the answer, issues the call the model requested, and repeats. It keeps the session memory, and it reaches nothing outside itself directly. This component is named after the agent loop it runs, and the two names are used interchangeably in this course.
  • One boundary component per external dependency. Agent Control reaches the user through the API gateway, the model through the model proxy, and the world through the tool gateway. Each is exchangeable because the interface belongs to Agent Control: changing the model provider changes the proxy alone.
  • Only one of the three is a trust boundary. The tool gateway authorizes an action the model proposed, and executes it. The API gateway authenticates a caller and the model proxy routes a call; both are useful, and neither decides whether an effect on the world may happen.

This division is not the design of one product; most agent runtimes converge on it.

Practice Framing: Model + Harness, Workflows vs. Agents

Production practice describes an agent as a model plus a harness, and separates workflows, whose control flow is fixed in code, from agents, whose control flow the model decides.

  • Model + Harness — harness (also called scaffold) is the practitioner's name for the runtime.
    • The division regroups the agent formula by who builds what: aligned LLM = the model, produced by the training ladder; tools + memory + loop (+ proactivity) = the harness.
    • "The model is the driver; the harness is the vehicle." You cannot engineer real agency purely by wrapping base models in if/else conditions.
    • Harness and runtime are terms of practitioners, and no standard or textbook defines them. The sources agree that the harness contains the agent loop and the tool handling. They disagree on the sandbox and the hosting of the agent: Osmani (2026) counts them as harness, Shen (2026) as a separate runtime. In this course runtime denotes every part of the agent that is neither the model nor the inference engine.
  • Workflows vs. Autonomous Agents
    • Workflows: Predefined code paths with LLM nodes for specific processing steps. Highly predictable and cheaper.
    • Agents: Dynamic loops where the model chooses its own execution path. Ideal for open-ended tasks where steps cannot be known in advance.

In Practice / This Week's Lab

The hands-on work is in two notebooks, and both are worked through in the lab session:

  • Exercises (lecture-Intro-exercises.ipynb) — pen and paper:
    • Part A — theory & calculations: conditional probability, the chain rule and statistical independence; a bigram model estimated by counting; the training ladder and the pipeline stages; chatbot vs agent and the core and its boundaries; the agent loop and the planning paradigms.
    • Part B — reflection (optional, not examined): an open question on critical thinking in language models.
  • Lab (lecture-Intro-lab.ipynb) — a tutorial whose cells are executed in order: set up Ollama, call a local tool-calling model via the OpenAI client, see that the model is stateless — memory exists only if you resend the history, and the token bill grows quadratically when you do — and inspect a structured tool call.

Summary

  • Part I: an LLM is an autoregressive distribution $P(W_{1:T})=\prod_t P(W_t\mid W_{1:t-1})$.
  • base → chatbot: alignment (SFT + RLHF/DPO) makes it follow instructions — reactive, talk-only.
  • chatbot → agent: tool-calling training lets it request tools via structured JSON calls; the runtime executes them.
  • Agent = aligned LLM + tools + memory (+ planning & proactivity), run in a loop
  • The agent's modules: chat model · Agent Control, i.e. the agent loop (the control + session memory) · API gateway · model proxy · tool gateway (the trust boundary).
  • Brown, Tom B., et al. "Language Models are Few-Shot Learners." Advances in Neural Information Processing Systems. Vol. 33. 2020. arXiv:2005.14165. — the base model, and the zero-, one- and few-shot settings of in-context learning.
  • Jurafsky, Daniel, and James H. Martin. Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. 3rd ed., online manuscript released August 19, 2026. — ch. 2, "Words and Tokens": words, subword tokens and byte-pair encoding; ch. 3, "N-gram Language Models": the Markov assumption, the estimation of an $n$-gram model from counts, perplexity and smoothing; ch. 8, "Post-training": instruction tuning and the alignment of a model by learning from preferences.
  • Ouyang, Long, et al. "Training language models to follow instructions with human feedback." Advances in Neural Information Processing Systems. Vol. 35. 2022. arXiv:2203.02155. — supervised fine-tuning followed by RLHF: the steps that turn a base model into an instruction-following assistant.
  • Tu, Chengying, et al. "A Survey on LLM Mid-training." arXiv preprint arXiv:2510.23081 (2025). — survey of the three training stages (pre-, mid- and post-training) that the training ladder places in order.
  • Wang, Lei, et al. "A Survey on Large Language Model Based Autonomous Agents." Frontiers of Computer Science, vol. 18, no. 6, 2024, 186345. arXiv:2308.11432. — survey of how LLM-based agents are constructed (profile, memory, planning and action modules), where they are applied, and how they are evaluated.
  • Xi, Zhiheng, et al. "The Rise and Potential of Large Language Model Based Agents: A Survey." Science China Information Sciences, vol. 68, no. 2, 2025, 121101. arXiv:2309.07864. — survey of LLM-based agents, from the classical definition of an agent (autonomy, reactivity, pro-activeness, social ability) to single-agent, multi-agent and human–agent systems.

References

Peer-reviewed papers

  • Agrawal, Lakshya A., et al. "GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning." International Conference on Learning Representations. Vol. 2026. 2026. arXiv:2507.19457. — reflective prompt evolution: an LLM rewrites the instruction from execution traces and evaluator feedback.
  • Berglund, Lukas, et al. "The Reversal Curse: LLMs trained on 'A is B' fail to learn 'B is A'." International Conference on Learning Representations. Vol. 2024. 2024. arXiv:2309.12288. — a fact fine-tuned in one direction is answered 96.7 % that way and 0.1 % in reverse, with no training-side repair; the same sentence in context is usable in both directions.
  • Brown, Tom B., et al. "Language Models are Few-Shot Learners." Advances in Neural Information Processing Systems. Vol. 33. 2020. arXiv:2005.14165. — the base model; the origin of the term in-context learning and the zero-/one-/few-shot spectrum.
  • Caballero, Ethan, et al. "Broken Neural Scaling Laws." International Conference on Learning Representations. Vol. 2023. 2023. arXiv:2210.14891. — a plain power law is strictly monotonic and has no inflection point; breaks, and the result that one cannot be extrapolated from below.
  • Guo, Qingyan, et al. "EvoPrompt: Connecting LLMs with Evolutionary Algorithms Yields Powerful Prompt Optimizers." International Conference on Learning Representations. Vol. 2024. 2024. arXiv:2309.08532. — crossover and mutation of a population of prompts, performed by an LLM.
  • Hoffmann, Jordan, et al. "An empirical analysis of compute-optimal large language model training." Advances in Neural Information Processing Systems. Vol. 35. 2022. arXiv:2203.15556. — Chinchilla: parameters and training tokens should be scaled equally, and why the earlier estimate was biased by a fixed learning-rate schedule.
  • Khattab, Omar, et al. "DSPy: Compiling Declarative Language Model Calls into State-of-the-Art Pipelines." International Conference on Learning Representations. Vol. 2024. 2024. arXiv:2310.03714. — prompts compiled from bootstrapped demonstrations filtered by a metric.
  • Krakauer, David C., et al. "Large language models and emergence: a complex systems perspective." Philosophical Transactions of the Royal Society A, vol. 384, no. 2320, 2026, 20250014. doi:10.1098/rsta.2025.0014. — emergence as a coarse-grained description, with no requirement for discontinuity.
  • Michaud, Eric J., et al. "The Quantization Model of Neural Scaling." Advances in Neural Information Processing Systems. Vol. 36. 2023. arXiv:2303.13506. — discrete skills with Zipfian use frequencies: abrupt single skills under a smooth aggregate power law.
  • Ouyang, Long, et al. "Training language models to follow instructions with human feedback." Advances in Neural Information Processing Systems. Vol. 35. 2022. arXiv:2203.02155. — SFT + RLHF; why a base model does not follow instructions.
  • Schaeffer, Rylan, et al. "Are Emergent Abilities of Large Language Models a Mirage?" Advances in Neural Information Processing Systems. Vol. 36. 2023. arXiv:2304.15004. — emergence as an artefact of discontinuous metrics.
  • Sumers, Theodore R., et al. "Cognitive Architectures for Language Agents." Transactions on Machine Learning Research, 2024. arXiv:2309.02427. — CoALA: the language model read as a probabilistic production system, and the agent loop as the cognitive architecture around it.
  • Wei, Jason, et al. "Emergent Abilities of Large Language Models." Transactions on Machine Learning Research, 2022. arXiv:2206.07682. — the LLM definition of an emergent ability.
  • Wooldridge, Michael, and Nicholas R. Jennings. "Intelligent agents: theory and practice." The Knowledge Engineering Review, vol. 10, no. 2, 1995, pp. 115–152. doi:10.1017/S0269888900008122. — the weak and strong notions of agency, and benevolence named as an assumption.
  • Yao, Shunyu, et al. "ReAct: Synergizing Reasoning and Acting in Language Models." International Conference on Learning Representations. Vol. 2023. 2023. arXiv:2210.03629. — the ReAct loop.
  • Yao, Shunyu, et al. "Tree of Thoughts: Deliberate Problem Solving with Large Language Models." Advances in Neural Information Processing Systems. Vol. 36. 2023. arXiv:2305.10601. — search-based planning.
  • Zelikman, Eric, et al. "STaR: Bootstrapping Reasoning With Reasoning." Advances in Neural Information Processing Systems. Vol. 35. 2022. arXiv:2203.14465. — self-taught reasoning from filtered rationales, and the capability floor below which it does not start.

Preprints & other non-peer-reviewed papers

  • Askell, Amanda, et al. "A General Language Assistant as a Laboratory for Alignment." arXiv preprint arXiv:2112.00861 (2021). — the HHH criteria (helpful, honest, harmless).
  • Bai, Yuntao, et al. "Constitutional AI: Harmlessness from AI Feedback." arXiv preprint arXiv:2212.08073 (2022). — RLAIF: preference labels produced by a model against a written list of principles.
  • Bai, Yuntao, et al. "Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedback." arXiv preprint arXiv:2204.05862 (2022). — RLHF toward helpful and harmless behaviour, with separate human comparison data for each.
  • Goldfeder, Judah, et al. "AI Must Embrace Specialization via Superhuman Adaptable Intelligence." arXiv preprint arXiv:2602.23643 (2026). — the three tests a definition of intelligence must pass, and SAI as the adaptation-speed alternative to a fixed task catalogue.
  • Grattafiori, Aaron, et al. "The Llama 3 Herd of Models." arXiv preprint arXiv:2407.21783 (2024). — small models trained far beyond compute-optimality for a cheaper inference budget.
  • Gunasekar, Suriya, et al. "Textbooks Are All You Need." arXiv preprint arXiv:2306.11644 (2023). — phi-1: the data distribution as a scaling axis of its own.
  • Kaplan, Jared, et al. "Scaling Laws for Neural Language Models." arXiv preprint arXiv:2001.08361 (2020). — the power-law dependence of pre-training loss on parameters, data and compute, each taken separately.
  • Tu, Chengying, et al. "A Survey on LLM Mid-training." arXiv preprint arXiv:2510.23081 (2025). — the three pipeline stages behind the rungs (pre-, mid-, post-training), and the definition that makes the boundary an objective rather than a dataset.
  • Zelikman, Eric, et al. "Quiet-STaR: Language Models Can Teach Themselves to Think Before Speaking." arXiv preprint arXiv:2403.09629 (2024). — reasoning trained from unlabelled text with the pre-training objective; the learned <|startofthought|> / <|endofthought|> tokens; the benefit as a skewed tail over hard tokens.

Textbooks & monographs

  • Gulli, Antonio. Agentic Design Patterns: A Hands-On Guide to Building Intelligent Systems. Springer Nature, 2025. — agent capability levels.
  • Jurafsky, Daniel, and James H. Martin. Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. 3rd ed., online manuscript released August 19, 2026. https://web.stanford.edu/~jurafsky/slp3/ — tokens and subword tokenization (ch. 2); the Markov assumption and the $n$-gram language model (ch. 3, §3.1); instruction tuning and alignment by preference-based learning (ch. 8).
  • Newell, Allen, and Herbert A. Simon. Human Problem Solving. Prentice-Hall, 1972. — production systems generalised from strings to an agent's goals and world state.
  • Russell, Stuart, and Peter Norvig. Artificial Intelligence: A Modern Approach. 4th ed., Pearson, 2021. — AI as rationality; the rational agent; the standard model (§1.1, §1.1.4, §2.2); the agent program — a persistent state updated from percepts, one action selected per cycle (§2.4).

Blogs, documentation & other web sources