Skip to content
Stanford CS230 | Autumn 2025 | Lecture 8: Agents, Prompts, and RAG
This video isn’t embeddableWatch on YouTube →
Stanford OnlineStanford Online

Stanford CS230 | Autumn 2025 | Lecture 8: Agents, Prompts, and RAG

For more information about Stanford’s Artificial Intelligence professional and graduate programs, visit: https://stanford.io/ai November 11, 2025 This lecture covers agents, prompts, and RAG. To learn more about enrolling in this course, visit: https://online.stanford.edu/courses/cs230-deep-learning Please follow along with the course schedule and syllabus: https://cs230.stanford.edu/syllabus/ More lectures will be published regularly. View the playlist: https://www.youtube.com/playlist?list=PLoROMvodv4rNRRGdS0rBbXOUGA0wjdh1X NOTE: There was no class on November 4, 2025 (Lecture 7). The previous lecture is Lecture 6. Andrew Ng Founder of DeepLearning.AI Adjunct Professor, Stanford University’s Computer Science Department Kian Katanforoosh CEO and Founder of Workera Adjunct Lecturer, Stanford University’s Computer Science Department

Kian Katanforooshhost
Nov 21, 20251h 49mWatch on YouTube ↗

EVERY SPOKEN WORD

  1. 0:053:38

    Lecture goals: “Beyond LLM” and the toolkit for real-world agentic systems

    1. KK

      Hi, everyone. Welcome to another lecture for CS230 Deep Learning. Today, we're going to talk about enhancing large language model applications, and I, I call this lecture Beyond LLM. Um, it has a lot of newer content and, uh, the idea behind this lecture is y- we started to learn about neurons, and then we learned about layers, and then we learned about deep neural networks, and then we learned a little bit about how to structure projects in C3, and now we're going one level beyond into, uh, what would it look like if you were building, uh, agentic AI systems at work in a startup, in a company. Um, and, uh, it's probably one of the more practical lectures. Again, the goal is not to build a product end-to-end in the next hour or so, but rather to tell you all the techniques that AI engineers have cracked, figured out, are exploring, so that after the class you have sort of the breadth of view of different prompting techniques, different agentic workflows, multi-agent systems, evals, and then when you wanna dive deeper, you have the baggage to dive deeper and learn faster about it. Okay? Uh, let's try to make it as interactive as possible, as usual. Um, when we look at the agenda, the agenda is going to start with the core idea behind challenges and opportunities for augmenting LLMs. So we start from a base model. How do we maximize the performance of that base model? Um, then we'll dive deep into the first line of optimization, which is prompting methods, and we'll see a variety of them. Then we'll go slightly deeper. If we were to get our hands under the hood and do some fine-tuning, what would it look like? I'm not a fan of fine-tuning, and I talk a lot about that, but I'll explain why I, I try to avoid fine-tuning as much as possible. Um, and then we'll do a section four on retrieval-augmented generation or RAG, which you've probably heard of in the news. Maybe some of you have played with RAGs. We're gonna sort of unpack what a RAG is and how it works, and then the different methods within, um, RAGs. And then we talk about agentic AI workflows. Um, I'll define it. Um, Andrew Ng is one of the, call it, first ones to have called this trend a agentic AI workflows, and so we look at the definition that Andrew gives to agentic workflows, and then we start seeing examples. The section six is very practical. It's a case study where we will, uh, think about an agentic workflow, and we'll-- and I'll ask you to measure, um, uh, if the agent actually works, and we brainstorm how we can measure if, um, an agentic workflow is working the way you want it to work. There's plenty of methods called evals that, um, uh, solve that problem. Uh, and then we look briefly at multi-agent workflow, and then we can have a, a sort of open-ended discussion where I'll share some thoughts on what's next in AI. Um, and I'm looking forward to hearing from you all as well on that one. Okay? So let's get started,

  2. 3:3812:06

    Why base LLMs fall short: domain gaps, staleness, control, and context limits

    1. KK

      uh, with the problem of augmenting LLM. So open-ended question for you. You are all familiar with pre-trained models like GPT-3.5 Turbo or GPT-4.0. What's the limitation of using just a base model? What are the typical issues that might arise as you're using a vanilla pre-trained model? Yes.

    2. SP

      We lack some domain knowledge.

    3. KK

      Lacks some domain knowledge. You're perfectly right. You know, you-- We, we had a group of students a few years ago, it was not LLM related, but, um, you know, they were building a, an autonomous, uh, farming, uh, device or vehicle that had a camera underneath taking pictures of crops to determine if the crop is, uh, sick or not, if it should be thrown away, like if it should be, if it should be used or not. And, um, and that data set is not a data set you find out there. And the base model or a pre-trained, um, computer vision model would lack that knowledge, of course. What else? Yes.

    4. SP

      Trained on, uh, quality pictures, but the reality of the pictures are very dark, uh, or blurry.

    5. KK

      Okay, maybe the-- you're saying-- So just to re- uh, repeat for people online, you're saying the model might have been trained on high-quality data, but the data in the wild is actually not that high quality. And in fact, yes, the distribution of the real world might di-differ, uh, as we've seen with GANs from the training set, and that might create an issue with pre-trained models. Although pre-trained LLMs are getting better at, you know, handling all sorts of data inputs. Uh, yes.

    6. SP

      Uh, lack current information.

    7. KK

      Like what?

    8. SP

      Current information.

    9. KK

      Lacks current information. Uh, the LLM is not up to date. And in fact, you're right. Imagine you have to retrain from scratch your LLM every couple of months. Uh, one story that I found funny, um, it's from probably three years ago or maybe more, five years ago, where, um, during his first presidency, uh, President Trump one day tweeted, uh, Covfefe. You remember that tweet or no?Just covfefe, and it was probably a typo, or it was in his pocket, I don't know. But that word, uh, did not exist. Uh, the LLMs, in fact, that Twitter was running at the time could not recognize that word. And so, uh, the recommender system sort of went wild because suddenly everybody was making fun of that tweet using the word covfefe, and the LLM was so confused on, you know, what does that mean? Where should we show it? To whom should we show it? And this is an example of, uh, nowadays, especially on social media, there are so many new trends and, um, it's very hard to retrain an LLM to match the new trend and understand the new words out there. I mean, you know, you oftentimes hear Gen Z words like rizz or mid or whatever. I don't know all of them, but, uh, uh, you, you probably wanna find a way that, uh, can allow the LLM to understand those trends without retraining the LLM from scratch. Yeah. What else?

    10. SP

      It's trained to have a breadth of knowledge, and if you wanted to use

    11. KK

      Yeah. It might be trained on a breadth of knowledge, but it might fail or not perform adequately on a narrow task that is very well-defined. Uh, think about enterprise applications that... Yeah, enterprise application, you need high precision, high fidelity, low latency, and maybe the model is not great at that specific thing. It might do fine, but just not good enough, and you might wanna augment it in a certain way. Yeah.

    12. SP

      Maybe it has, like, a shallow domain knowledge, but not really deep, so it makes the model a lot heavier, a lot slower.

    13. KK

      Yeah.

    14. SP

      Training the model.

    15. KK

      So maybe it has a lot of, uh, broad domain knowledge that might not be needed for your application, and so you're using a massive heavy model when you actually are only using two percent of the model capability. You're perfectly right. You might not need all of it, so you might find ways to prune, quantize the model, modify it. All of these are, are, are good points. I'm gonna add a few more as well. Um, LLMs are very difficult to control. Uh, your last point is actually an example of that. You wanna control the LLM to use a part of its knowledge, but it's not. It's, in fact, getting confused. Uh, we've seen that in history. In 2016, uh, Microsoft created a notorious Twitter bot that learned from users, and it quickly became a racist jerk. Microsoft ended up removing the bot sixteen hours after launching it. The community was really fast [chuckles] at, uh, determining that this was a racist bot. Um, and, and, you know, you can empathize with Microsoft in the sense that it is actually hard to control an LLM. They might have done a better job to qualify before launching, uh, but it is really hard to control an LLM. Even more recently, this is a tweet from Sam Altman, um, last November, um, where there was this, uh, debate between Elon Musk and Sam Altman on, uh, whose LLM is the left-wing, uh, propaganda machine or the right-wing propaganda machine, and they were hating on each other's LLMs. Uh, but that tells you at the end of the day that, uh, even those two teams, uh, Grok and OpenAI, which are probably the best-funded team with a lot of talent, are not doing a great job at controlling their LLMs, you know. And from time to time, if you hang out on X, uh, you might see screenshots of users interacting with LLMs and the LLM saying something really controversial or, or, or, uh, racist or, you know, something that's-- would not co-- uh, not be considered, uh, uh, great by [chuckles] social standards, I guess. And, uh, and that tells you that the model is really hard to, um, to control. Um, the second aspect of it is, uh, something that you've mentioned earlier. LLMs may underperform in your task, um, and that might include specific knowledge gaps such as medical diagnosis. If you're doing medical diagnosis, you would rather have a-- an LLM that is specialized for that and is great at it. And in fact, something that we haven't mentioned as a group has sources, so the answer is sourced specifically. You have a hard time believing something unless you have the actual source of the research that backs it up. Um, inconsistencies in style and format. So imagine you're building a legal AI agentic workflow. Uh, legal has a very specific way to write and read, uh, where every word counts. You know, if you're negotiating a large contract, every word on that contract might mean something else when it comes to the court, and so it's very important that you use an LLM that is very good at it. The precision matters. And then, you know, task-specific understanding, such as doing a classification on a niche field. Here, I pulled an example where, um, you know, let's say a biotech product is trying to use an LLM to, uh, categorize user reviews into positive, neutral, or negative. Um, you know, maybe for that company, something that, uh, would be considered a negative review typically is actually considered a neutral review because the NPS of that industry tends to be way lower than other industries, let's say. Um, that's a task-specific understanding, and the LLM needs to be aligned to what the company believes is the categorization that it wants. We will see an example of how to solve that problem in a second. And then limited context handling. Um, a lot of AI applications, especially in the enterprise, have, uh, required data that has a lot of context. Like, just to give you a simple example, knowledge management is an important space that enterprises buy a lot of knowledge management tool. Um, when you go on your drive and you have all your documents, ideally, you could have an LLM running on top of that drive. You can ask any question, and it will read immediately, uh, thousands of document and answer, "What was our Q4 performance in sales? Um, it was X dollars." Uh, it finds it super quickly. In practice, because LLMs do not have a large enough context, you cannot use a standalone vanilla

  3. 12:0616:42

    Context windows & the “needle in a haystack” problem; is RAG future-proof?

    1. KK

      pre-trained LLM to solve that problem. You will have to augment it.Does that make sense? Uh, the other aspect around context windows is they are in fact limited. If you look at the context windows of the models from the last five years, um, even the best models today will range in context, um, window or number of tokens it can take as input, um, somewhere in the hundreds of thousands, um, of tokens max. Just to give you a sense, two hundred thousand tokens is roughly two books. Yeah. So that's how much you can upload, uh, and, and it can read pretty much. And you can imagine that when you're dealing with video understanding or, um, heavier, uh, data files, that is, of course, an issue. So you might have to chunk it, you might have to embed it, you might have to find other ways to get, uh, the LLM to handle larger contexts. Um, the attention mechanism is also, uh, powerful but problematic because it does not do a great job at attending in very large contexts. There is actually a, an interesting, uh, uh, problem called needle in a haystack. It's an AI problem where, um, or call it a benchmark, where, um, in order to test if your LLM is good at attending-- at putting attention on a very specific fact within a large, uh, corpus, researchers might randomly insert in a book one sentence that con-- uh, that, that outlines a certain fact, such as, uh, "Arun and Max are having coffee at Blue Bottle" in the middle of, uh, the Bible, let's say, or some very long, uh, text. Um, and then you ask the LLM, um, uh, "What were Arun and Max having, um, you know, uh, at Blue Bottle?" And you see if it remembers, say, it was coffee. It's actually a complex problem, not because the question is complex, but because you're asking the model to find a fact within a very large corpus, and that's complicated. Yeah. So again, this is a, a limiting factor for LLMs. We, we'll talk about RAG in a second, but I wanna preview, you know, the, the-- there is, uh, debates around whether RAG is the right, uh, long-term approach for AI systems. So as a, as a high-level idea, a RAG is a mechanism if you will, that embeds documents, uh, that an LLM can retrieve, um, and then add as context to, um, its, uh, initial prompt and answer a question. Um, it has lots of application. Knowledge management is an example. So imagine you have your drive again, but every document is sort of compressed in representation, and the LLM has access to that lower dimensional representation. Um, the debates that this tweet from Yaofu, um, outlines is, uh, in theory, if we have infinite compute, then RAG is useless because you can just read a massive corpus immediately and answer your question. Uh, but even in that case, um, latency might be an issue. Imagine the time it takes for an AI to read all your drive every single time you ask a question. It doesn't make sense. So, uh, RAG has other advantages beyond even, uh, the accuracy. On top of that, the sourcing matters as well. So it might-- RAG allows you to source. We, we'll talk, we'll talk about all that later. But there are-- there's always this, uh, debate in the, in the community whether a certain method is actually future-proof. Because in practice, as compute power doubles every year, let's say, some of the methods we're learning right now might not be relevant three years from now. Like, we don't know, essentially. Um, you know, and, and the analogy that, that he makes on, on, um, you know, context windows and why RAG approaches might be relevant even a long time from now, um, is search. You know, when you search on a search engine, you still find, uh, sources of information, and in fact, in the background, there is very, uh, uh, you know, detailed traversal algorithms that, uh, rank and find, uh, the specific links that might be the, the best to present you, um, uh, versus if you had to read-- imagine you had to read the entire web every single time you're doing a search query, uh, without being able to narrow to a certain portion of the space, uh, that might again not be, uh, um, uh, reasonable.

  4. 16:4218:12

    Two levers for better LLM apps: stronger foundation models vs better engineering

    1. KK

      Okay. When we're thinking of, um, improving LLMs, uh, the easiest way, uh, we think of it is, is two dimensions. One dimension is we are going to improve the foundation model itself. So for example, we move from, uh, GPT, uh, three point five Turbo to GPT-4 to GPT-4o to GPT-5. Each of that is supposed to improve the base model. GPT-5 is another debate because it's sort of packaging other models within itself. But, you know, if you're thinking about three point five, 4 and 4o, that's really what it is. The pre-trained model improves, and so you should see your, uh, performance improve on your tasks. Um, but the other dimension is we can actually engineer-- leverage the LLM in a way that makes it better. So you can prompt simply GPT-4o. You can, mm, change some prompts and improve the prompt, and it will improve the performance. It's shown. Uh, you can even put a RAG around it. You can put an agentic workflow around it. You can even put a multi-agent system around it, and that is another dimension for you to improve performance. So that's how I want you to think about it. Which LLM I'm using, and then how can I maximize the performance of that LLM? This lecture is about the vertical axis. Those are the methods that we will see with-- together. Sounds good for the introduction. So let's move to

  5. 18:1221:45

    Prompting matters: the BCG consultant study, “frontiers,” centaurs vs cyborgs

    1. KK

      prompt engineering. Um-I'm gonna start with an interesting study just to motivate why prompt engineering matters. Um, there is a, a study from, uh, you know, HBS, UPenn, um, uh, as well as Harvard Business School and, and, and others also involved, Wharton, that, uh, took a subset of BCG consultants, uh, individual contributors, split them into three groups. One group had no access to AI, one group had access to, um, I think it was GPT, uh, four, um, and then one group had access to the LLM, but also a training on how to prompt better. Um, and then they observed, uh, the performance of these consultants across a wide variety of tasks. There's a few things that they noticed that I thought was interesting. One is something they called the Jagd frontier, um, meaning that certain tasks that consultants are doing fall beyond the Jagd frontier, meaning AI is, uh, is not good enough. It's not, it's not improving, uh, human performance. In fact, it's actually making it worse. Um, and some tasks are within the frontier, um, meaning that, uh, AI is actually significantly improving the performance, the speed, the quality of the consultant. Um, many tasks fell within and many tasks fell without, and they shared their, um, insights. But the TLDR is, uh, there is a frontier within which AI is absolutely helping and, uh, one where they call out this behavior of falling asleep at the wheel, where people relied on AI on a task that was beyond the frontier, and in fact, uh, it ended up going worse because the human was not reviewing the outputs carefully enough. Um, they did note that the, the group that was trained was, uh, the best, uh, better than the group that was not trained on prompt engineering, which also motivates why this lecture matters, um, so that you're, you're, you're within that group afterwards. Uh, one other insights, um, were the centaurs and the cyborgs. Uh, they noticed that consultants had the tendency to work with AI in one of two ways, and you might yourself fi-- uh, find-- uh, be part of one of these groups. The centaurs, uh, are mythical creatures that are half, uh, human and half, uh, uh, I think half, uh, uh, uh, what, horses? Yeah, horses. Half horses, half something. Um, and, uh, those were individuals that would divide and delegate. They might give a pretty big task to the AI. So imagine you're working on a PowerPoint, which consultants are known to do. Um, you might actually write a very long prompt on how you want it to do your PowerPoint and then let it work for some time and then come back, and it's done. When others would act as cyborgs. Cyborgs are fully blended bionic, uh, human robots, a human robot and robot-- uh, augmented with robotic parts. Uh, and those individuals would not delegate fully a task. They would actually work super quickly with the model and, like, back and forth. I find that a lot of students are actually more working like cyborgs than, uh, centaurs. But, uh, while maybe in the enterprise, when you're trying to automate a workflow, you're thinking more like a centaur. Yeah. That's just something good to keep in mind. Also, a lot of companies will tell you, "Oh, we're hiring prompt engineers, et cetera. It's a career." I, I don't buy that. I think it's just a skill that everybody should have. Uh, you're not gonna make a career out of prompt engineering, but you're probably gonna use it as a very powerful skill

  6. 21:4527:35

    Core prompt design principles: specificity, role prompting, reflection, and step-by-step thinking

    1. KK

      in your career. Um, so let's talk about basic prompt design principles. Uh, I'm giving you a very simple prompt here. Uh, summarize this document, and then the document is uploaded alongside it, and the model has not, um, much context around, you know, what should be the summary? Well, how long should be the summary? What should it talk about? Et cetera. You can actually improve these prompts, um, by, by doing, you know, something like summarize this ten-page scientific paper on renewable energy in five bullet points, focusing on key findings and implications for policymakers. That's already better, right? You're sharing the audience, and it's going to tailor it to the audience. You're saying that, uh, you want five bullet points, and you want to focus only on key findings. Um, you know, that's a better prompt, you would argue. Um, how could you even make these prompts, uh, better? Uh, what are other techniques that you've heard of or tried yourself that could make this one-shot prompt, uh, uh, better? Yeah.

    2. SP

      Write formulas, uh, like write the example.

    3. KK

      Okay, write, write example. So say, uh, you mean, uh, here is an example of a great summary. Yeah, you're right. That's a good idea.

    4. SP

      Just ask it to be like someone. Act like you are now.

    5. KK

      Okay. Very popular technique. Act like a renewable energy expert giving a conference at, uh, Davos, let's say. Yeah, that's great. Um, someone where-

    6. SP

      It sounds cliche saying it, but just say like, "You're really good at it." Like-

    7. KK

      Yeah. You are the best in the world at this. Explain. [laughs] Yeah, yeah, actually, I mean, these things work. It's, it's funny, but, uh, it does work to, to say, act like XYZ. It's a very popular, uh, prompt template. We'll, we'll see a few examples. What else could you do? Yes.

    8. SP

      I personally like to say critique your own project.

    9. KK

      Okay.

    10. SP

      Yeah.

    11. KK

      Critique your own project, so you're using reflection. So you might actually do one output and then ask it to critique it and then give it back. Yeah, we'll see that. That's a great one. That's, that's the one that probably works best within those typically, but we, we'll see some examples. What else? Uh, yeah.

    12. SP

      Break the task down into steps.

    13. KK

      Okay, break the task down into steps. Do you know how that is called?

    14. SP

      No.

    15. KK

      Okay. Chain of thoughts. So, um, this is actually a popular method that's been shown in, in research that-It improves. You could actually give a clear instruction and also encourage the model to think step by step. Approach the task step by step and do not skip any step. And then you give it some steps such as step one, identify the three most important findings. Step two, explain how key each finding impacts renewable energy policy. Step three, write the five bullet summary with each point addressing a finding, um, et cetera. So, uh, chain of thoughts, I linked the paper from twenty twenty-three, uh, that popularized chain of thoughts. Chain of thoughts is very, very popular right now, especially in AI startups that are trying to control their LLMs. Okay. Um, to go back to your examples about act like XYZ, um, I-- what I like to do, Andrew Ng also talks about that, uh, is to look at other people's prompts. And in fact, in, in online, you have a lot of prompt repositories for free on GitHub. In fact, I, I linked the awesome prompt, uh, template rep-repo on GitHub, where you have so many examples of great prompt that engineers have built. They said it works great for us, and they published it online. And a lot of them starts with act as. You know, act as a Linux terminal, act as an English translator, act like, um, a position interviewer, et cetera. The advantage of a prompt template is that you can actually put it in your code and scale it for many user requests. So let me give you an example from Workera. Um, you know, Workera evaluates skills. Some of you have taken the assessments already and, um, tries to personalize it to the user. Um, and in fact, if you actually read in an HR system in an enterprise, in the HR system, you might have, uh, Jane, uh, is a product manager, level three, and she is, uh, in the US, and her preferred language is English. And actually that metadata can be inserted in a prompt template that we personalize for Jane. And similarly for Joe, whose favorite language is-- preferred language is Spanish, it will, uh, uh, it will tailor it to Joe, and that's called a prompt template. Yeah.

    16. SP

      Usually foundation models, they don't use prompt templates. That's something you have to, um, integrate yourself.

    17. KK

      So, uh, the f-question is, do the foundation models use a prompt templates, or do you have to integrate it yourself? So the foundation models probably use a system prompt that you don't see. Like when actually you type on ChatGPT, it is possible, it's not public, that OpenAI behind the scene has like, "Act like a very helpful assistant for this user, and by the way, here is your memories about your-- the, the user that we kept in our database. Uh, you can actually check your memories." And then your prompt goes under, and then the generation starts. So probably they're using something like that, but it doesn't mean you can't, um, add one yourself. So in fact, if y- if you think about a prompt template for, for the Workera example I was showing, maybe it starts when you call, uh, OpenAI by act like a helpful assistant, and then underneath it's like, act like a great, uh, AI mentor that helps people in their career. And OpenAI's prompt template also has follow the instruction from

  7. 27:3531:58

    Zero-shot vs few-shot prompting: aligning subjective tasks with examples

    1. KK

      the creator or something like that. You know, it's possible. Yeah. Uh, questions about prompt templates? Again, I would encourage you to go and read examples of prompts. Some of them are quite thoughtful. Um, let's talk about zero-shot versus few-shot prompting. It came up earlier. Uh, here's an example. Again, going back to the categorization of, uh, product reviews. Let's say that we're working on a task where the prompt is classify the tone of the sentence as positive, negative or neutral, and the, the-- and then you paste the review, which is, "The product is fine, but I was expecting more." If I were to survey the room, I would bet that some of you would say it's negative, some of you would say it's neutral because you actually have a first part that is relatively positive. It's fine. Uh, and then the second part, I was expecting more, which is relatively negative. So where do you land? Uh, this can be a subjective question, and maybe in one industry, this would be considered amazing, and another one, it would be considered really bad because people are used to really flourishing reviews. And so the way you can actually align the model to your task is by converting that zero-shot prompt. Zero-shot refers to the fact that it's not being given any example, uh, into a few short prompts where the model is given in the prompt a set of examples to align it to what you want it to do. So the example here is you, you-- again, you paste the same prompt as before with the user review, and then you add, "Here are examples of tone classifications. This exceeded my expectation completely. Positive. It's okay, but I wish it had more features. Negative. The service was adequate. Neither good nor bad. Uh, neutral." Now classify the tone of this sentence, um, you know, after you've heard about these things, and the model then says negative. And the reason it says negative, of course, is likely, um, because of the second example, which was, "It's okay, but I wish it had more features," which we told the model that was negative. Because the model saw that, it's aligned now with your expectations. Few-shot prompts are very popular. Um, and in fact, for AI startups that are slightly more sophisticated, you might see them, uh, keep a prompt up to date whenever the-- a user says something, and, uh, they might have a human label it and then add it as a few shots in their relevant prompt in their code base. Um, you can think of that as almost building a data set, but instead of actually building a separate data set like we've seen with supervised fine-tuning and then train-- fine-tuning the model on it, you're just putting it directly in the prompt. It turns out it's probably faster to do that if you wanna experiment quickly because you don't touch the model parameters, you just update your prompts. And you know, if it's text examples, you can actually, you know, concatenate so many examples, uh, in a single prompt. At some point it will be too long, and you will not have the necessary context window, but it's a pretty strong approach that is quick, uh, to align an LLM.Okay. Yes.

    2. SP

      Is there any, like, research on how, how long a prompt can be until it starts impairing its effect by-

    3. KK

      So question was, is there any research on how long the prompt can be before the model essentially loses itself or doesn't follow instructions anymore? There is. Uh, the problem is that research is outdated every few months, uh, because models get better. Um, and so I, I don't know where the state of the art is. You can probably find it online on benchmarks on, like, we see that... I, I, I give an example. Uh, on the Workera product, you have, um, a voice conversation for some of you that have tried it, where you-- you're asked, like, explain what is a prompt, and then you explain it, and then there's a scoring algorithm in the end. We know that after eight turns, the model loses itself. After eight turns, because you always paste the previous, uh, user response, it just starts going wild. And so the techniques we use in the background is we actually create chapters of the conversation. Maybe one chapter is the first eight prompt, and then you actually start over from another prompt. You, you can summarize the first part of the conversation, insert the summary,

  8. 31:5837:44

    Chaining prompts (not chain-of-thought): modular workflows for control and debugging

    1. KK

      and then keep going. You know, those are engineering hacks that engineers might have figured out in the background. Yeah. Because, yeah, eight turns makes a prompt quite long, actually. Uh, let's move on to chaining. Uh, chaining is the most popular technique out of everything we've seen so far in, uh, uh, in prompt engineering. Uh, it's not chain of thought. So chain of thought we've seen is think step-by-step, step one, step two, step three, do not skip any step. This is different. This is chaining complex prompt to improve performance, and this is what it looks like. Um, you take a single step prompt, such as, "Read this customer review and write a professional response that acknowledges their concern, explains the issue, offers a resolution," and then you paste the customer review, which is, "I ordered a laptop, it arrived three days late, the packaging was damaged. Very disappointing. I needed that urgently for work." And then the output is an email that is immediately given to you by the LLM after it reads the prompt. Um, so this might work, but it might be hard to control, you know. 'Cause think about it, there's multiple steps that you have listed, and everything is embedded in the same prompt. And if you wanted to debug step-by-step and know which step is weaker, you couldn't. You would have everything mixed together. So one advantage of chaining is, you know, you would, you would separate the prompts so that you can debug them separately, and it will also lead to, um, an easier manner to improve your workflow. Um, let's say a first prompt is extract the key issues. Identify the key concerns mentioned in this customer review. Paste the customer review. Second prompt, using these issues, so you paste back the issues, draft an outline for a professional response that acknowledges concerns, explains possible reasons, and offer a resolution. So this is not, you know, uh, uh, a prompt number three, write the full response. So using the outline, um, uh, write the professional response. And then you get your final output. So in theory, you can tell me, "Oh, the second approach is better than the first one at first." But what you can notice is that we can actually test those three prompts separately from each other and determine if we will get the most gains out of, uh, engineering the first prompt, optimizing it, or the second one or the third one. We now have three prompts that are independent from each other. And, you know, maybe if, uh, the outline was better, um, the performance of, uh, the email, the email, how much it will-- or the open rate will be or the user satisfaction on the response will actually get higher, you know. And so chaining improves performance, but most importantly helps you control your workflow and debug it more seamlessly. Yes.

    2. SP

      So if we know that the three prompt independently work very well, if we combine them into one prompt and we highlight that step-by-step thinking process, do we-- does on average, we get the same point out or do we still have to do that breakdown with the prompt?

    3. KK

      So let me try to rephrase. You say, let's say we look at the first prompt, which has, uh, all three tasks built in that prompt. Um, what, what exactly do you mean? You mean like if we evaluate the output and we measure some user insight, satisfaction, et cetera, um, why don't we just modify that prompt and essentially see how it improves user satisfaction?

    4. SP

      Yeah. Instead of doing a three-step process where we prompt again.

    5. KK

      I see, I see. Why do we need the three steps?

    6. SP

      Yeah.

    7. KK

      Yeah. I mean, think about it. The intermediate output is what you wanna see. Like, if I'm debugging the first, um, uh, approach, uh, the way I would do it is I would capture user insights. Like, here's the email. How good was the response? Thumbs up, thumbs down. Um, was your issue, issue resolved? Uh, thumbs up, thumbs down. Those would tell me how good is my prompt. And I can engineer that prompt, optimize it, and I would probably drive some gains. Um, but I will not be able easily to trace back to what the problem was. While in the second approach, not only I can use the end-to-end metrics to improve my process, I can also use the intermediate steps. For example, if I look at prompt two and I look at the outline and I see the outline is actually meh, it's not great, then I think I can get a lot of gains out of the outlineUm, or the outline is actually really good, but the last prompt doesn't do a good job at translating it into an email. So the outline is exactly what I want the, the LLM to do, but the, the translation in a customer-facing email is not good. In fact, it doesn't follow our vocabulary intern-internally. Then I know the third prompt is where I would get the most gains. So that-that's what it allows me to do, have intermediate steps to review. Yeah.

    8. SP

      Are there any latency concerns with this, uh, long chain?

    9. KK

      We'll talk about it. Are there any latency concerns? Yes. Um, in certain applications, um, you don't wanna use a chain, or you don't wanna use a long chain because it, uh, adds latency. We'll talk about that later. Good point. Uh, so practically, this is what, uh, chaining complex prompts look like. You have your first prompt with your first task. It outputs. The output is, is pasted in the second prompt with the second task being defined. The output is then pasted into the third prompt with the third

  9. 37:4441:19

    Evaluating prompts at scale: human review, tooling, and LLM-as-judge rubrics

    1. KK

      task being defined, and so on. That's what it looks like in practice. Super. Uh, we'll talk more later about testing your prompts, but there are methods now to do it, and we, we'll see later in this lecture with our case study how, uh, we can test our prompts. Uh, but h-h-here is an example of how you, you might do it. Um, you, you might have a, a summarization workflow, you know, prompt, um, that is the baseline. It's a single, uh, prompt. You might have a refined summarization, which is a modified prompt of this or a workflow with a chain, you know. Um, and then you have your test case, which is, uh, the input that you want to summarize, let's say. And then you have the generated output, and you can have humans go and rate these outputs, and you would notice, uh, that the baseline is better or worse than the refined prompt. Of course, this manual approach takes time, um, but it's a good way to start. And usually the advice is get hands-on at the beginning because you would quickly notice some issues, and it will give you better intuition on what tweaks can lead to better performance. However, if you wanted to scale that system across many products, many parts of your code base, uh, you might wanna find a way to do that automatically without asking humans to review and grade summaries, right? Um, one approach is to, um, use, you know, platforms like, you know, at Workera we-- our team uses a platform called PromptFu that allows you to actually automate part of this testing. Um, in a nutshell, what it does is it can allow you to run the same prompt with five different LLMs immediately, put everything in a table that makes it super easy for a human to grade, let's say. Or alternatively, it might, uh, allow you to defane-- uh, define LLM judges. LLM judges can come in different flavors. Uh, for example, I can have an LLM judge that does a pairwise comparison. So what the LLM is asked to do is, "Here are two summaries. Just tell me which one is better than the other one." Um, that's what the LLM does, and that can be used as a proxy for how good the summarization baseline versus the refined version is. Another way to do an LLM, uh, judge is if you do it for a single answer grading. So here's a summary, rate it from one to five, you know. And then you can go even deep-deeper and do a, a reference-guided pairwise comparison. Or you add also a rubric. You say a five is when a summary is below a hundred characters. I'm just making up. Below a hundred characters, mentions at least three key points that are distinct, and starts with a first sentence that displays the overview and then goes into detail. That's a great summary, number-- five out of five. Zero is the LLM failed to summarize and actually was very verbose, let's say. And so you put a rubric behind it, and you have an LLM as judge finding the rubric. Of course, you can now pair different techniques. You can do a few shot for the rubric. You can actually give examples of a num-- five out of fives, four out of fours, three out of threes, because now you know multiple techniques. Okay? Does that make sense? Yeah. Okay. So that was the second section on prompt engineering, uh, or the first line of optimization.

  10. 41:1944:52

    Fine-tuning: when it helps, why to avoid it, and a cautionary Slack example

    1. KK

      Now, let's say you've exhausted all your chances for prompt engineering, and you're thinking about actually touching the model, modifying its weights, uh, or fine-tuning it, in other words. Um, I was telling you I'm not a, a fan of fine-tuning. There's a few reasons why. Um, one, it requires substantial labeled data typically to fine-tune. Although now there are approaches that are getting better at fine-tuning that look more like few-shot prompting actually than fine-tuning. It's sort of merging, uh, although one modifies the weight, the other doesn't modify the weights. Um, fine-tune models may also overfit to specific data. We're gonna see a funny example, actually. Um, losing, uh, their general purpose utility. So you might fine-tune a model, and actually, when someone asks a pretty generic question, it doesn't do well anymore. You know, it might do well on your task. So it might be relevant or not. And then it's, it's time and cost-intensive. That's my main problem. And, uh, you know, at, at, at Workera, we, we don't, we don't-- we steer away from fine-tuning as much as possible, uh, because by the time you're done fine-tuning your model, the next model is out, and it's actually beating your fine-tuned version of the previous model. So I would steer away from fine-tuning as much as you can. The advantage of the prompt engineering methods we've seen is you can put the next best pre-trained model directly in your code. It will update everything immediately. Fine-tuning doesn't work like that.There are advantages, though, where it still makes sense if the task requires repeated high-precision outputs, such as legal, scientific explanation, and if the general-purpose LLM struggles with domain-specific language. So, uh, let's look at a quick example together, um, which is an example, uh, from Ross Lazarovits, um, I think it was a couple of years ago, September twenty-three, where, um, uh, Ross, uh, tried to do Slack fine-tuning. So he looked at a lot of Slack messages within his company, and he was like, "I'm gonna fine-tune a model that speaks like us or operates like us because this is how we work, right? This is the data that represents how people work at the company." Um, and so if he, he actually went ahead and fine-tuned the model, um, gave it a prompt like, "Hey, write a..." You know, he was delegating to the model, "Write a five hundred-word blog post on prompt engineering." And the model responded, "I shall work on that in the morning." Um, and, and then he tries to push the model a little further and say, "It's morning now." Um, and the model said, "I'm writing right now. It's six thirty AM here." Uh, "Write it now." "Okay." "Please." [laughs] "Okay, I shall write it now. I actually don't know what you would like me to say about prompt engineering. I can only describe the process. The only thing that comes to mind for a headline is how do we build prompts?" You know, it, it's kind of a funny, um, example for fine-tuning because it's true that it went wrong. Like, he was supposed to think like, "I want the model to speak like us at work," and it ended up acting like people and not actually following instructions. So one example why I would steer away from fine-tuning. Super. Uh, let's talk about

  11. 44:5250:09

    RAG fundamentals: embeddings, vector databases, retrieval, grounding, and citations

    1. KK

      RAGs. Um, RAGs is important. It's important to know out there and at least having the basics. It's a very common interview question, by the way. If you go interview, uh, for a job, they might ask you to explain in a nutshell to a five-year-old what is a RAG. And hopefully after that, you'll be able to do it. Um, so, uh, we've seen some of the challenges with standalone LLMs. Those challenges include the context window being small, the fact that it's hard to remember details within a large context window, um, knowledge gaps, you know, uh, cutoff dates you mentioned earlier. The model might be trained up to a date, and then it cannot follow the trends or be up to date. Um, hallucinations. There are some fields, think about medical diagnosis, where hallucination are very costly. You can't afford a hallucination. You know, even in education, imagine deploying a model for the US youth education, and it hallucinates, and it teaches millions of people something completely wrong. It's a problem. Um, and then lack of sources. Uh, a lot of fields love sources. Research fields love sources. Education loves sources. Legal loves sources as well. And so, um, the pre-trained LLM doesn't do a good job to source. And in fact, if you, if you have tried to find sources on a plain LLM, it actually hallucinates a lot. It makes up research papers. It just lists like completely fake stuff. Um, so how do we solve that? Um, with a RAG. RAG integrates with external knowledge sources, databases, documents, APIs. Uh, it ensures that answers are more accurate, up-to-date, and grounded because you can actually update your document. Your, your drive is always up to date. I mean, ideally, you're always pushing new documents to it. And when you query, what is our Q4 performance in sales? Hopefully, there is the last board deck in, uh, the drive, and it can read the last board deck. You know. Um, and more developer control. We'll see why, um, RAGs allow for targeted customization without actually requiring the retraining of the model. In fact, you don't touch the model with RAGs. It's really a technique that is put on top of the model. So to see an example of a, a RAG, this is a question and s- answering, um, uh, application where we're in the medical field and a user is asking, uh, a query, "What are the side effects of drug X?" Um, this is an important question. You can't hallucinate. You need to source. You need to be up to date. Maybe there is a new, um, um, update to that drug that is now in the database and you need to read that, so you have to-- Like a RAG is a great example of what you would wanna use here. The, the way it works is you have your knowledge base of a bunch of documents. Um, what you do is you use, um, an embedding to embed those documents into lower dimensional representations. Uh, so for example, if the document is a PDF, uh, a long PDF, uh, you might, you know, read the PDF, understand it, and then embed it. We've seen plenty of embedding approaches together, triplet loss, et cetera, you remember. Um, so imagine one of them here for LLMs is embedding those documents into lower representation. Um, if the representation is too small, you will lose information. If it's too big, you will add latency, right? It's a trade-off. Um, you will store typically those representation into a database, um, called a vector database. There's a lot of vector database providers as-- uh, out there. Um, uh, you know, uh, c- I, I, I think I've listed a couple that are very common. No, I haven't listed, but I can, I can share afterwards. Um, a vector database is essentially storing those vector in a very efficient manner, allowing the fast retrieval, um, uh, with a certain distance metric. So, um, what you do is you also embed, usually with the same algorithm, the user prompts, and you run a retrieval process, which is essentially saying, um, based on the embedding from the user query and the vector database, find the relevant documents based on the distance between those embeddings.Once you've found the relevant documents, you pull them, and then you add them to the user query with a system prompt or a prompt template on top. So the prompt template can be, um, answer user query based on list of documents. If answer not in the document, say, "I don't know." That's your prompt template where the user query is pasted, the documents are pasted, and then your outputs, um, should be what you want because it's now grounded in the documents. You can also add to this prompt template, "Tell me the exact page, chapter, line of the document that was relevant, and in fact, link it as well," just to be more precise. Any question on RAGs? This is a simple vanilla RAG. Yeah. Yes.

  12. 50:0953:19

    RAG beyond vanilla: chunking for location-aware retrieval and HYDE for better matching

    1. SP

      Do the document embeddings still retain information about what's found on what page and what paragraph?

    2. KK

      Question is, do the document embeddings still retain the information of the location of the information within that document, especially in big documents? Um, great question. Um, we'll get to it in a, in a second, uh, because you're right that the vanilla RAG might not do a good job with very large documents. So let's say, uh, you know, when you open a medication box and you have this gigantic, uh, white paper with all the information and it's very long, uh, maybe a, a vanilla RAG would not cut it. So what people have figured out is a bunch of techniques to improve RAGs, and in fact, chunking is a great technique that is very popular. So you might actually store in the vector database the embedding of the full document, and on top of that, you will also store a chapter-level, uh, vector. You know, and when you retrieve, you retrieve the document, you retrieve the chapter, um, and that allows you to be more precise with the sourcing. It's one example. Um, another technique that's popular is HYDE, um, uh, hypothetical document embeddings, where a group of researchers, um, published a paper showing that when you get your user query, one of the main problem is the user query actually does not look like your documents. For example, the user query might be, "What are the side effects of drug X?" When actually in the document, in the vector database, the vectors represents very long documents. So how do you guarantee that the vector embedding is gonna be close to the document embedding? What they do is they use the user query to generate a fake hallucinated document. They embed that document, and then they compare it to the vector, uh, in the vector database. Does that make sense? So for example, the user says, "What is the side effect of drug X?" There's a prompt that this is given to another prompt that says, "Based on this user query, generate a five-page report answering the user query." It generates potentially a completely fake, um, uh, uh, answer. You embed that, and it will be closer to the document that you're looking for, likely. You know. It's one example of a, of a RAG approach. Again, the purpose of this lecture is not to go through all these tree and explain you every single methods that has been discovered, uh, for RAGs, but I just wanted to show you how much research has been done between twenty-twenty and twenty-twenty-five in RAGs and how many branches of research you, you now have that you can, uh, learn from. Uh, the survey paper is linked in the slides, by the way, and I'll share them after the lecture. Super. So, uh, we've made some progress. Hopefully, now you feel like if you were to start an LLM application, you know how to do better prompts, you know how to do chains, you know how to do fine-tuning, uh, you also know how to do retrieval.

  13. 53:191:03:56

    Agentic AI workflows: definition, examples, and the shift from deterministic to fuzzy software

    1. KK

      And you have the baggage of techniques that you can go and read and find the code base, pull the code, vibe code it, but you have the breadth now. Um, the next set of, uh, topics we're gonna see is around, uh, uh, the question of how could we extend the capabilities of LLMs from performing single tasks enhanced with external knowledge to handling multi-step autonomous workflows? You know, and this is where we get into proper, uh, agentic AI. So let's talk about agentic AI workflows towards autonomous and specialized systems. Then we'll talk about evals, then we'll see multi-agent systems, and we'll end with a, with a little, uh, thoughts on what's next in AI. So, um, Andrew Ng actually, um, coined the term, um, agentic AI workflows, um, and his reason was that a lot of companies use, uh, let's say agents. Agents. Agents everywhere. Agents everywhere. If you go and work at these companies, you would notice that, uh, they mean very different things by agents. Some people actually have a prompt, and they call it an agent. You know? Other people, they have a very complex multi-agent system, they call it an agent. And so calling everything an agent doesn't do it justice. So Andrew says, "Let's call these agentic workflows," because in practice, it's a bunch of prompts with tools, with additional resources, API calls that ultimately are put in a workflow, and you can call that workflow agentic. So it's all about the multi-step process, um, to complete a task. Also, calling it agentic workflow allows us to not mix it up with what I called, uh, agent, uh, the li-- the last lecture with reinforcement learning. 'Cause in RL, agent has a very specific definition, interacts with an environment, passes from one state to the other, has a reward and an observation. You remember that chart, right? So-So, um, here's an example of how we move from a one-step prompt to a, a multi-step agentic workflow. Um, let's say a user queries a, a, a product. What is your refund policy on a chatbot? Um, and the response using a RAG says, "Refunds are available within thirty days of purchase," and maybe the RAG can even look link to the policy documents. That's what we learned so far. Um, instead, an agentic workflow can function like this. The user says, "Can I get a refund for my order?" And the response via the agentic workflow is the agent retrieves the refund policy using a RAG. The agent then follows up with the users and says, "Can you provide your order number?" Um, then the agent queries an API to check the order details, and finally comes back to the user and confirms, "Your order qualifies for a refund. The amount will be processed in three to five business days." This is much more thoughtful than the first version, which is sort of vanilla, right? So that's what we're gonna talk about in the next couple of slides is how do we get from the first one to the second one. Um, there are plenty of specialized agentic workflows online. You know, you've heard, and if you hang out in SF, you probably see a bunch of billboards, uh, you know, AI software engineer, AI skills mentor you've interacted with in the class to Workera AI SDR, AI lawyers, AI, you know, specialized cloud engineer. Um, you know, it would be a stretch to say that everything works, but there's work being done towards that. You know. I'm not personally a fan of putting a face behind those things. I think it's gimmicky, and I think in a few years from now, actually, very few products will have a human face behind it, uh, but might be a marketing tactic from some startups. It's more scary than it is engaging, frankly. Um, okay, I wanna talk about the paradigm shift. Uh, it's especially useful, let's say you're a software engineer or you're planning to be a software engineer, because software engineering as a discipline is sort of shifting. Or at least the best engineers I've worked with are able to move from a deterministic mindset to a fuzzy mindset and balance between the two whenever they need to get something done. So here's the paradigm shift between traditional software and agentic AI software. Uh, the first one is, uh, the way you handle data. Traditional software deals with structured data. You have JSONs, you have databases. Uh, they're pasted, uh, in a very structured manner in a data engineering pipeline, and then they're used to be displayed on a certain interface. Uh, the user might fo-- fill a form that is then retrieved and pasted in the database. All of that historically has been structured data. Now, more and more companies are handling, uh, free-form text, images, um, and, and all of that requires dynamic interpretation, um, uh, to transform an input into an output. Um, the software itself used to be deterministic. Now you have a lot of software that is fuzzy, and fuzzy software creates so many issues. I mean, imagine if you let your user ask anything on your website. The chances that it breaks is tremendous. The chances that you're attacked is tremendous. The chances-- It's really, really complicated. It's more complicated than people make it seem, uh, on Twitter. Um, fuzzy engineering is truly hard. You know. You might get hate as a company because one user did something that you authorized them to do that ended up breaking the database and ended up, you know, we've seen that with many companies in the last couple of years. So it takes a very specialized engineering mindset to do fuzzy engineering, but also know when you need to be deterministic. Um, the other thing I'd call is with agentic AI software, um, you, you sort of wanna think about your software as like your manager. So y-you're familiar with the monolith or, or, um, um, you know, microservices approaches in software, you know, where you structure your software in different, you know, boxes that can talk to each other, and it allows teams to debug one section at a time, you know. Um, now the equivalent with agentic AI is you think as a manager. So you think, okay, if I was to delegate my product to be done by a group of humans, uh, what would be those roles? Would I have a graphic designer that then, you know, puts together a chart and then sends it to a marketing manager that converts it into a nice blog post that then gives it to the performance marketing expert, that then publishes the work, uh, the, the blog post and then optimizes an A/B test, then to a data scientist that analyzes the data and then s- puts hypothesis and validates them or invalidates them. That's how you typically think if you're building an agentic AI software. You know. When actually the equivalent of that in traditional software might be completely different. It might be we have a data engineer box right here that handles all our data engineering, and then here we have the UI/UX stuff. Everything UI/UX-related goes here and, you know, companies might structure it in very different ways. And here is the business logic that we wanna care about, and there's five engineers working on the business logic, let's say. Okay. Uh, testing and debugging is also very different, um, and we'll talk about it in the next section. Uh, the other thing that, uh, I feel matters is with AI in engineering, the cost of experimentation is going down drastically. And so people, I feel, should be more comfortable throwing away code. You know, it's, it's like in traditional software engineering, you probably don't throw away code a ton. You, you build a code and it's solid and it's bulletproof, and then you, you update it over time. When we've seen AI companies be more comfortable throwing away codes.You know, which has advantages in terms of the speed at which you move, but also disadvantages in terms of, uh, the quality of your software that it can break more. You know. Okay. So anyway, just wanted to do an aparté on the, the, the paradigm shift from deterministic to fuzzy engineering. Um, oh, and actually I can give you an example from, uh, from Workera that we learned, uh, probably over the last twelve months, is like, if you, if you've used Workera, you, you might have seen that the interface has, um, asks you sometimes multiple-choice questions, and sometimes it asks you multiple select, and sometimes it asks you drag and drop, ordering, matching, whatever, right? Those are example of deterministic item types. Meaning you answer the question. On a multiple choice, there is one correct answer. It's fully deterministic. On the other hand, you sometimes have, uh, voice questions, uh, where you go through a role play, or you have voice plus coding questions where your code is being read by the interface or whatever. Um, those are fuzzy, meaning the scoring algorithm might actually make mistakes, and those mistakes might be costly. And so companies have to figure out a human-in-the-loop system, um, which you might have seen with the appeal feature at the end. So at the end of the assessment, you have an appeal feature where it allows you to say, "I wanna appeal the agent because, uh, I wanna challenge what the agent said on my answer because I thought that was better than what the agent thought." And then you bring a human in the loop that then can fix the agent, can tell the agent, "Actually, you were too harsh, um, on the answer of this person." Um, and, you know, that's an example of a fuzzy engineered system that then adds a human in the loop to make it more aligned. And so if you're building a company, I would encourage you to think about, "What can I get done with determinism? And let's get that done." And then the fuzzy stuff, I want to do fuzzy because it allows more interaction, it allows more back and forth, but I need to put guardrails around it, and how am I gonna design those guardrails, pretty much. Okay. Um, here's another example, uh, from enterprise workflows, um, which are likely to change due to agentic

  14. 1:03:561:06:59

    Enterprise workflow redesign example: credit risk memos and adoption realities

    1. KK

      AI. Um, this is a paper from McKinsey, uh, I believe from last year, where, uh, they looked at a financial institution, and they said that, y-you know, "We observed that they often spend one to four weeks to create a credit risk memo," and here's the process. A relationship manager, um, gathers data from fifteen and more than fifteen sources on the borrower, loan type, other factors. Um, then the relationship manager and the credit analyst collaboratively analyze that data from these sources. Then the credit analyst typically spends, um, you know, twenty more-- twenty hours or more writing a memo and then goes back to the relationship manager. They give feedback, and then they go through this loop again and again. And, uh, it takes a long time to get a credit memo out. They then run a, a research study where, uh, they changed the process. They said gen AI agents could actually cut time, um, by twenty to sixty percent on credit risk memos. And the process has changed to the relationship manager directly work with the gen AI agent system, provides relevant materials that needs to produce the memo. The agent subdivides the project into tasks that are assigned to specialist agents, gathers and analyzes the data from multiple sources, drafts a memo. Then the relationship manager and the credit analyst sit down together, review the memo, give feedback to the agent, and within, you know, twenty to sixty percent less time are done. And so this is an example where you're actually not changing the human stakeholders. You're just changing the process and adding gen AI to, uh, reduce the time it takes to get a credit memo out. It turns out that, um, uh, imagine you're an enterprise and you have, uh, you know, a hundred thousand employees, and there's a lot of enterprises with a hundred thousand employees out there. Uh, you are currently under crisis in terms of redesigning your workflows. You, um, you are-- You know, it turns out that if you actually pool the job descriptions from the HR system and you interpret them, you also pool the business process workflows that you have encoded in your drive, you actually can find gains in multiple places. And, uh, in the next few years, you're probably gonna see workflows being more optimized to add gen AI. Um, even if that happens, the hardest part is changing people. What we know this is, this is great in theory, but now let's try to fit that second workflow for ten thousand credits, uh, risk analysts and, uh, relationship managers. My guess is it will take years. It will take ten, twenty years to get to this being actually done at scale within an organization, uh, because change is so hard. You know, so hard to rewire business workflows, job descriptions, incentivize people to do different and be different and train them. And so, so, you know, this is what the world is going towards, but it's gonna take a long time, I think. Um,

  15. 1:06:591:19:13

    Inside an agent: memory tiers, tools/APIs, autonomy levels, and MCP for scalable tool access

    1. KK

      okay. Then I wanna talk about how the agent actually works and what are the cor-core components of an agent. Uh, imagine, um, a travel booking AI agent. That's an easy example you've all thought about. I still haven't been able to get an agent to book a trip for me or, or I was scared because it was gonna book a, a very expensive or long trip. But in theory, um, uh, you, you can, you can have a travel booking agent that has prompts. So the prompts we've seen, we know the methods to optimize those prompts. That travel agent also has a content managemen-- context management system, which is essentially the memory of what it knows about the user. Uh, that context management system might include a core memory or working memory and an archival memory, okay?What the difference is, um, within memory, um, is not every memory needs to be fast to access. Like, think about it. You, you're onboarded on a product, and the first question is, "Hi, what's your name?" And I say, "My name is Kian." That's probably gonna sit in the working memory because the agent, every time he's gonna talk to me, he's gonna wanna use my name, right? But then maybe the second question is, "Kian, what's your birthday?" And I give it my birthday. Does it need my birthday every day? Probably not. So it's probably gonna park it on the long-term memory or the archival memory, and those memories are slower to access. They're farther down the stack. And, you know, that structure allows the agent to determine what's the working memory and what's the long-term memory, you know. And that makes it easier for the agent to retrieve super fast. 'Cause think about it. When you interact with ChatGPT, you feel that it's very personal at times, right? You feel like it understands you. Um, imagine every time you call it, it has to read the memories, right? And that can be costly. It's like a very-- it's a very burdensome cost because it happens every time y-you, you talk to it. So you want to be highly optimized with the working memory. You know, if it takes three seconds to look in the memory, every time you're gonna talk to your LLM, it's gonna take three seconds, which you don't want. So anyway. And then you have the tools. The tools can include, uh, APIs, like a flight search API, hotel booking API, car rental API, weather API, and then the payment processing API. And typically, you would want to tell your agent how that API works. It turns out that agents, um, or LLMs, I should say, are very good at reading API documentation. So you give it the API documentation, and it reads the JSON, and it reads what does a GET request look like, and this is the format that I need to push, and then it pushes it in that format, let's say, and then it retrieves something. Does that make sense, those different components? Uh, you know, Anthropic also talks about resources. Resources is data that is sitting somewhere that you might let your agent read. For example, if you're building your startups, you have a CRM. A CRM has data in it, and you wanna do lookups in that data. You will probably give a lookup tool, and you will give access to the resource, and it will do lookups whenever you want super fast. So. Uh, this type of architecture can be built with different degrees of autonomy, from the least autonomous to the most autonomous, and I'll give you a few examples. Uh, less autonomous would be you've hard-coded the steps. So let's say I tell the travel agent, um, first identify the intent, then, um, look up in the database the history of this customer with us and their preferences, then go to the flight API, blah, blah, blah, then go to the-- I would hard-code the steps. Okay? That's the least autonomous. Uh, the semi-autonomous is I might hard-code the tools, but I'm not gonna hard-code the steps. So I'm gonna tell the agent, um, "You're-- Act like a travel agent, and, um, and, uh, you-- your task is to help the person book a travel, and these are the tools that you have accessible to yourself." And so I'm not hard-coding the steps, I'm just hard-coding the tools that you have access to your-- for yourself. Uh, the more autonomous is the agent decides the steps and can create the tools. So that's where you might give actually access to a code editor to the agent, and the agent might actually be able to ping any API in the web, perform some web search. It might even be able to create some code to display data to the user. It might even be able to perform some calculations like, "Oh, I'm gonna calculate the fastest route to get from San Francisco to New York, um, and which one might be the most appropriate for what the user is looking for. And then I wanna calculate the distance between the airport and that hotel versus that hotel, and I'm gonna write code to do that." So it's actually fully autonomous from that perspective. Okay? So yeah, remember those keywords: memory, uh, prompts, tools, et cetera. Uh, now, I presented the flights API, but it does not have to be an API. Uh, you probably have heard the term MCP or Model Context Protocol. That was coined by Anthropic. I, I pasted the seminal article on MCP at the bottom of this slide. But let me explain in a nutshell why those things would differ. Um, uh, in, in the API case, um, you would actually, uh, teach your LLM to ping an API. So you would say, "This is how you ping this API, and this is the data that it will send you back." And, um, you would have to do that in a one-off manner. So you would have to build or sort of give the API documentation of your flight API, um, your booking hotel API, your car rental API, and then you would give tools for your model to communicate with those APIs. Um, it doesn't scale very well, um, you know, versus MCP. MCP, um, it's really about, you know, putting a system in the middle, sort of, that would make it simpler for your LLM to communicate with that endpoint. So for instance, um, you might, you know, have an MCP server, an MCP client, where you're trying to communicate with that travel, uh, database or the flight API or MCP, and, uh, your agent might actually just communicate with it and say, "Hey, uh, what do you need in order to give me more flight information?" And that, that agent will respond by, "I would like you to tell me where is the origin flight, where is the destination, and what you're looking for at a high level. This is my requirement." "Okay, let me get back to you with my requirement."Oh, you forgot to tell me your budget, whatever. Oh, let me give you my budget, et cetera. Um, and, uh, uh, it's, it's, it's agent-to-agent communication, which allows, uh, more scalability. You don't need to hard code everything. Companies have displayed their MCPs out there, and you can, uh, your agent can communicate with them and figure out how to, uh, get the data it needs. Does that make sense? Yeah.

    2. SP

      Isn't this just shifting-

    3. KK

      Oh, sorry.

    4. SP

      -the question of like rewriting any exact call to this? So you might have suffered minor changes in the API. Rather than your agent needing to rewrite that, the MCP now does.

    5. KK

      Right. Yes.

    6. SP

      So you have an is-is this not a shifting issue?

    7. KK

      Uh, I think it, it is ultimately. Uh, and the question is, is it a shifting issue? Because anyway, if an API has to be updated, the MCP has to be updated, is what you're saying, right? Yes. That, that's correct. But at least, um, it allows the agent to sort of go back and forth and figure out what the requirements are. But at the end of the day, ideally, if you're a startup, you have some documentation, and automatically you have an agent or a, an LLM workflow that reads that documentation and updates the code accordingly, you know. But I agree, it's not, it's not something that is fully autonomous. No. Uh, yeah.

    8. SP

      I've seen that there's been some security issues. Why is that a possible value?

    9. KK

      Which security specifically? Yeah.

    10. SP

      Uh, your focus group.

    11. KK

      Yeah. So are there security issues with MCPs? Uh, so think about it this way. It, it, uh, uh, MCPs, depending on the data that you get access to, might have different requirements, lower stake or higher stake. I'm not an expert at, you know, the full range, but it wouldn't surprise me that, um, uh, you know, when you, when you, when you expose an MCP to an A... I think you would-- A lot of MCPs have authentication. So, you know, you might actually need a code to actually talk to it, just like you would with an API, uh, or a key. Um, yeah. But that's a good question. I'm, you know, I'm not an expert at the security of these systems, but, uh, you know, we can look into it. Uh, any other questions on what we've seen with the agentic workflows, APIs, tools, MCPs, memory? All of that is under progress. So even memory is not a solved problem by any means. It's pretty hard, actually. Again. Yes.

    12. SP

      You don't need an, um, MCP to MCP communication, right? You can have an MC-- The MCP just makes it easier to access the API, but technically you could just probably engineer, uh, your way to retrieve something from the API. You could do that the same way, it's just computationally more intense, right? Like that's-- The whole idea is just to make it more efficient.

    13. KK

      Yeah.

    14. SP

      Not necessarily access.

    15. KK

      Exactly. Exactly. Yeah. Is, is MCP about efficiency or accessing more data? It's about efficiency. It's like, you know, let's say you have a coding agent, um, and, you know, it has an MCP clients, and there's multiple MCP servers that are exposed out there. Um, that agent can communicate very efficiently with them and find what it needs. Um, uh, and it's, it's a more efficient process than actually, uh, displaying APIs and the APIs on that side and how to ping them and what the protocol, you know. But, you know, it's not about the data that is being exposed, because ultimately you control the data that is being exposed. You probably, you know, de-- depending on how the MCP is built, my guess is you probably expose yourself to other risks because your, uh, your MCP server can, can see any input pretty much from another LLM, and so it has to be robust. Um, but yeah. Super. Uh, so let, let's look at an example of a step-by-step, uh, uh, uh, workflow for the travel agent. So let's say the user says, "I wanna plan a, plan a trip, um, to Paris from December fifteenth to twentieth, um, with flights, hotels near the Eiffel Tower, and then an itinerary of must-visit places." That's the task to the travel agent. Step two, the agent plans the steps. So it says, "I'm gonna find flights. Use the flight search API, uh, to get option for December fifteenth. Search hotels. Generate recommendation for places to visit. Validate preferences, um, budget, et cetera. Book the trip with the payment processing API." Step three-- That's just the planning, by the way. Step three, execute the plan. Use your tools, combine the results, and then proactive user interaction and booking. It might make a first proposal to the user and ask the user to validate or invalidate, and then may repeat, uh, that planning and execution process. And then finally, it might actually update the memory. It might say, "Oh, I just learned through this interaction that the user only likes direct flights. Next time I-I'll, I'll only give direct flights." Or, "I noticed users are fine with three-star hotels or four-star hotels, and in fact, they're-- they don't wanna go above budget," or something like that. Um, so that hopefully makes sense by now on, you know, how you might do that. My question for you is,

  16. 1:19:131:34:23

    How to know an agent works: eval strategies + customer support case study

    1. KK

      uh, how would you know if this works? And if you had such a system running in production, how would you improve it? Yeah.

    2. SP

      Let users rate their experience.

    3. KK

      So that's an example. So let users rate their experience at the end. Uh, that would be an end-to-end test, right? You're looking at the user experience through the steps and say, how good was it from one to five, let's say. Yeah, it's a good way. And then if you learn that a user says one, what-- how would you improve the, the workflow?

    4. SP

      Often saying a couple of precise

    5. KK

      Okay, so you would go down a tree and say, "Okay, you said one, uh, what, what was your issue?" And then the user says, uh, "The prices were too high," let's say. And then you would go back and fix that specific, uh, uh, tool or prompt or... Yeah. Okay. Any other ideas?

    6. SP

      If there's a number two deterministic, the question you have kind of always helps now. Evaluation or, or is just that it's really spotty. You kind of-

    7. KK

      Yeah. Good. So that's a good insight. Separate the LLM-related stuff from the non-LLM-related stuff, the deterministic stuff. The deterministic stuff, you might be able to fix it, uh, you know, more objectively, essentially. Yeah. There was... What else? So give me an example of an objective issue that you can notice and how you would fix it versus a subjective issue. Yeah.

    8. SP

      Objectively, the flights, there's like a weird flight which is cheaper. There's, uh, although it would be like around here, it's more expensive. That's objective.

    9. KK

      Okay. So let's say you say there's the same flight, but one is cheaper than the other, let's say. It's objectively worse. And so you can capture that almost automatically. Yeah. So you could actually build evals that are objective, that are tracked across your users, and you might actually run an analysis after and see that for the objective stuff, we notice that our LLM AI, agentic AI workflow is bad with pricing. It just doesn't read prices well because it always gives a more expensive option. Yeah, you're perfectly right. How about the subjective stuff? Yeah.

    10. SP

      Like do you choose a direct or indirect flight if the indirect is a little bit cheaper?

    11. KK

      Yeah. Good one. Do you, do you choose a direct flight or an indirect flight if the indirect is cheaper, but the direct is more comfortable? Um, yeah, that's a good one actually. Um, so how would you capture that information? Let's say this is used by thousands of users.

    12. SP

      Um, could you feed something in about the user preferences?

    13. KK

      Uh, could you feed something in? Yeah. I mean, you could, you could, um, could you feed something in, uh, about the user preferences? Well, you could, you could build a dataset that has some of that information. So you build ten prompts where the user is asking specifically for a direct-- is saying that I prefer direct flights because I care about my time, let's say. And then you look at the output, and you actually give a good-- the example of a good output, and you probably are able to capture the performance of your agentic workflow on this specific eval. Whether does it prioritize? Does it understand price-conscious? Is it price-conscious, essentially, and comfort-conscious? Yeah. What about the tone? Let's say, let's say the LLM right now is not very friendly. How would you notice that, and how would you fix it? Yeah.

    14. SP

      Have a test user and so, like, run prompts and see if there's something wrong with that.

    15. KK

      Okay. Have a test user run the prompt and see if there's something wrong with that. Tell me about the last step. How would you notice that something is wrong?

    16. SP

      So have, uh, a couple of tests, like probably a, uh, another LLM judges that would, uh, evaluate the response-

    17. KK

      Yeah.

    18. SP

      -and see if it's, like, satisfying.

    19. KK

      Yeah. I agree with your approach. Have LLM judges that evaluate the response against a certain rubric of what politeness looks like. So here in this case, you could actually start, uh, with error analysis. So you start, you, you have a thousand users, and, you know, you can pull up twenty user interaction and read through it. And you might notice at first sight, the LLM seems to be very rude. You know, it's just super, super short in its answers, and it's not very helpful. Um, you notice that with your error analysis manually. Then you go to the next stage. You actually put evals behind it. You say, "I'm gonna create a set of, um, a set of, uh, LLM judges that are gonna look at the user interaction and are gonna rate how polite it is, and I'm gonna give it a rubric." Then what I'm gonna do is I'm gonna flip my LLM. Instead of using GPT-4, I'm gonna use Groq. And instead of using Groq, I'm gonna use Llama. And then I'm gonna run those three LLMs side by side, give it to my LLM judges, and then get my subjective score at the end to say, "Oh, uh, X model was more polite on average." Yeah, perfectly right. That's an example of an eval that is very specific and allows you to choose between LLMs. You could actually do the same eval, not across LLMs, but fix the LLM, change the prompt. You actually, instead of saying, "Act like a travel agent," you say, "Act like a helpful travel agent." And then you see the influence of that word on your eval with the LLM as judges. Does that make sense? Okay. Uh, super. So let's, let's move forward and do a case study with evals, and then we're, we're almost done, um, for today. Uh, let's say your product managers-- uh, manager asks you to build an AI agent for customer support. Okay? Where do you start? And here is an example of the user prompt. "I need to change my shipping address for order," blah, blah, blah. "I moved to a new address." So wh-what do you start if I'm giving you that project? You know?Yes.

    20. SP

      Research online for existing, uh, models and see, uh, do some research on how they've been done before and pick one model and then, uh-

    21. KK

      All right. So do some research, see benchmarks and how different models perform at customer supports, and then pick a model. That's what you mean? Yeah. You c-- It's true, you could do that. What, what, what else could you do? Yeah.

    22. SP

      Do an orchestration frame from the category because the process will take those first.

    23. KK

      Okay. Yeah, I like that. Uh, try to, uh, decompose the different tasks that it will need and try to guess which ones will be more of a struggle, which ones should be fuzzy, which ones should be deterministic. Yeah, you're right.

    24. SP

      Yes. And I would just sit down with, like, a group of customer support and see how to ask them, do all of us then probably bring every task to the workflow.

    25. KK

      Yeah, similar to what you said. That's what I would recommend as well. You say, "I would sit down with a customer support agent for a day or two, and I would decompose the tasks they're going through. I will ask them, where do they struggle? How much time it takes?" Yes. That's usually where you wanna start with task decomposition. So let's say we've done that work and we have these lists. I'm simplifying, but the customer support agent, human, typically would extract info, then look up in the database to retrieve the customer record, then check the policy. You know, are we allowed to update the address, or is it a fixed data point? Um, and then draft a response email and send the email. Okay, so we've decomposed that task. Uh, once you've decomposed that task, uh, how do you design your agentic workflow? Yes.

    26. SP

      Each steps to task, you find which one, which one would be deterministic, which one we're gonna use a RAG answer or whatever method. In each task, what are you gonna use next for resources?

    27. KK

      Exactly. So to repeat, I'm gonna-- you're gonna look at the decomposition of tasks, get an instinct of what's fuzzy, what's deterministic, and then determine which line is going to be an LLM one shot, which one will require maybe a RAG, which one will require a tool, which one will require memory, which one... So you will start designing that map. Um, completely right. That's also what I would recommend. You, you might actually, uh, draft it and say, "Okay, I take the user prompt, um, and the first step of my task deposi-prosi-decomposition was extract information." That seems to be a vanilla LLM. You, you, you can guess that the vanilla LLM would probably be good enough at extracting the user wants to change their address, and this is the order number, and this is the new address. You probably don't need too much technology there other than the LLM. Um, the next step, it feels like you need a tool because you're actually going to have to look up in the database and also update the address. So that might be a tool, and you might have to build a custom tool for the LLM to say, "Let me connect you to that database," or, "Let me give you access to that resource with an MCP." You know. After that, you probably need an LLM again to draft the email, but you would probably paste confirmation. You paste the confirmation that your address has been updated from X to Y, and then the LLM will draft an answer. And of course, just to not forget, you might need a tool to send the email. You know, you might actually need to, um, you know, post something to-- for the email to, to go out. And then you'll get the output. Does that make sense? So exactly what you described. Okay. Now moving to the next step. Once we have decomposed our tasks, then we have designed an agentic workflow around it. It took us five minutes. In practice, it would take you more. If you're building your startup on that, you wanna make sure your task decomposition is accurate, your thing is accurate here, and then you can have a lot of work done on every tool and optimize it and latency and cost and so... But let's say-- And now we wanna know how, um, uh, if it works, you know. And I'm gonna assume that you have LLM traces. LLM traces are very important. Actually, if you're interviewing with an AI startup, I would recommend you in the interview process to ask them, "Do you have LLM traces?" Because if they don't have LLM traces, it is pretty hard to debug an LLM system. You know, because you don't have visibility on the chain of complex prompts that were called and where the bug is and, you know. So it's a basic, uh, sort of part of an AI startup stack to have, uh, LLM traces. So let's assume you have traces. How would you know if your system work? You know, we-- I, I want-- You know, I, I'm gonna summarize some of the things I heard earlier. Um, you gave us an example of, uh, an end-to-end, um, metric. You look at the user satisfaction at the end. Um, you can also do a component-based approach where you actually will look at the tool, the database updates, and you will manually do an error analysis and see, oh, the tool actually always forgets to update the email. It just fails at writing, you know. And I'm gonna fix that. This is deterministic, pretty much. Um, or, um, you know, when it tries to send the email and ping the system that is supposed to send the email, it doesn't send it in the right format, and so it bugs at that point. Again, you could fix that. Um, draft of the email. The LLM doesn't do a great job. It's not very polite at drafting the email, you know. So you could look at component by component, and it's actually easier to debug than to look at it end-to-end. You'll probably do a mix of both.Um, another way to look at it is what is objective versus what is subjective. So for example, an objective example would be a DLLM, um, extracted the wrong order ID. You know, the, the user said, "My order ID is X," and the LLM, when it actually pasted, uh, looked up in the database, it used the wrong order ID. This is objectively wrong. You can actually write a Python code that checks that, checks just the alignment between what the user mentioned and, and what was actually pasted in the database or for the lookup. Um, you also have subjective stuff, which we talked about, where you probably wanna do either human rating or LLM as judges. It's very relevant for, uh, subjective evals. Um, and finally, you will find yourself having quantitative evals and more qualitative evals. So quantitative would be percentage of successful address updates. Uh, the latency, you could actually track the latency component-based and see which one is the slowest. Let's say sending the email is five second. Y-you know, it's too long, let's say. You would notice component-based or the full workflow, and then you will decide where am I optimizing my latency and how am I gonna do that? And then finally, qualitative, uh, you might actually do some error analysis and look at, you know, where are the hallucinations, um, where are the tone mismatches? Uh, you know, are the user confused, and by what they're confused, you know? That would be more qualitative, and typically it would take more, um, uh, you know, white glove approaches to do that. Okay? So here's what it could look like. I gave you some examples, but you would build evals to determine objectively, subjectively, component-based, end-to-end based, and then quantitatively and qualitatively where is your LLM failing and where it's doing well. Does that give you a sense of the type of stuff you could do to fix-- improve that agentic workflow? Super. Well, that was our case study on evals. We're not gonna delve deeper into it, but hopefully it gave you a sense of the type of stuff you can do with LLM judges, with, you know, um, objective, subjective, component-based,

  17. 1:34:231:43:14

    Multi-agent workflows: when parallelism and reuse beat a single agent (smart home exercise)

    1. KK

      end-to-end, et cetera. Um, last section on multi-agent workflows. So you might, you might ask, uh, "Hey, uh, why do we need a multi-agent workflow when we o-- when the workflow already has multiple steps, already calls the LLM multiple times, already gives them tools? Why do we need, uh, multiple agents?" And so many people are talking about multi-agent system online. It's not even a new thing, frankly. I mean, multi-agent system have been around for a long time. Uh, the, the main advantage of a multi-agent system is going to be parallelism. It's like, is there something that I wish I would run in parallel, sort of independently, but maybe there are some syncs in the middle? Uh, but that's where you wanna put a multi-agent system. It's when it's parallel. The other advantage that some companies, um, have with multi-agent system is an agent can be reused. So let's say in a company you have an agent that's been built for design. That agent can be used in the marketing team, and it can be used in the product team, you know? And so now you're optimizing an agent which has multiple stakeholders that can communicate with it and benefit from its, uh, performance. Um, actually, I'm gonna ask you a question and take a few, uh, maybe a minute to think about it. Let's say you were, uh, building smart home automation for your apartment or your home. What agents would you wanna build? Yeah. Write it down, and then I'm gonna ask you in, in a minute to share some of the agents that you will build. Also, think about how you would put a hierarchy between these agents or how you would organize them or who should communicate with who, okay? Okay, take a minute for that. Be creative also because I'm gonna ask all of your agents, and maybe you have an agent that nobody has thought of. Okay, let's get started. Who wants to give me a, a set of agents that you would want for your home, smart home? Yes.

    2. SP

      So, uh, the first is like a set of agents to track my movements in the house and track information about my housemates, like housemates. Another agent would receive that information and, uh, adjust the room temperature, lighting based on the, based on me. And another agent that can travel to all of the equipment and some of the usage of, uh, like for example, gas, water, electricity, et cetera, and it need to orchestrate all of them.

    3. KK

      Okay. So let me repeat. You have four agents, I think, roughly. One that tracks biometric, like your-- where are you in the home, where are you moving, how you're moving, things like that, that sorts of knows your location. The second one, um, uh, determines the temperature, uh, of the rooms and has the ability to change it. The third one tracks energy efficiency and might give feedback on energy and energy usage. It might be, I don't know, maybe it has the control over the temperature as well, I don't know actually, uh, or the gas, uh, or the water. Um, might cut your water at some point. [chuckles] Uh, the-- and then you have an orchestrator agent. What is exactly the orchestrator doing?

    4. SP

      I think it passes instructions to all the other agents so you can-

    5. KK

      Okay. Passes the instructions. So is that the agent that communicates mainly with the user?

    6. SP

      Yeah.

    7. KK

      Okay. So if I have-- I'm coming back home, and I'm saying, "I want the oven to be preheated," I communicate with the orchestrator, and then it would funnel to another agent. Okay.Sounds good. Yeah. So that's an example of a, I wanna say, a hierarchical, um, agent-- multi-agent system. Um, what else? Any other ideas? What, what would you add to that? Yeah.

    8. SP

      Like, kind of a identification, and it's true for yourself too. On one, it's, it's true.

    9. KK

      Mm-hmm.

    10. SP

      You can have, like, or depending on who it is, you have, like, access to the, like, minimal action that you can do. Imagine entering a room or just entering a computer or just opening a fridge, like the minimum kind of action.

    11. KK

      Yeah.

    12. SP

      So you have, like, lots of agents per, per each, uh, domestic. And then depending on who, who is it and all the content you have, you, you can move around.

    13. KK

      Oh, I like that. That's a really good one. So let me summarize. You have a security agent that determines if you can enter or not, and when you enter, it understands who you are, and then it gives you certain sets of permissions that might be different depending on if you're a parent or a kid or, you know, you might have access to certain cars and not others, or the kid cannot open the fridge or I don't know, like something like that. Yeah. Or, uh, okay, I like that. That's a good one. Yeah. And it does feel like it's a complex enough workflow where you want a specific workflow tied to that. I, I agree. What, what else? Yes.

    14. SP

      Uh, considering on the ambient stuff, it can get, like, more complicated. So you can try energy savings with the ambient, right? You can track the weather APIs for instance to know whether or not you should keep your heaters on, uh, whether or not to keep your blinds open or closed when you're not in the house or these kinds of things. Also when to tap into the grid, right? At nighttime, it can be much cheaper.

    15. KK

      Yeah.

    16. SP

      So, um, another rough round thought I had as well, this is, like, much harder is that you can track products from the grocery store to understand what's in your fridge and not.

    17. KK

      Okay.

    18. SP

      So when you lose the data, like you wanna add to it.

    19. KK

      Well, that's really good, actually. So you mentioned two of them. One is maybe an agent that has access to external APIs that can understand the weather out there, the winds, the sun, and then has control over certain, uh, devices, uh, at home, temperature, blinds, things like that, and also understands your preferences for it. That does feel like it's a good use case because you could give that to the orchestrator, but it might lose itself because it's doing too much. So you probably-- And also these problems are tied together, like temperature outdoor with the weather API might influence the temperature inside, y-how you want it, et cetera. Agree. And then the second one, which I also like, is you might have an agent that looks at your fridge and what's inside, and it might actually have access to the camera in the fridge, for example, um, and know your preferences and also has access to the e-commerce API, uh, to order Amazon groceries ahead of time. Um, I agree. And maybe the orchestrator will be the communication line with the user, but it might communicate with that agent, um, in order to get it done. Uh, yeah, I like those. So those are all, uh, really good examples. Here, here is the list I had, um, up there. So climate control, lighting, security, energy management, entertainment, notification agent, alerts about the system updates, energy saving, and orchestrator. So all of them you mentioned, actually. Um, and then we didn't talk about the different interaction patterns, but you do have different ways to organize a multi-agent system: flat, hierarchical. It sounds like this would be hierarchical, I agree. And the reason is UI/UX, is I would rather have to only talk to the orchestrator rather than have to go to a specialized application to do something. Like, it feels like the orchestrator could be responsible for that. And so I agree. I would probably go for a hierarchical setup here. But maybe you might act-- also add some connections between other agents, like in the flat system, where it's all to all. For example, uh, with climate control and energy, if you wanna connect those two, you might actually allow them to speak with each other. When you allow agents to speak with each other, it is basically an MCP protocol, by the way. So you treat the agent like a tool, exactly like a tool. Here is how you interact with this agent. Here is what it can tell you. Here is what it needs from you, essentially. Okay, super. And then without going into the details, there are advantages to multi-agent workflows versus, uh, you know, single agents, such as debugging. It's easier to special-- debug a specialized agent than to de-debug an entire system. Parallelization as well. It's easier to have things run in parallel, um, and you can earn time. Um, you know, there are some advantages to doing that, and I leave you with this slide if you wanna go deeper. Super. So we've learned so many techniques to optimize LLMs, uh, from prompts to chains to fine-tuning, retrieval, um, and to multi-agent system as well. And

  18. 1:43:141:49:47

    What’s next in AI: plateau debates, architecture search, multimodality, and skill half-life

    1. KK

      then just to end on, um, a couple of trends I want you to watch. Uh, I think next week is Thanksgiving. Is that it? Is Thanksgiving break? No, the week after. Okay. Well, ahead of the Thanksgiving break, so if you're traveling, you can think about these things. Um, what's next is in AI, I wanted to call out a couple of trends. Um, so Ilya Sutskever, one of the OGs of, uh, uh, you know, LLMs, um, and, you know, OpenAI co-founder, um, raises that question about are we plateauing or not? You know, the question of, uh, are we going to see in the coming years LLMs sort of, uh, not improve as fast as we've seen in the past? It-it's been the feeling in the community probably that, uh, you know, the last version of GPT, um, uh, did not bring the level of performance that people were expecting, although it did make it so much easier to use for consumers because you don't need to interact with different models. It's all under the same hood. So it seems that it's progressing, um, but the plateau is, is unclear. The, the way I would think about it is, um-Uh, the LLM scaling laws tell us that if we continue to improve compute and energy, then LLMs should continue to improve, but at some point, it's gonna plateau. So what's gonna take us to the next step? Um, it's probably architecture search. Still a lot of LLMs, even if we don't understand what's under the hood, are probably transformer-based today, but we know that the human brain does not operate the same way. There's just certain things that we do that are much more efficient, much faster. We don't need as much data. So theoretically, we have so much to learn in terms of architecture search that we haven't figured out. It's not a surprise that you see those labs hire so many engineers because it is possible that in the next few years you're gonna have thousands of engineers trying to figure out the different engineering hacks and tactics and architectural searches that are gonna lead to better, uh, models, and one of them suddenly will find the next transformer, and it will reduce by 10X the need for compute and the need for energy. Um, you know, it's sort of if you've read, uh, Isaac Asimov's, uh, uh, Foundation series, um, individuals can have an amazing impact on the future because of their decisions. You know, whoever discovered transformers had a tremendous impact on the direction of AI. I think we're gonna see more of that in the coming years, where some group of researcher that is iterating fast might discover certain things that would suddenly unlock that plateau and take us to the next step, and it's gonna continue to improve like that. And so it doesn't surprise me that there's so many companies hiring engineers right now to figure out those hacks and those, those techniques. Um, the other set of gains that we might see is from multimodality. So the way to think about it is we've, we've, we've had LLMs first text-based, and then we've added imaging. And today, you know, models are very good at images. They're very good at text. Turns out that being good at images and being good at text makes the whole model better. So the fact that you're good at understanding a cat image makes you better at text as well for a cat. Now you add another modality like audio or video, the whole system gets better. So you're better at writing about a cat if you know what a cat sounds like, if you can look at a cat on an image as well. Does that make sense? So we see gains that are translated from one modality to another, and that might lead in the pinnacle of robotics, where all these modalities come together and suddenly the robot is better at running away from a cat because it understands what a cat is, how it sounds like, what it looks like, et cetera. That make sense? Um, the other one is the multiple methods working in harmony. In the Tuesday lectures, we've seen supervised learning, unsupervised learning, self-supervised learning, reinforcement learning, prompt engineering, RAGs, et cetera. If you look at, um, how, uh, babies learn, um, it is probably a mix of those different approaches. Like a baby, um, might have some meta learning, meaning it, you know, it has some survival instinct that is in the-- encoded in the DNA, most likely. Um, and that's like the baby's pre-training, if you will. On top of that, uh, the mom or the dad, um, is pointing at stuff and saying, "Bad, good, bad, good," supervised learning. On top of that, the baby's falling on the ground and getting hurt, and that's a reward signal for reinforcement learning. On top of that, the baby's observing other people doing stuff, or other babies, you know, doing stuff, unsupervised learning. You see what I mean? It's-- we're probably a mix of all these methods and, um, and I think that's where the trend is going, is where those methods that you've seen in CS230 come together in order to build an AI system that learns fast, is low latency, is cheap, energy efficient, and makes the most out of all of these methods. Um, finally, and this is especially true at Stanford, um, you have research going on that you would consider human-centric and some research that is non-human centric. By human-centric, I should say human approaches that are modeled after the brain and approaches that are not modeled after humans because it turns out that the human, uh, body is very limiting. And so if you actually only do research on what the human brain looks like, you're probably missing out on compute and energy and stuff like that that you can optimize even beyond neuronal connections in the brain. But you still can learn a lot from the human brain, and that's why there are professors that are running labs right now that try to understand how does backpropagation work for humans. And in fact, it's probably that we don't have backpropagation. We don't use backpropagation. We only do forward propagation, let's say. So this type of stuff is interesting research that I would encourage you to read if you're curious about the direction of, of AI. Um, and then finally, um, one thing that's gonna be pretty clear, I call it all the time, but it's the velocity at which things are moving. You're noticing part of the reason we're, we're giving you a breadth in CS230 is because these methods are changing so fast. So I don't wanna bother going and teaching you the number seventeen methods on RAG that optimizes the RAG, because in two years you're not gonna need it, you know? So I would rather you think about what is the breadth of things you wanna understand, and when you need it, you are sprinting and learning the exact thing you need faster because the half-life of skill is so low. You know, you wanna come out of the class with a good breadth and then have the ability to go deep whenever you need after the class. And so that's sort of how that class is designed as well. Um, yeah, that's it for today. So thank you. Um, thank you for participating.

Episode duration: 1:49:53

Install uListen for AI-powered chat & search across the full episode — Get Full Transcript

Transcript of episode k1njvbBmfsw

Get more out of YouTube videos.

High quality summaries for YouTube videos. Accurate transcripts to search & find moments. Powered by ChatGPT & Claude AI.