← All lectures

CME295 / Lecture 07

Agentic LLMs

Tool use, retrieval, and language models that act across multiple steps.

On this page
  1. Summary
  2. Knowledge Tree
  3. Feynman Questions
  4. Narrative Study Notes
  5. Suggested Answers

Watch the lecture

Watch on YouTube ↗

1. Summary

Meta: Source type: local timestamped SRT plus source video; title: CME295 Lecture 7 - Agentic LLMs; course: Stanford CME295 Large Language Models; language: English; duration: 01:49:22; transcript type: timestamped SRT with repeated caption overlap cleaned for measurement; generated date: 2026-09-10.

Core: The lecture extends reasoning LLMs into systems by adding retrieval for current knowledge, tool calling for structured external actions, and agents for iterative observe-plan-act workflows.

Abstract: Lecture 7 starts from the previous reasoning-model stack, then asks how an LLM can use knowledge and capabilities outside its weights. The first half explains RAG: long-context stuffing fails because context is finite and irrelevant tokens distract the model, so a system retrieves relevant chunks, augments the prompt, and generates from grounded context. The lecture then opens the retriever design space: chunk size and overlap, embedding dimensions, bi-encoders, approximate nearest neighbors, BM25, hybrid retrieval, contextual retrieval, prompt caching, reranking with cross-encoders, and ranking metrics such as NDCG, MRR, precision@K, and recall@K. The second half moves from information retrieval to action. Tool calling exposes documented APIs to the model, lets the model predict a structured call, executes that call outside the model, and feeds the structured result back for a natural-language response. The lecture closes by scaling tools through routers and MCP-like standardization, then defining agents as systems that repeatedly observe, plan, act, and stop only when the task state is solved. The practical design lesson is that external capability makes LLMs useful, but each added interface also adds retrieval, grounding, evaluation, budget, and safety failure modes.

Concept: Retrieval-augmented generation - a system pattern that retrieves relevant external context and places it in the prompt before generation.

Concept: Candidate retrieval - the fast first-stage search that narrows a large knowledge base to potentially relevant chunks.

Concept: Reranking - the slower second-stage scoring that compares query and candidate together to order the final chunks.

Concept: Tool calling - model-mediated selection of a documented external function plus backend execution and response synthesis.

Concept: Model Context Protocol - a standardization layer for exposing tools, prompts, and resources from external servers to LLM hosts.

Concept: Agentic workflow - an iterative system loop in which a model observes state, plans a next step, acts through tools, and repeats until a goal is complete.

TakeHome: RAG solves freshness by filtering external knowledge before the LLM sees it; it is primarily a retrieval-quality problem, not just a context-window problem.

TakeHome: Tool calling separates model reasoning from backend execution: the LLM chooses and parameterizes a call, while ordinary software performs the side effect.

TakeHome: Agents are powerful because they loop over tools and state, but that same loop amplifies grounding errors, token cost, and safety risk.

2. Knowledge Tree

Agentic LLM systems/
├── Starting point: reasoning LLMs/
│   ├── vanilla LLM limitations
│   ├── reasoning chains and GRPO recap
│   └── next gaps: freshness and action
├── RAG for external knowledge/
│   ├── motivation: cutoff, limited context, distraction
│   ├── retrieve, augment, generate
│   ├── knowledge base: documents, chunks, embeddings
│   ├── candidate retrieval: ANN and bi-encoders
│   ├── lexical retrieval: BM25 and hybrid scores
│   ├── contextual retrieval and prompt caching
│   ├── reranking with cross-encoders
│   └── retrieval metrics: NDCG, MRR, precision@K, recall@K
├── Tool calling for external actions/
│   ├── structured input-output as function
│   ├── API documentation and schema exposure
│   ├── model predicts call, backend executes call
│   ├── response generation from structured result
│   ├── SFT pairs versus prompt-optimized explanations
│   └── information, computation, and action tools
├── Scaling the tool ecosystem/
│   ├── too many tools in finite context
│   ├── tool selection and routing
│   ├── MCP servers and clients
│   └── tools, prompts, and resources
└── Agents and safety/
    ├── agents as autonomous goal pursuit
    ├── observe-plan-act loop
    ├── agent-to-agent protocol
    ├── data exfiltration and tool-based attacks
    └── start small, start capable, optimize later

3. Feynman Questions

Question 1. Why does the lecture say RAG is needed even when modern models have very large context windows?

Question 2. In the RAG pipeline, what distinct problem does each stage solve: retrieve, augment, and generate?

Question 3. Why does chunk size create a tradeoff between local precision and missing context?

Question 4. What is the difference between a bi-encoder retriever and a cross-encoder reranker?

Question 5. Why might BM25 retrieve the correct teddy-bear document when embedding similarity retrieves the wrong one?

Question 6. What does NDCG reward that plain recall@K does not?

Question 7. In tool calling, why is the model not the same thing as the backend tool implementation?

Question 8. Why does tool-use training often need one behavior for tool prediction and another behavior for final response generation?

Question 9. How does a tool selector or router make large tool ecosystems more scalable?

Question 10. What does MCP standardize between an LLM host and external tool providers?

Question 11. Why is an agent more than a single tool call?

Question 12. Why does the lecture end with safety and the advice to start small with capable models?

4. Narrative Study Notes

001 · From reasoning models to connected systems

00:00:05-00:08:50

The lecture opens by turning Lecture 6 into a launching point. Up to this point, the course has built models that can pretrain, follow instructions, align to preferences, and spend inference-time tokens on reasoning. The recap of GRPO matters because it reminds the learner that modern LLMs can be trained as policies: they produce candidate outputs, receive rewards, and update toward behavior that solves a task. But Lecture 7 changes the object of study. Instead of asking only whether the model can reason inside its own weights, the instructor asks how the model can interact with outside systems. That shift creates two practical gaps. First, the model may need knowledge that was not in pretraining or instruction tuning. Second, the model may need to do something in the world rather than merely answer. The lecture names the three techniques that address these gaps: RAG connects the model to external documents, tool calling connects it to external functions, and agents connect tool use into iterative workflows. The old context is reasoning inside the model; the new context is reasoning plus interfaces that let the model retrieve, call, and act.

Concept: Agentic LLMs - LLM-based systems that use external context, functions, or loops so the model can solve tasks beyond direct text generation. GRPO recap slide connecting Lecture 6 reasoning to Lecture 7 systemsGRPO recap slide connecting Lecture 6 reasoning to Lecture 7 systems

Mechanism: Reasoning models improve problem solving by spending extra tokens; connected systems improve capability by adding external state and external operations. The engineering challenge is to decide which part belongs in the model and which part belongs in the surrounding system.

Notes: The lecture separates today's work from the prior reasoning lecture: RAG targets freshness and knowledge access, while tool calling and agents target interaction with outside systems.

Application: For system design, this opening says to treat an LLM product as more than a model endpoint. A reasoning chain can improve derivation, but the product still needs retrieval when the answer depends on outside facts, tools when the answer requires structured computation or side effects, and agent loops when the task requires several dependent actions. The first design question is therefore not "which model," but "which interface must the model use to close the task gap."

StudyCue: Keep the three verbs in order: retrieve knowledge, call functions, and act through loops. They are the lecture's control vocabulary for moving from model intelligence to deployed systems.

LinkBack: Transcript 00:00:05-00:08:50.

002 · Why RAG is needed

00:08:50-00:15:30

The first main topic is retrieval-augmented generation. The instructor motivates it with a simple election example: if an event happened after the model's training cutoff, the model cannot know the answer from its weights. One naive fix is to put all recent information into the prompt, but the lecture rejects that fix for two reasons. Context length is finite, even when it reaches hundreds of thousands of tokens; a very large context is comparable to a large book, not to the whole evolving world. More importantly, irrelevant context can degrade performance. The needle-in-a-haystack example shows that a fact can become harder to use when it is buried inside a large prompt, especially when its position and surrounding distraction vary. The instructor uses this to state the core RAG principle: do not ask the LLM to attend to everything; first filter the outside world down to relevant evidence. RAG is not just a hack for small context windows; it is a discipline for protecting generation from stale weights and distracting context.

Concept: Knowledge cutoff - the boundary after which information is unavailable to a model unless it is supplied externally. Needle-in-a-haystack slide showing degradation from irrelevant long contextNeedle-in-a-haystack slide showing degradation from irrelevant long context

Mechanism: The retrieval layer changes the problem from remembering everything to selecting the evidence most likely to help the current question. That selection protects the LLM from both missing facts and irrelevant tokens.

Notes: The GPT-5 model-card example in the transcript is used as a moving illustration of two quantities: a knowledge cutoff date and a context window. The lecture's deeper point is stable: larger windows reduce pressure but do not remove the need for relevance filtering.

Application: In a production assistant, this means freshness cannot be solved by periodically hoping the base model knows more. The system must know when the user's question depends on recent or private state, then route to a retrieval path that returns compact evidence. A long-context model still needs an evidence policy, because context capacity does not guarantee context relevance.

StudyCue: The election example and the needle-in-a-haystack slide make the same point from two sides: missing context causes ignorance, while excess irrelevant context causes confusion.

LinkBack: Transcript 00:08:50-00:15:30.

003 · RAG pipeline and knowledge-base construction

00:15:30-00:25:00

After motivating RAG, the lecture gives the basic pipeline. A user prompt arrives first. The system retrieves documents or chunks that look relevant to that prompt. It then augments the prompt by adding the retrieved information. Finally, the LLM generates a response from the user request plus that evidence. This ordering matters because retrieval is doing the grounding work before generation begins. The instructor then moves into how the external knowledge base is built. Documents are divided into chunks, where a chunk is a bounded segment measured in tokens, often on the order of hundreds of tokens. Each chunk receives an embedding, so retrieval can compare the query to chunks in vector space. The design has hyperparameters: embedding dimension controls representational capacity and compute/storage cost; chunk size controls how much context each vector represents; overlap reduces boundary loss at the cost of redundancy. The practical tradeoff is not abstract. If chunks are too small, they lose the surrounding meaning that makes a passage interpretable. If chunks are too large, the embedding may blur several topics into one vector. The RAG pipeline works only when the knowledge base is cut and embedded so that retrieval can recover meaning at the right granularity.

Concept: Chunk - a bounded piece of a document used as the retrieval unit, usually sized in hundreds of tokens rather than whole documents. Retrieve, augment, generate slide showing the three RAG stagesRetrieve, augment, generate slide showing the three RAG stages

Mechanism: Chunking turns unstructured documents into searchable retrieval units; embeddings turn those units into vectors whose geometry approximates relevance. The important engineering choice is where to place the boundary between enough context and too much semantic averaging.

Notes: The transcript mentions typical embedding sizes around thousands of dimensions and typical chunk sizes around hundreds of tokens, with roughly 500 tokens as an example scale rather than a universal law.

Application: The chunking choice should follow the document type. A Markdown lecture note, JSON record, medical report, API manual, or legal contract carries structure that naive token slicing can destroy. The lecture does not go deep into structured chunkers, but it flags the right instinct: preserve natural boundaries when those boundaries carry meaning. Good RAG begins before retrieval, because badly prepared chunks make even a strong retriever search the wrong objects.

StudyCue: When evaluating a RAG system, ask whether the retrieved unit is the unit a human would cite. If the answer is no, tune chunking before blaming generation.

LinkBack: Transcript 00:15:30-00:25:00.

004 · Candidate retrieval with embeddings and bi-encoders

00:25:00-00:35:00

With the knowledge base constructed, the lecture separates retrieval into two stages. Candidate retrieval is the fast, broad first pass: from a huge knowledge base, select a smaller set of potentially relevant chunks, such as a few hundred. The instructor emphasizes speed because a naive linear scan across all stored vectors becomes expensive at scale. In practice, systems use approximate nearest-neighbor indexing or related partitioning strategies to avoid comparing the query against every chunk one by one. The architecture used in this first pass is often a bi-encoder. The query passes through an encoder and becomes a query vector. Each chunk has already passed through an encoder and become a chunk vector. The retriever compares those two independently computed vectors, often with cosine similarity or a related distance. Sentence-BERT appears as the example paper because it trains sequence embeddings so relevant pairs have high cosine similarity and irrelevant pairs have low cosine similarity. A bi-encoder buys retrieval speed by encoding query and chunk separately, then reducing relevance to a vector-similarity operation.

Concept: Bi-encoder - a retrieval architecture in which the query and document chunk are encoded independently before a similarity score compares their vectors. Candidate retrieval slide showing query and chunk encoded separatelyCandidate retrieval slide showing query and chunk encoded separately

Mechanism: The independence of the two encodings makes precomputation possible: chunks can be embedded offline, indexed once, and searched quickly at inference time. The price is that the query and chunk do not interact through attention before the first-stage relevance score is computed.

Notes: Approximate nearest-neighbor search belongs to this first-stage speed problem. The model architecture and index architecture work together: the encoder creates vectors, and the index makes vector lookup scalable.

Application: This is the retrieval analog of using a cheap screen before an expensive diagnostic test. The first-stage retriever should avoid false negatives, because a chunk missed here cannot be rescued by a later reranker or generator. At the same time, it must stay fast enough to support interactive latency. Candidate retrieval should be judged mainly by whether it preserves the right evidence for the next stage.

StudyCue: Do not confuse embedding quality with index quality. The embedding model defines the space; the ANN/index method determines how efficiently the system searches that space.

LinkBack: Transcript 00:25:00-00:35:00.

005 · Hybrid and contextual retrieval

00:35:00-00:45:00

The lecture then shows why embedding similarity alone is not always enough. Semantic similarity can retrieve passages that are meaningfully related but miss exact words that matter. The teddy-bear example makes the failure concrete: if the query asks where Cuddly is, an embedding system may treat Cuddly and Huggy as semantically close because they are both teddy-bear names, but the user needs the document that specifically names Cuddly. BM25 gives a complementary signal because it rewards lexical overlap between the query and document. For use cases where exact terms, identifiers, names, product codes, or patient-specific labels matter, hybrid retrieval can combine embedding-based semantic scores with BM25-like heuristic scores. The instructor then returns to the chunk-boundary problem. A chunk may be locally relevant but hard to interpret without its parent document. Contextual retrieval mitigates this by prepending a short, LLM-generated context to each chunk before embedding or retrieval. Because generating context for many chunks could be expensive, prompt caching can reuse activations for the shared document prefix. Hybrid retrieval protects exact-match requirements, while contextual retrieval protects meaning that would otherwise be lost at chunk boundaries.

Concept: BM25 - a lexical retrieval method that scores documents using query-term overlap and related term-frequency signals. Contextual retrieval slide showing chunk-level context from the whole documentContextual retrieval slide showing chunk-level context from the whole document

Mechanism: The hybrid score answers whether the right words appear, and the contextual prefix answers what the isolated chunk means inside the larger document. Both fixes attack relevance failures that pure vector similarity can hide.

Notes: Prompt caching is introduced as a cost-control method: when many chunk-context prompts share the same long document prefix, the system can compute that prefix once and reuse stored activations during generation.

Application: The teddy-bear naming example generalizes to domains Sid would care about: patient IDs, device serial numbers, gene symbols, company tickers, drug names, and error codes often require exact lexical recovery. A semantic retriever may understand the topic but still miss the exact object. Hybrid retrieval is a guardrail against semantic smoothing when identity-bearing tokens matter.

StudyCue: Contextual retrieval and hybrid retrieval solve different failure modes. One restores missing parent context; the other restores exact-term pressure.

LinkBack: Transcript 00:35:00-00:45:00.

006 · Reranking and retrieval metrics

00:45:00-00:58:20

Once candidate retrieval has narrowed the search space, the lecture introduces reranking as the slower but more precise second stage. A reranker does not score query and chunk independently. Instead, a cross-encoder receives both at the same time and can compute attention across their tokens before producing a relevance score. That interaction is more expressive than vector similarity because the model can notice token-level alignments, contradictions, and context-dependent relations. It is also more expensive, which is why it is applied only to the smaller candidate set. The lecture then asks how to measure whether the final ranking is good. NDCG rewards systems that place relevant documents earlier, discounting relevance as rank gets worse and normalizing by the ideal possible ranking. MRR focuses on the rank of the first relevant result. Precision@K asks how many of the selected top-K chunks are actually relevant. Recall@K asks how many of all actually relevant chunks were captured in the top K. Benchmarks such as the Massive Text Embedding Benchmark let retriever variants be compared with these metrics. Retrieval quality is not one number: NDCG measures ordering quality, MRR measures first-hit speed, precision@K measures selected-set purity, and recall@K measures missed evidence.

Concept: Cross-encoder - a reranking model that jointly processes the query and chunk so attention can model direct interactions before scoring relevance. NDCG slide showing discounted cumulative gain normalized by ideal rankingNDCG slide showing discounted cumulative gain normalized by ideal ranking

Mechanism: The two-stage design spends cheap computation to avoid missing candidates, then spends expensive computation only where better ordering can change the final prompt. This is the same engineering pattern as many search and recommendation systems: broad recall first, precise ranking second.

Notes: NDCG is sensitive to rank position, while recall@K is not. A system can retrieve the same relevant documents but receive a worse NDCG if it buries the best evidence below weaker candidates.

Application: Retrieval metrics should be chosen by failure cost. If the application only needs one authoritative source, MRR may be central. If the model will synthesize from several passages, precision@K matters because wrong passages pollute the prompt. If missing one critical source is dangerous, recall@K matters. NDCG becomes valuable when the order of evidence changes what the generator is likely to trust first.

StudyCue: The reranker is not a replacement for candidate retrieval; it is a precision layer placed after recall has already done its job.

LinkBack: Transcript 00:45:00-00:58:20.

007 · Tool calling as structured external capability

00:58:20-01:10:00

The second major topic begins by contrasting unstructured documents with structured input-output relationships. In RAG, the outside world is mostly text to retrieve. In tool calling, the outside world can be represented as a function: given arguments, return a structured output or cause an external action. The instructor anchors the definition in the idea that autonomous systems complete tasks by dynamically accessing, and sometimes acting on, external resources. The teddy-bear function makes the abstraction concrete. A function such as find_teddy_bear has a name, documentation, arguments such as location, backend implementation that queries an API, and structured return values such as candidate teddy bears and their locations. The LLM does not need to see every implementation detail. It needs the API surface: what the function is called, what it means, what inputs it expects, and what output structure it will return. Tool calling turns the model from a closed text generator into a controller that can choose documented software interfaces.

Concept: Function API - the exposed name, documentation, input schema, and output schema that let the LLM know when and how to call a tool. Real-life tool example showing an LLM with a function APIReal-life tool example showing an LLM with a function API

Mechanism: The model predicts the call, but ordinary backend code executes the call; this separation keeps probabilistic language modeling distinct from deterministic system integration. That distinction is essential for debugging and safety.

Notes: Python appears because it is easy for LLMs and humans to read, not because tool calling is intrinsically tied to Python. Any language or service interface can be exposed if its behavior is documented and structured.

Application: This separation also defines responsibility. The prompt and schema should make the tool legible to the model, but the backend must validate arguments, enforce permissions, handle errors, and return structured data. The model should not be trusted to implement the security boundary just because it can describe the call. A tool is safe only when the software boundary remains explicit after the model chooses the action.

StudyCue: In diagrams, track which arrows are model inference and which arrows are ordinary program execution. Most tool bugs come from blurring that boundary.

LinkBack: Transcript 00:58:20-01:10:00.

008 · Tool execution and tool-use training

01:10:00-01:20:00

The lecture then decomposes tool calling into an execution loop. First, the model receives the user query plus the function API and predicts which function to call with which arguments. Second, the function call is executed outside the LLM, so the backend returns a structured answer. Third, the model receives that structured result and generates the final natural-language response. The instructor uses this decomposition to ask what must be trained. One behavior maps conversation context and API documentation into a tool call; another behavior maps the tool result plus conversation history into a final response. Traditional supervised fine-tuning can provide paired examples for both stages. But the lecture also points out a newer practical alternative: since strong LLMs already understand code-like structures, one can sometimes avoid retraining and instead optimize an explanation or prompt that teaches the model how to use the API. Few-shot examples can help, but they may generalize poorly if they cover only narrow input phrasings. A better explanation can be iterated offline against an evaluation set of desired tool calls, then reused at inference time. Tool-use training is really interface teaching: the model must learn both when to call the function and how to turn the returned structure back into the user's answer.

Concept: Tool prediction - the model behavior that maps a user request and available API documentation into a structured function call. Tool-use training slide showing tool prediction and response generation pairsTool-use training slide showing tool prediction and response generation pairs

Mechanism: SFT changes model weights, while prompt-optimized explanations change the interface contract placed in context. Both methods try to make the same latent behavior reliable: parse the user goal, choose the right tool, produce valid arguments, and synthesize the answer.

Notes: The final response stage should use the full conversation state, not only the raw JSON. The model must know why the tool was called, what the result means, and how the user expects the answer to be phrased.

Application: The lecture's offline prompt-optimization idea is especially practical for fast-changing tool ecosystems. Instead of retraining the model each time an API changes, the developer can update the API description, run an evaluation set, and iterate on the explanation until call prediction stabilizes. The evaluation set becomes the bridge between prompt engineering and reliable interface behavior.

StudyCue: Tool calling has two correctness checks: the call must be syntactically valid for the backend, and the final response must be semantically faithful to the backend result.

LinkBack: Transcript 01:10:00-01:20:00.

009 · Tool categories, tool selection, and MCP

01:20:00-01:33:00

After teaching one tool, the lecture expands to many tools. Tool calling can support information tools such as search, weather, or stocks; computation tools that translate a query into executable code; and action tools that send email or change external state. This breadth creates the next bottleneck. A model cannot carry every possible tool specification in a finite context window, and even if it could, too many tools can distract it or make it mediocre at selecting among them. The instructor presents tool selection as the scaling pattern. A lightweight first stage sees the query and a compact list of tool names/descriptions, then selects or routes to the tools that may be relevant. A second stage places only those selected API specifications into the model context. The lecture then introduces MCP as a standardization attempt. Instead of every LLM host and tool provider inventing custom formats, an MCP server can expose tools, prompts, and resources to an MCP client inside the LLM host. Tool selection controls context pressure, and MCP controls interface fragmentation; together they make tool ecosystems more scalable.

Concept: Tool router - a selection component that narrows a large tool list to the small API set likely to help the current user request. Tool selection slide showing router selecting tools before final LLM callTool selection slide showing router selecting tools before final LLM call

Mechanism: The router treats tool descriptions like a retrieval problem over capabilities, while MCP treats tool exposure like a protocol problem between infrastructure components. One chooses what to show; the other standardizes how it is shown.

Notes: In the teddy-bear poetry-book example, the LLM host is the application using the model, the MCP server is the book provider, tools find or recommend books, prompts demonstrate usage, and resources store external book or user-collection data.

Application: A large product cannot solve tool scale by putting every integration into every prompt. The system needs a capability index, routing policy, and protocol surface so that tool exposure remains small, relevant, and maintainable. Tool selection is RAG applied to actions: retrieve the right capability before asking the model to use it.

StudyCue: MCP is not the agent itself. It is infrastructure that makes external capabilities discoverable and callable in a more standard way.

LinkBack: Transcript 01:20:00-01:33:00.

010 · Agents and the observe-plan-act loop

01:33:00-01:40:00

Agents are introduced as one layer above tools. A single tool call can answer one structured need, but an agent autonomously pursues a goal on the user's behalf. The lecture defines that autonomy through recurrence: the system can reason, call tools, observe the returned state, plan a next step, and continue until the goal is satisfied. The teddy-bear temperature example shows the loop. The user says the teddy bear is cold and asks the system to do something. The observe step reformulates the vague request into actionable state: the room temperature is relevant and currently unknown. The plan step identifies that the system must determine the temperature. The act step calls a tool such as get_current_room_temperature. The next observe step interprets the returned temperature, such as 65 Fahrenheit, as too cold. A new plan proposes increasing the temperature, and a new act step calls a thermostat adjustment function. When the final observation says the room is now warm enough, the agent exits and reports the completed action to the user. An agent differs from a tool call because it maintains task state across repeated observe-plan-act cycles until the goal condition is met.

Concept: ReAct loop - an agent pattern that alternates reasoning or observation with actions so tool results can drive the next decision. ReAct in action slide showing observe stage for the teddy-bear temperature taskReAct in action slide showing observe stage for the teddy-bear temperature task

Mechanism: The loop converts ambiguous user intent into measured state, planned intervention, executed action, and verified completion. That conversion is why agents feel more capable than one-shot chat responses.

Notes: The important stop condition is not merely that a tool was called. The agent stops when the observed world state matches the task objective closely enough to return a final response.

Application: The teddy-bear temperature example is intentionally simple, but it captures the architecture of more serious workflows. A medical scheduling agent, lab-data agent, or financial operations agent would still need the same loop: identify missing state, select the next measurement or action, execute through a tool, interpret the result, and decide whether to continue. The agent's intelligence is distributed across state tracking, planning, tool choice, and stop-condition judgment.

StudyCue: ReAct is easiest to remember as a control loop, not as a prompt style. The loop matters because each action changes the state that the next reasoning step must observe.

LinkBack: Transcript 01:33:00-01:40:00.

011 · Agent-to-agent protocols and safety

01:40:00-01:46:00

Once agents act independently, the lecture asks how they can communicate and how they can fail. The agent-to-agent protocol is presented as another standardization effort. An agent can expose skills, examples, execution status, and cancellation behavior so another agent or host knows what it can request and how to track or stop that request. A student question clarifies that an agent can be imagined as an LLM with its own context and task loop, while other agents may see only its inputs and outputs. That modularity helps compose systems, but it also creates budget and control concerns. The lecture then moves to safety. Tool-enabled models can write externally visible data, invoke APIs, or change user state, so malicious prompts or compromised workflows can cause real-world harm. Data exfiltration is the concrete example: a prompt might try to send sensitive information through an email or other public channel. The instructor mentions tool-use safety benchmarks and a recent Anthropic report about tool-assisted cyberattack behavior to emphasize that attackers and defenders both gain capability. The safety issue is not that tools are bad; the issue is that tool access turns language mistakes and malicious instructions into possible external actions.

Concept: Data exfiltration - the unauthorized movement of private information out of the user's controlled environment through a tool or communication channel. Safety slide listing real-world harm and data exfiltration risksSafety slide listing real-world harm and data exfiltration risks

Mechanism: Standard protocols make agents composable, but safety controls must decide which requests, tools, arguments, and outputs are allowed before composition becomes execution. This is why permissioning and monitoring belong in the system design, not only in the prompt.

Notes: The transcript treats safety as a first-order design constraint for agentic systems: as tool capability grows, evaluation must include misuse, prompt injection, exfiltration, harmful side effects, and the system's ability to refuse or contain unsafe actions.

Application: The safety lesson is a systems lesson. If an agent can read secrets and write emails, then prompt injection can become exfiltration unless the system separates read permissions, write permissions, destination checks, human approvals, and audit logs. Stronger model reasoning helps, but it does not replace these controls. Agent safety must be enforced where authority crosses from text into external state.

StudyCue: The more independent the agent, the more important cancellation, status reporting, sandboxing, and permission scopes become.

LinkBack: Transcript 01:40:00-01:46:00.

012 · Closing design advice for agentic systems

01:46:00-01:49:18

The lecture closes by returning from protocols and safety to engineering practice. Agents can fail at every step of the thought process: they may misread a tool result, choose the wrong tool, predict invalid arguments, diverge during a multi-step loop, or optimize the wrong intermediate target. These compounding errors explain why large-scale fully autonomous agents remain difficult despite strong LLMs and abundant tools. The instructor distinguishes two ways to improve capability. Fine-tuning can repair specific behaviors, but ideally one wants stronger base reasoning and better evaluation so the system does not require fragile task-specific patches for every failure mode. The final practical advice is conservative and useful: start with a small, simple use case; verify that it works correctly; use a capable model first to learn the headroom; then optimize latency, size, and cost after the behavior is correct. The last line reframes coding in the age of code generation: producing code is becoming cheap, but judging whether code is correct and useful remains the hard part. For agentic LLMs, engineering taste becomes the scarce resource because the system builder must know what to automate, what to constrain, and what correctness means.

Concept: Start correct, then optimize - a development strategy that first proves the workflow on a narrow case with a capable model, then reduces cost and latency only after behavior is reliable. Closing thoughts slide advising simple starts and capable models before optimizationClosing thoughts slide advising simple starts and capable models before optimization

Mechanism: Agent reliability is multiplicative across steps: a small error rate per decision can become a large failure rate across a long autonomous workflow. Short loops, clear tools, strong models, and explicit evaluation keep that compounding under control.

Notes: The closing advice matches the whole lecture's structure. RAG, tool calling, MCP, and agents all add capability by exposing interfaces, but each interface must be measured, constrained, and judged by someone who understands the task.

Application: This is why the lecture's final advice is not merely operational caution. Starting with a capable model reveals whether the workflow is conceptually possible before optimization hides failures behind weaker reasoning. Starting small reduces the number of states the developer must inspect. Only after the workflow is correct should latency, model size, and cost become the main optimization targets. Capability-first prototyping prevents premature efficiency work from disguising an unsolved correctness problem.

StudyCue: The final "taste matters" message is a technical claim: as code generation becomes cheaper, the hard work moves to specification, evaluation, architecture, and deciding whether the generated system is actually right.

LinkBack: Transcript 01:46:00-01:49:18.

5. Suggested Answers

Question 1. Why does the lecture say RAG is needed even when modern models have very large context windows?

Answer 1. Large windows help, but they do not solve freshness or relevance. A model still lacks post-cutoff information unless it is supplied externally, and too much irrelevant context can distract generation. RAG is needed because it retrieves the relevant outside evidence before the model spends attention on the prompt.

Question 2. In the RAG pipeline, what distinct problem does each stage solve: retrieve, augment, and generate?

Answer 2. Retrieve finds candidate evidence in the knowledge base, augment inserts that evidence into the user prompt, and generate uses the grounded prompt to produce the answer. The pipeline separates evidence selection from language generation so the model answers from selected context rather than from weights alone.

Question 3. Why does chunk size create a tradeoff between local precision and missing context?

Answer 3. Small chunks can point retrieval to a precise local passage, but they may remove the surrounding explanation needed to interpret it. Large chunks preserve more context, but their embeddings may average together several topics. Chunk size controls whether the retrieval unit is too context-poor or too semantically diffuse.

Question 4. What is the difference between a bi-encoder retriever and a cross-encoder reranker?

Answer 4. A bi-encoder embeds the query and chunk separately, then compares vectors quickly. A cross-encoder reads query and chunk together, uses token-level interaction, and scores relevance more precisely but more expensively. Bi-encoders buy speed through independent embeddings; cross-encoders buy accuracy through joint attention.

Question 5. Why might BM25 retrieve the correct teddy-bear document when embedding similarity retrieves the wrong one?

Answer 5. Embedding similarity may treat Cuddly and Huggy as semantically related teddy-bear names, while BM25 rewards exact word overlap with the query. When an identifier matters, lexical overlap can preserve the exact term that semantic similarity may blur.

Question 6. What does NDCG reward that plain recall@K does not?

Answer 6. Recall@K checks whether relevant documents appear somewhere in the top K, but NDCG discounts lower-ranked relevant documents and normalizes against the ideal ranking. NDCG rewards putting relevant evidence near the top, not merely including it somewhere in the selected set.

Question 7. In tool calling, why is the model not the same thing as the backend tool implementation?

Answer 7. The model sees the API surface and predicts a structured call, but external software executes the function, accesses databases or services, and returns structured output. The LLM controls the interface choice, while the backend performs the actual operation.

Question 8. Why does tool-use training often need one behavior for tool prediction and another behavior for final response generation?

Answer 8. The first behavior maps the user request and API documentation into a valid call with arguments. The second behavior maps the tool result and conversation history into the user's natural-language answer. Tool use requires both valid action selection and useful response synthesis.

Question 9. How does a tool selector or router make large tool ecosystems more scalable?

Answer 9. It first selects a small set of likely relevant tools from a large list, then passes only those API specifications into the model context. A router reduces latency, context pressure, and confusion by showing the model only the tools that may matter for the current task.

Question 10. What does MCP standardize between an LLM host and external tool providers?

Answer 10. MCP standardizes how external servers expose tools, prompts, and resources to an MCP client inside the LLM host. It turns custom tool integration into a protocol boundary between the host and the provider.

Question 11. Why is an agent more than a single tool call?

Answer 11. A single tool call performs one operation, while an agent keeps state across a loop: observe what is known, plan what is needed, act through tools, observe the result, and repeat. An agent is defined by iterative goal pursuit, not by one isolated API invocation.

Question 12. Why does the lecture end with safety and the advice to start small with capable models?

Answer 12. Tool and agent systems can cause real external effects, and multi-step loops compound small model errors into larger failures. Starting small with a capable model lets the builder verify correctness before optimizing cost or latency. The scarce skill is judging and constraining the workflow before automation scales the mistake.