Stanford OnlineStanford CS230 | Autumn 2025 | Lecture 8: Agents, Prompts, and RAG
CHAPTERS
- 0:05 – 3:38
Lecture goals: “Beyond LLM” and the toolkit for real-world agentic systems
Kian frames the lecture as a practical jump from core deep learning concepts to building production-grade LLM applications. He previews a toolbox approach: prompting, limited fine-tuning, RAG, agentic workflows, evals, and multi-agent patterns.
- •Motivation: moving from models to systems used in startups/companies
- •Breadth-first survey of techniques to accelerate future learning
- •High-level roadmap: prompting → (optional) fine-tuning → RAG → agents → evals → multi-agent
- •Emphasis on practical engineering trade-offs, not end-to-end product building
- 3:38 – 12:06
Why base LLMs fall short: domain gaps, staleness, control, and context limits
The class crowdsources limitations of vanilla pre-trained models and expands them into a concrete set of failure modes. The takeaway is that strong base models still need augmentation for enterprise-grade reliability and specificity.
- •Missing domain-specific knowledge and mismatched real-world data distributions
- •Knowledge cutoff and rapidly changing language/trends (e.g., new slang)
- •Hard-to-control outputs and safety/alignment issues (historical examples)
- •Need for high precision in domains like legal/medical and consistent style/format
- •Context window constraints for enterprise knowledge management use cases
- 12:06 – 16:42
Context windows & the “needle in a haystack” problem; is RAG future-proof?
Kian explains why even large context windows don’t fully solve retrieval and attention challenges. He introduces ongoing debate about whether RAG remains necessary as compute and context sizes grow, emphasizing latency and sourcing as enduring reasons.
- •Context windows are finite; large files and corpora exceed practical limits
- •Attention can degrade over long contexts (needle-in-a-haystack benchmark)
- •RAG preview: retrieve relevant info instead of rereading everything
- •Debate: infinite compute vs real constraints like latency and user experience
- •Analogy to web search ranking as a persistent narrowing mechanism
- 16:42 – 18:12
Two levers for better LLM apps: stronger foundation models vs better engineering
The lecture positions improvement along two axes: upgrading the underlying model and improving how you use it. This course focuses on the ‘engineering on top’ dimension—prompting, RAG, and agent workflows that raise performance without retraining.
- •Horizontal axis: model upgrades (e.g., GPT-3.5 → GPT-4 → GPT-4o)
- •Vertical axis: engineering methods that maximize a given model
- •Prompting, RAG, agents, and multi-agent systems as performance multipliers
- •Goal: systematic techniques rather than ad hoc prompt tinkering
- 18:12 – 21:45
Prompting matters: the BCG consultant study, “frontiers,” centaurs vs cyborgs
A research study on consultants is used to motivate prompt skill as a productivity differentiator. Kian highlights the idea of a frontier where AI helps vs hurts, and two human-AI collaboration styles that appear in practice.
- •Tasks can be inside or beyond the AI “frontier”; beyond it, AI can degrade results
- •“Falling asleep at the wheel”: overreliance without verification
- •Training in prompting improves outcomes vs untrained AI use
- •Centaurs (delegate big chunks) vs cyborgs (rapid back-and-forth iteration)
- •Prompt engineering as a universal skill, not a standalone long-term job role
- 21:45 – 27:35
Core prompt design principles: specificity, role prompting, reflection, and step-by-step thinking
Kian upgrades a vague summarization prompt into a targeted one, then gathers techniques from the class. He introduces prompt templates and chain-of-thought prompting as systematic ways to increase reliability and controllability.
- •Make requests specific: audience, length, format, and focus areas
- •Role prompting (“act as…”) to steer tone and expertise
- •Reflection/self-critique loops to improve outputs
- •Chain-of-thought prompting: instruct step-by-step reasoning and sub-steps
- •Prompt repositories and reusable templates to scale in production
- 27:35 – 31:58
Zero-shot vs few-shot prompting: aligning subjective tasks with examples
Using sentiment/tone classification, Kian shows why subjective labeling varies and how few-shot examples pin down the desired mapping. He also discusses practical limits of long prompts and real-world “turn count” failures.
- •Zero-shot can be ambiguous on subjective tasks (mixed sentiment reviews)
- •Few-shot examples act like lightweight alignment without weight updates
- •Operational pattern: add newly labeled examples to prompts over time
- •Prompt length/long conversations can degrade performance in practice
- •Engineering workaround: chunk conversations and summarize earlier turns
- 31:58 – 37:44
Chaining prompts (not chain-of-thought): modular workflows for control and debugging
Kian distinguishes chaining from chain-of-thought and shows how splitting a complex prompt into stages improves traceability. The key benefit is the ability to identify which step causes failures and iterate on that component.
- •Single “do-everything” prompts are hard to debug and control
- •Chaining separates steps: extract issues → outline → draft final response
- •Intermediate outputs enable targeted improvements and error isolation
- •Trade-off: additional calls increase latency (flagged for later discussion)
- •Chaining becomes a foundation for agentic workflows later
- 37:44 – 41:19
Evaluating prompts at scale: human review, tooling, and LLM-as-judge rubrics
The lecture shifts from writing prompts to systematically testing them. Kian explains manual grading, prompt testing platforms, and multiple forms of LLM judging (pairwise, scoring, rubric-guided) to automate iteration.
- •Start with human rating to build intuition and spot obvious failure modes
- •Tooling can run prompts across multiple models and organize comparisons
- •LLM-as-judge: pairwise preference vs single-answer rating
- •Rubrics improve judge reliability (criteria-based scoring)
- •Combine techniques: few-shot examples for the judge and for the rubric itself
- 41:19 – 44:52
Fine-tuning: when it helps, why to avoid it, and a cautionary Slack example
Kian argues that fine-tuning is often slower than model progress and costly in data/time, making it a last resort. A Slack fine-tuning anecdote illustrates how tuning can accidentally optimize for workplace behavior rather than instruction following.
- •Downsides: labeled data needs, overfitting, losing general utility, cost/time
- •Pragmatic concern: new base models can surpass your tuned older model
- •When it can still make sense: high-precision repeated domain tasks
- •Slack fine-tuning failure mode: model learns human-like procrastination/deflection
- •Preference for prompt/RAG/agent approaches before touching weights
- 44:52 – 50:09
RAG fundamentals: embeddings, vector databases, retrieval, grounding, and citations
Kian explains RAG as the core method to ground LLM outputs in external documents. He walks through the pipeline from embedding documents to retrieving relevant chunks and injecting them into a prompt template that enforces “I don’t know” behavior and sourcing.
- •RAG addresses: context limits, cutoff dates, hallucinations, and missing citations
- •Embed documents and store vectors in a vector database for fast similarity search
- •Embed the query and retrieve nearest documents/chunks
- •Prompt template: answer only from provided docs; otherwise say “I don’t know”
- •Add citation requirements (page/chapter/line links) for trust and auditability
- 50:09 – 53:19
RAG beyond vanilla: chunking for location-aware retrieval and HYDE for better matching
After a question about page/paragraph traceability, Kian introduces RAG enhancement ideas. He explains hierarchical chunking and HYDE, where the system generates a hypothetical answer document to improve retrieval similarity against long-form sources.
- •Chunking/hierarchical indexing: document-level and chapter-level embeddings
- •Improves precision and source localization in large PDFs and manuals
- •HYDE: generate a hypothetical long-form answer, embed it, then retrieve similar docs
- •Illustrates rapid research branching in RAG (survey paper referenced)
- •Key mindset: treat RAG as a design space with many tunable components
- 53:19 – 1:03:56
Agentic AI workflows: definition, examples, and the shift from deterministic to fuzzy software
Kian defines agentic workflows (per Andrew Ng) to reduce confusion around “agents,” and contrasts them with RL agents. He then explains how software engineering changes when outputs are probabilistic and inputs are open-ended, requiring guardrails and human-in-the-loop design.
- •Agentic workflow = multi-step LLM-driven process with tools/resources and planning
- •Example: refunds agent (RAG policy → ask order # → API lookup → confirm refund)
- •Why ‘agentic’ term helps distinguish from RL ‘agent’ terminology
- •Traditional software: structured data + deterministic logic; agentic: unstructured + fuzzy
- •Guardrails, safety, and human-in-the-loop patterns (e.g., appeals) become central
- 1:03:56 – 1:06:59
Enterprise workflow redesign example: credit risk memos and adoption realities
A McKinsey case study illustrates how agentic systems can compress multi-week processes by delegating sub-tasks to specialized agents and accelerating drafting. Kian emphasizes that organizational change and rollout across thousands of employees is typically the true bottleneck.
- •Baseline memo workflow: data gathering across many sources + iterative drafting loops
- •Agentic redesign: agent gathers/analyzes, drafts memo, humans review/refine
- •Reported impact: significant time reduction (20–60%)
- •Human roles often remain; process changes around them
- •Scaling challenge: retraining and changing incentives can take years
- 1:06:59 – 1:19:13
Inside an agent: memory tiers, tools/APIs, autonomy levels, and MCP for scalable tool access
Kian breaks down core building blocks of a practical agent: prompts, memory, and tools. He introduces working vs archival memory, degrees of autonomy (hard-coded steps vs tool-only constraints vs tool creation), and explains MCP as a more scalable interaction pattern than one-off API integrations—while noting open security/maintenance concerns.
- •Memory design: working/core vs long-term/archival trade-offs for latency
- •Tools: APIs, resources (e.g., CRM), and documentation that LLMs can interpret
- •Autonomy spectrum: fixed steps → choose steps with fixed tools → create tools/code
- •MCP concept: standardized agent-to-tool/agent-to-agent protocol for discoverable interactions
- •Practical concerns raised: API changes still require updates; security/auth and robustness
- 1:19:13 – 1:34:23
How to know an agent works: eval strategies + customer support case study
Kian leads a discussion on measuring agent quality and improving it using traces, objective vs subjective signals, and component-level vs end-to-end metrics. A customer support agent example (change shipping address) demonstrates task decomposition, tool design, and how to build a rigorous eval suite including LLM judges for tone.
- •Start with task decomposition by shadowing domain experts (e.g., support agents)
- •Design workflow: extraction (LLM) → database lookup/update (tool) → email drafting (LLM) → send (tool)
- •Importance of LLM traces for debugging multi-call pipelines
- •Eval taxonomy: end-to-end vs component-based; objective vs subjective; quantitative vs qualitative
- •LLM-as-judge for tone/politeness and preference testing across prompts/models
- 1:34:23 – 1:43:14
Multi-agent workflows: when parallelism and reuse beat a single agent (smart home exercise)
Kian explains why multiple agents can outperform one: parallel execution, specialization, and reusability across teams or products. A smart-home brainstorm produces hierarchical orchestrator designs plus specialized agents for climate, security/permissions, energy optimization, and inventory management.
- •Multi-agent value proposition: parallelism, specialization, reuse, easier debugging
- •When it’s not needed: if the work is mostly sequential, a single agent chain may suffice
- •Smart home agent ideas: movement/context, climate control, security/identity, energy management, fridge inventory + ordering
- •Common architecture: hierarchical orchestrator + specialist agents; sometimes add lateral links
- •Agent-to-agent interaction aligns with MCP-style tool abstraction
- 1:43:14 – 1:49:53
What’s next in AI: plateau debates, architecture search, multimodality, and skill half-life
Kian closes with open questions about whether progress is plateauing and what could unlock the next leap. He highlights architecture innovation, multimodal training effects, hybrid learning paradigms, brain-inspired vs non-human-centric research, and the rapid obsolescence of tactical methods.
- •Community debate on scaling plateaus and what ‘progress’ looks like in products
- •Architecture search could yield the “next transformer” with major efficiency gains
- •Multimodality improves capabilities across modalities (text ↔ image ↔ audio/video ↔ robotics)
- •Future systems likely blend supervised/unsupervised/RL/self-supervised methods
- •Fast-moving field: prioritize breadth + ability to learn deeply on demand