Exercises

Agentic AI · L-Intro

Part A — Foundations & Calculations

Exercise 1 — Conditional Probability from a Joint Table (calculation)

Given the joint distribution $P(X,Y)$:

$X$ $Y$ $P$
0 0 0.1
0 1 0.2
1 0 0.6
1 1 0.1

Compute the conditional distribution $P(X \mid Y{=}1)$.

Exercise 2 — Build a Joint via the Chain Rule (calculation)

Given the marginal $P(W)$ and the conditional $P(D\mid W)$:

$W$ $P(W)$
sun 0.8
rain 0.2
$P(D\mid W)$ $D=$ wet $D=$ dry
$W=$ sun 0.1 0.9
$W=$ rain 0.7 0.3

Compute the joint table $P(W,D)=P(D\mid W)\,P(W)$.

Exercise 3 — Statistical Independence (calculation)

Marginals $P(T)$: hot 0.5, cold 0.5; $P(W)$: sun 0.6, rain 0.4. Joint $P(T,W)$:

$T$ $W$ $P(T,W)$
hot sun 0.4
hot rain 0.1
cold sun 0.2
cold rain 0.3

Are $T$ and $W$ statistically independent? Justify.

Exercise 4 — Chain Rule (theory)

  1. Chain Rule: Write $P(W_{1:3})$ for a 3-token sequence as a product of conditional probabilities.
  2. Joint Space Size: How many parameters are needed to store the full, unfactorised joint distribution $P(W_{1:T})$ in a lookup table for a vocabulary $\vert{}V\vert{}$ and length $T$? (Count the free parameters.)
  3. The Conditional Bottleneck: Why does the chain rule factorization in (1) fail to solve this exponential memory problem if we try to store the exact conditional probabilities $P(W_t \mid W_{1:t-1})$ in a lookup table? What structural assumption do classical language models use to fix this?

Exercise 5 — A Bigram Model by Counting (calculation)

The lecture estimated a first-order Markov (bigram) model from this corpus. The corpus is counted as one sequence of $20$ tokens, and . is a token of its own. The pair . the, which crosses a sentence boundary, is therefore counted as a bigram like every other pair:

the cat sat on the mat . the cat ate the fish . the dog sat on the log .

(a) Estimate by counting: the conditional distributions $P(W_t \mid W_{t-1}{=}\texttt{the})$ and $P(W_t \mid W_{t-1}{=}\texttt{cat})$. Give every non-zero entry and check each distribution sums to $1$.

(b) Score the sentence the cat sat on the mat . under the bigram model $P(W_{1:T}) = P(W_1)\prod_{t=2}^{T} P(W_t \mid W_{t-1})$. Take $P(W_1{=}\texttt{the})=1$: the first token of a sentence follows a ., and $P(\texttt{the}\mid\texttt{.})=\tfrac22=1$ in the corpus.

(c) Now score the dog ate the fish . — a grammatical sentence built from the same vocabulary. What value do you get, and why? Name the problem and the standard family of remedies.

(d) The corpus has $\vert{}V\vert{}=10$ distinct tokens. How many free parameters does the full joint $P(W_{1:6})$ need? How many does the bigram model need (transitions and the initial distribution)? How many a trigram model?

(e) Which conditional-independence statement licenses the reduction in (d)? Write it with the $\perp$ notation.

(f) An LLM is not an $n$-gram model with a very large $n$. Give two distinct reasons — one about the table in (d), one about how the conditional is computed.

(g) An $n$-gram model is usually estimated with two additional tokens: a start token <s> before the first token of every sequence and an end token </s> after its last token. Jurafsky & Martin (2026), ch. 3, count every sentence as a sequence of its own. Here the corpus is one sequence, so it receives one <s> and one </s>:

<s> the cat sat on the mat . the cat ate the fish . the dog sat on the log . </s>

In a formula the two tokens are written $\langle s\rangle$ and $\langle /s\rangle$.

  1. Which quantity of (b) and (d) does <s> replace?
  2. Estimate $P(W_t \mid W_{t-1}{=}\texttt{.})$ from the sequence with the end token. State the difference between the token . and the token </s>.
  3. A neural language model also has an end token in its vocabulary. The inference engine is the program that calls the model once per generated token. State how the inference engine uses the end token to terminate generation, and what terminates generation if the end token is never sampled.

Exercise 6 — The Training Ladder, the Pipeline Stages and the Capability Levels (conceptual)

(a) Explain what each ladder stage adds, and why a tool-calling-tuned model drives an agent loop reliably.

(b) The rungs say what a model can do; the pipeline stages — pre-training, mid-training, post-training — say when it was installed. Assign each rung to the stage(s) that produce it, and state what distinguishes mid-training from pre-training given that both optimise the same next-token objective.

(c) The training ladder (base → aligned → tool-calling) and the agent capability levels (0–3) answer two different questions. State each question in one sentence. Then give a system that sits high on one and low on the other — in both directions.

Exercise 7 — Chatbot vs Agent, and the Agent's Modules (conceptual)

(a) Classify each as chatbot or agent, and justify:

  • (i) a bot answering FAQs from a fixed text, no actions;
  • (ii) a system that reads your calendar, books a meeting, and emails attendees.

(b) In the agent architecture, which component

  • (i) talks to the messenger,
  • (ii) executes a tool,
  • (iii) calls the LLM?
  • (iv) holds the control flow — decides, after each model answer, whether to call the model again, issue a tool call, or reply to the user?

Exercise 8 — The Agent Loop (theory)

The lecture writes the agent loop with the deliberation factored out:

$$ \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}) \\ 4: \quad \qquad o \gets \text{Execute}(a) \\ 5: \quad \qquad \textit{state} \gets \text{Update}(\textit{state}, a, o) \\ 6: \quad \textbf{return } \text{Result}(\textit{state}) \\ \hline \end{array} $$

(a) A chatbot is this loop with two things taken away. Which, and what does the loop reduce to?

(b) Assign each of the four core capabilities — tools, memory, planning, proactivity — to the line (or the argument) that carries it.

(c) Line 4 is the security boundary. State precisely what it separates, and what is lost if the model executes the action itself.

(d) Give two distinct failure modes the step budget $B$ guards against. What does the caller lose when the loop stops because $B$ ran out rather than because $\text{Done}$ became true — and what must $\text{Result}$ therefore report?

(e) The model is stateless, yet $\textit{state}$ survives across iterations. Where does it live, and what exactly does the runtime do at line 3 on the $k$-th iteration?

Exercise 9 — Planning Paradigms, Workflows and Agents (conceptual)

(a) Classify each system as implicit planning, explicit plan generation, or search-based planning:

  1. an assistant that calls a search tool, reads the snippet, and decides from it what to call next;
  2. a coding assistant that first writes a task list into a file, then works through it;
  3. a system that expands several candidate next steps, scores each with a self-critique, and backtracks away from the ones that score badly.

(b) Look again at the Agent-Loop box. Which of the three paradigms does it describe? Justify your answer by naming the line that differs between them, and say what each paradigm needs $\textit{state}$ to hold.

(c) Workflow or agent? Decide for each and justify in terms of predictability and cost:

  1. every incoming invoice is OCR'd, the total extracted, and a row appended to a ledger;
  2. "find out why the nightly build started failing last week and propose a fix."

Part B — Reflection ⚖️

Exercise 10 — Critical Thinking in Language Models (optional — not examined)

This exercise is optional and is not part of the exam.

Open question. Are language models capable of critical thinking, or do they mainly reproduce majority opinion, including its prejudices? Answer in about one page: take a clear position, and state the strongest objection to it.

(a) A language model approximates the distribution $P(W_t \mid W_{1:t-1})$ of its training text. Does the most probable continuation correspond to the best-argued position or to the most frequent one? What follows for a well-argued view that is rarely written down?

(b) Which of these mechanisms could make a model depart from the majority — and does each one evaluate reasons or only shift the probabilities?

  1. the system prompt and the rest of the context;
  2. alignment by preference tuning;
  3. tools that bring in information not contained in the weights;
  4. the model's own intermediate steps — chain-of-thought, a derivation the model writes before its answer and then conditions on (Wei et al., 2022).

(c) Preference tuning rewards answers that raters prefer, and models learn from it to agree with the user's stated view, at times over the correct one — sycophancy (Sharma et al., 2023). Why is this more dangerous for an agent than for a chatbot?

(d) Design a test, runnable with the lab setup, that shows whether a model follows the evidence or the user's opinion, and state which result would falsify your position.

References.

  • Sharma, Mrinank, et al. "Towards Understanding Sycophancy in Language Models." International Conference on Learning Representations. Vol. 2024. 2024. arXiv:2310.13548.
  • Wei, Jason, et al. "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models." Advances in Neural Information Processing Systems. Vol. 35. 2022. arXiv:2201.11903.