Context Engineering Clearly Explained

Tina Huang www.youtube.com

Brief Summary

This video explains context engineering, its relevance to AI application development, and how it differs from prompt engineering. It details the essential components of an AI agent and how context engineering serves as the instruction manual for these components. The video also provides a practical example of a context-engineered prompt for an AI research assistant and shares resources for further learning.

  • Context engineering is crucial for building AI applications like AI agents, focusing on providing the right information in the right format at the right time.
  • The six essential components of an AI agent are model, tools, knowledge and memory, audio and speech, guardrails, and orchestration.
  • Context engineering involves creating a detailed prompt that instructs the AI agent on how to use its various components and tools effectively.

Intro

The video introduces the concept of context engineering, explaining its origins and relevance. It promises to cover the definition of context engineering, its purpose, practical application, and concrete examples. The video includes assessments to test understanding of the material.

Context Engineering Defined & How It Differs From Prompt Engineering

Context engineering involves designing dynamic systems that provide Large Language Models (LLMs) with the appropriate information in the correct format at the right time to complete a task. It is particularly relevant for those developing LLM applications, including AI agents. While context engineering is considered the evolution of prompt engineering, prompt engineering remains relevant for simple chatbot interactions. Context engineering becomes essential when building AI agents because it requires providing comprehensive instructions and resources to handle various scenarios, unlike the iterative nature of chatting with a chatbot. The complex prompts used in context engineering often resemble code, distinguishing it from basic prompting. Context engineering is the progression of prompt engineering in crafting complex prompts for building AI applications.

Quiz 1

The video presents a quiz question to test the viewer's understanding of the concepts discussed so far. Viewers are encouraged to write their answers in the comments section.

Using Context Engineering to Build an AI Agent

An AI agent is defined as a software system that uses AI to achieve goals and complete tasks on behalf of users, such as customer service, sales assistance, or coding assistance. Regardless of the type, every AI agent consists of six essential components: model, tools, knowledge and memory, audio and speech, guardrails, and orchestration. These components are analogous to the elements of a burger: bun, patty, vegetables, and condiments. The context engineer's role is to create an instruction manual, detailing how these components work together, including tool usage, memory access, knowledge base, and audio/speech functionalities. The resulting prompt serves as the AI agent's guide for utilizing its capabilities, making it crucial to refine this prompt through context engineering.

Quiz 2

Another assessment is presented to the viewers in the form of quiz questions, encouraging them to share their answers in the comments section.

Demo: Context Engineered Prompt For An AI Agent

The video demonstrates a context-engineered prompt for an AI research assistant designed to identify and summarize AI trends. The system prompt is structured into six components using markdown format: role, task, input, output, constraints, and capabilities and reminders. The task component details the steps the AI agent should take, such as extracting subtasks, prioritizing them, generating JSON outputs, calculating time periods, and summarizing findings. The input is specified using XML tags, and the output format is defined in JSON, including variables like ID, query, source type, time period, domain focus, priority, start date, and end date. Constraints focus on succinctness and avoiding fluff, while capabilities and reminders specify the tools and knowledge bases the agent can access, such as web search, and reminders to ensure relevance. The presenter also shares that such system can be split into multi-agent systems.

Context Engineering Resources

Two resources are recommended for those wanting to learn more about context engineering. The first is a blog post from Cognition, which shares two principles for context engineering in multi-agent frameworks: always share context between agents, and recognize that actions carry implicit decisions. The second resource is an article from Langchain, which presents a framework that breaks down common strategies for context engineering, including writing context, selecting context, compressing context, and isolating context.

Quiz 3

A final assessment is presented to the viewers in the form of quiz questions, encouraging them to share their answers in the comments section.

Summarize any YouTube video in seconds

Get summaries like this one for any video, in your language, with the free Summ app.

Download on the Apple Store
Get it on Google Play

Transcript

Full transcript of “Context Engineering Clearly Explained”. Click a timestamp to open the video at that moment. Need another video? Use the YouTube transcript generator.

0:00 I learned about context engineering for you. So, let me now save you the hours you have to spend scrolling through X and Reddit trying to understand what is context engineering. The outline of today's video is that I'm going to first explain what is context engineering, why it came about, and what it's relevant for. Then, we'll talk about how to do context engineering, and finally some examples to make it all concrete. As per usual, it's not enough for me just to talk about stuff. So, there will be little assessments throughout this video. So, please pay attention. And if you can answer these questions, then congratulations. you have now been educated on context engineering. So without further ado, let's go. A portion of this video is sponsored by Augment Code. All right, let's first define context engineering. Context engineering is designing and building dynamic systems that give an LM the right info in the right format at the right time to

0:45 accomplish a task. In other words, you're packing the context window, which is the input area of a large language model just right. All right, now that we've defined the term, the first point I want to make is that context engineering is only relevant to people who are making LLM apps, including things like AI agents. You may have already heard or read online that context engineering is the new prompt engineering. That is true, but it doesn't mean that like prompt engineering is dead. For example, if you just want to chat with a chatbot, like chat GBT about the kind of running shoes that you should choose for your feet. You know, you're having a back and forth conversation talking about the different cushioning types, uh, certain price ranges, how different outfits match up for your running outfits. All of that is prompting. That's still prompt engineering, and it's still completely relevant in those scenarios. Context engineering only becomes relevant when you're building AI applications like AI

1:31 agents. Because unlike that chatbi conversation where you're just going back and forth, when you're building something like an AI agent, you can't iteratively keep talking to the agent until it gets the answer correct. You need to give it a set of instructions that encompasses all the actions it has to take and all the different scenarios that it's going to encounter. For example, if you're building a customer service AI agent for your online store, that agent needs to be equipped with the ability to handle all sorts of inquiries like billing problems, refund issues, login issues, searching up terms and conditions because people can't read, people asking it stupid irrelevant questions, probably also people yelling at it and abusing it unfortunately, and be able to escalate to a human when necessary. And to be able to give it all the instructions and resources and everything that it needs in order to accomplish these tasks, your prompts become larger and larger and more and more complex. At some point they even

2:16 start to resemble code with XML tags and markdown. As you can see this is really really different than just prompting and having a conversation with chatbt which is why people came up with the term context engineering. So yeah that's pretty much it. Context engineering isn't some new technique that's completely coming out of the blue. It really is the progression of prompt engineering in the very specific cases of crafting complex prompts for building AI applications. As Andre Kaparthy explains the LM is the CPU and the context window is the RAM. Make sense? I'm going to put on screen now a little assessment. Please write in the comments your answer. All right, let's now dive deeper into what context engineering actually looks like when we're building an AI agent. First, to make sure we're all on the same page, the definition of an AI agent is a software system that uses AI to pursue goals and complete

3:02 tasks on behalf of users. For example, a customer service AI agent that answers customer service queries. A sales assistant AI agent that's able to qualify leads and follow up with people. A coding agent that can help you to code. There are lots and lots of different types of AI agents. However, regardless of what types of AI agents there are, there are six components which are essential building blocks that make up an AI agent. The first component is model. Every AI agent needs to have an AI model. It can be open GPT models, it can be claude, it can be Gemini, it can be smaller models, it can be larger models, it can be open source models, whatever fits. The second component is tools. Tools allow agents to be able to interact with external systems. For example, a personal assistant agent needs to be able to have a tool that allows it to access your Google calendar to be able to book appointments for you. Next up is knowledge and memory. Most agents need a way to store and retrieve information. For example, if you have a therapy AI agent and you're having

3:49 conversations with it, you need it to have memory so that it's able to remember what has been said in previous conversations. If you have a legal AI agent that's meant to screen through some very specific cases, you need to give it the knowledge base of those specific cases that you want it to work on. Then there's audio and speech. Equipping your AI agent with the ability for audio and speech will allow it to be a lot more natural and easier to interact with. Every AI agent also needs to have guardrails which are safety mechanisms to ensure proper behavior. You don't want your customer service AI agent to swear back at your users probably. And finally, there is orchestration. These are systems that allow you to deploy your AI agent, monitor them, and improve them over time. You don't want to just release your AI agent into the wild and just run away. Got to keep track of what it's doing. The analogy that I like to make is that these six components of AI agents is sort of like a burger. Like in

4:34 order for a burger to be considered a burger, it needs to have a bun, a patty, vegetables, and condiments. You can have different types of buns like whole wheat, whites, even lettuce buns and different types of patties, like different types of meats. But you do need to have these different components to be able to be called a burger. Same with AI agents. You can have different types within these components, but you do need to have these components to be considered an AI agent. Now, continuing this analogy, imagine that you are an alien and you don't understand how these burger thingies work. So, whoever is telling you to make a burger probably needs to also provide an instructions manual telling you that the bun goes on either side. Then you're supposed to put in the vegetables, the condiments, and the patty in the middle. And that's how you would know how to assemble your burger. It's the same thing for AI agents. You can have all of these different components of these AI agents, but you need to have an instruction manual for how all these things fit

5:20 together. And that is where the context engineer comes in. You're coming up with that prompt that exactly details how everything is working together, what the tools are, how to use them, how to access memory, what's in the knowledge base, when to use speech and audio functionalities, etc., etc. The resulting prompt is going to be the instructions manual for your AI agent to be able to use all the things that it's equipped with. It is really important to get this prompt right, and people spend a lot of time context engineering until they get that perfect prompt. Time for the next little assessment. Please answer the questions on screen and put your answers in the comments. As we've already talked about, context engineering goes handinhand with building AI applications. And when it comes to building AI applications that are meant to be more than just proof of concepts or demos, pure vibe coding just isn't enough. That is where Augment code comes in. It's built for real

6:06 engineering work, including debugging, writing tests, refactoring, and navigating complex systems. Augment's context engine feeds Claude Sonnet for exactly what it needs for your codebase. There's no need for guessing, model picking, or forks. Just a deeply integrated assistant that helps you ship. You can even launch cloud agents to refactor or fix tests even when your laptop is closed. It runs in your IDE including VS Code, Jet Brains, Vim, and Cursor. They also take security very, very seriously. Augment is ISO and SOCK 2 certified, and there's no training on customer code. You can try it off for free for 14 days at this link over here, also linked in description. Thank you so much Augment Code for sponsoring this portion of the video. Now, back to the video. Okay, I'm going to show you now a full example of a context engineered prompt for an AI agent. Specifically, this is a prompt for an AI research

6:51 assistant that I made for myself in order to keep up with all the AI trends. The general structure of the system prompt is that I have these six different components, which is like the little hashtag thingies that is markdown format. And this is useful because it helps um structure the prompt in a way that is easier to follow. So, under role, you're an AI research assistant focused on identifying and summarizing recent trends in AI from multiple source types. Your job is to break down a user's query into actionable subtasks and return the most relevant insights based on engagement and authority. Under task, so the thing that we actually want the AI agent to do, we have given a research query delimited by the XML tags user query and end tag user query. So this is um XML tags. It's also a way to structure the information so it's more clear for the AI to be able to process. Do the following. Step one is to extract

7:38 up to 10 diverse high priority subtasks each targeting a different angle or source type. Step two is to prioritize by engagement such as views, likes, repost, and citations as well as authority of source such as publication reputation and domain expertise. Step three is to generate a JSON output for each subtask in the format below. And step four is to calculate the correct start date and end date in UTC ISO format based on the specified time period. And step five is to summarize all findings into a single concise trend summary approximately 300 words max. As you can see, it is very very structured and detailed going step by step saying that you need to extract up to 10 different subtasks like 10 different types of sources regarding a specific topic from the user. You need to prioritize it. Uh generate certain specified JSON outputs like a type of output and make sure that the time

8:25 periods are in the correct time period that the user specifies and then go on to actually summarize all the findings. The input is within the XML tags which is user query. Uh it says insert search query here. This is where the user would input whatever it is that they want to search. So for the output of this agent, you have you will output up to 10 subtasks in this exact format and this is a JSON format that we very clearly stated. So every single subtask which is a source it needs to be exactly in this format has the ID. The query specifies subquery related to one aspect of the main topic. The source type it can be news, it can be from X, it can be from Reddit, LinkedIn, newsletter, academic or specialized. The time period for when that resource came out it can be between 1 day to 10 days. Domain focus is a technology science or health priority determining how important this source is from highest of one to lowest of 10 and the start date and the end date in this

9:12 specific format. Under output, it says that you will output up to 10 subtasks in this exact format. So we can see here that this is JSON format and we're specifying all of the different variables that need to be there. Then after performing all subtasks, write a final output summarizing the key recent trends, including limiting to 300 words using bullet points or short paragraphs. Only include new relevant high signal developments and avoiding fluff background or personal commentary. Then there's constraints. Focus on capturing the main point succinctly. Complete sentences and perfect grammar are unnecessary. Ignore fluff, background information, and commentary. Do not include your own analysis or opinions. Then finally, we have capabilities and reminders. We're telling it what are the different tools and knowledge bases that it has access to and giving it very specific reminders so it doesn't go off track. You have access to the web search tool to find and retrieve recent news

9:57 articles relevant to the search term. You must be deeply aware of the current date to ensure the relevance of news summarizing only information published within the past 10 days. So this is example of a system prompt for a single research assistant AI agent. So and this is actually considered a very very simple prompt. I also contain everything within that singular AI agent. When actually like normally when I do something like this, I would generally split it into multi- aent systems where you would have one agent that searches up all the different sources and you have another agent that would actually go and summarize everything for you. But even just for illustration purposes, I hope you can see that how complex this context engineering can get. And it's going to go and gather information, gather news from different newsletters as well as Reddit. Then it would aggregate all of that information

10:42 together and ultimately come up with a summary that it's going to send to me on WhatsApp. And in this case, I implemented this AI agent using NA10. You can of course implement this using a variety of other tools as well. Like in our AI agents boot camp, we teach people to implement no code agents using NAT. And for people who want to use code, uh we would generally teach them how to use like something like OpenAI's agents SDK. But it doesn't actually matter whatever it is I use to implement these prompts. Um they are applicable across different agentic systems. So before I end this video, I do want to share with you guys two additional resources which I think are excellent if you really want to dive deeper into context engineering and how it is that you can go about u creating these multi- aent systems and getting the results from it. The first one is a blog post from cognition and they share two fundamental principles for context engineering specific for multi- aent frameworks. The first one is to always

11:29 share context between your agents. And the second is that actions carry implicit decisions. And whenever you have a decision point, you need to be very very careful of this in your architecture and in your context engineering as well. Highly recommend that you check out this blog post. The second article is from Langchain where they showcase this really great framework that breaks down common strategies that people use when context engineering. The first one is writing context. How it is that you can allow your large language model to write down information surrounding a task so it's able to save it and use it for later. The second is selecting context. How it is that you can pull information from external sources to help your agent perform a task. The third is compressing context. When there is a lot of information that you're trying to give in large language model, there are techniques that you can do in order to help compress that information in a more

12:15 compact way. And the fourth is isolating context. How to split context in between different environments and different places. I'm not going to go into more details about this to keep this video relatively succinct, but you do want to dig deeper into techniques for context engineering so you can build better AI apps like AI agents. Highly recommend that you check out these resources. All right, that is everything that I have for you today. So, here is the final little assessment. Please write your answers in the comments below. Thank you so much for watching until the end of this video and I will see you guys in the next video or live stream.

Share

More video summaries