Section Insights
Understanding Prompt and Context Engineering
What is the difference between prompt engineering and context engineering?
Prompt engineering involves crafting the input text for a language model, while context engineering encompasses the broader system of assembling all necessary information for the model to function effectively.
- Prompt engineering focuses on the specific wording of instructions.
- Context engineering includes all elements the model needs for accurate responses.
- Both disciplines are crucial for effective AI interactions.
The Importance of Providing Context
Why is context important in AI interactions?
Providing sufficient context, such as company travel policies, is essential for the AI to make appropriate decisions and recommendations.
- Insufficient context can lead to incorrect outputs.
- Context engineering ensures the AI has the necessary information to perform tasks.
- Effective prompt engineering requires understanding the context in which the AI operates.
Techniques for Effective Prompt Engineering
What are some key techniques in prompt engineering?
Techniques include role assignment, few-shot examples, chain of thought prompting, and constraint setting, each enhancing the model's ability to generate relevant outputs.
- Role assignment helps the model adopt specific expertise.
- Few-shot examples clarify format and style requirements.
- Chain of thought prompting encourages detailed reasoning.
Components of Context Engineering
What are the key components of context engineering?
Key components include memory management (short-term and long-term), state management, and retrieval augmented generation (RAG) to ensure the AI maintains context and retrieves relevant information.
- Short-term memory summarizes conversations to maintain context.
- Long-term memory retrieves user preferences and patterns.
- State management tracks progress in multi-step tasks.
Integrating Tools and Context in AI Systems
How do tools and context engineering enhance AI capabilities?
Tools enable AI to access databases and APIs, while context engineering defines how these tools are used, enhancing the AI's ability to perform complex tasks effectively.
- Tools bridge the gap between AI and real-world data.
- Context engineering guides the AI in using tools appropriately.
- Combining prompt and context engineering leads to better AI systems.
Transcript
0:00 I think by now most of us are familiar with the term prompt engineering. It's the process of crafting the input text used to prompt a large language model, including instructions and examples and formatting cues. It's what steers the LLM's behavior and output. Now, context engineering, on the other hand, is the broader discipline of programmatically assembling everything the LLM sees during inference. Now that includes prompts, but also retrieve documents and memory and tools—everything needed to deliver accurate responses. So, to demonstrate the difference, let me introduce you to an agentic AI model that I like to call Graeme.
0:41 Secret Agent Graeme. Agent Graeme specializes in travel booking. So, if I send Graeme this prompt, "Book me a hotel in Paris for the DevOps conference next month," well, the agent responds with "Sure thing. The Best Western Paris Inn has great wifi and free parking. It's booked." Cool. But the only trouble is the Best Western is located in Paris, Kentucky, and that DevOps conference is in Paris, France. Now, you could argue that that's a failing of prompt engineering.
1:14 I wasn't specific on the location. But it could also be seen as a failing of context engineering because if Agent Graeme here was just a little smarter, well, they could have used a tool to check my calendar or look up the conference online to find the right location. So... so let's try again with a follow-up prompt. My conference is in Paris, France. €900 a night. Ritz booked. Champagne. Breakfast included. Well, wish me luck getting that one approved through my company expense reimbursement system.
1:47 But Graeme here can't really be blamed for that one because I didn't provide sufficient context. I should have made my company's travel policy available to the agent. Perhaps there's a JSON file specifying things like maximum permissible hotel rates for the area. So, prompt engineering—that's the craft of wording the instruction itself. And context engineering is the system-level discipline of providing the model with what it needs to plausibly accomplish the task. So let's take a look at these two terms a bit closer.
2:19 And we'll start with the key techniques that make prompt engineering effective. Now this is part art, part science. But there are several prompt engineering techniques that are now widely adopted. So, take for example, role assignment. This tells the LLM who it should be. So, you are a senior Python developer reviewing code for security vulnerabilities. Well, that produces vastly different outputs than a more generic code review request.
2:51 The model adopts the expertise, the vocabulary and the concerns of that persona that we asked for. ... another good technique comes down to few shot examples. So, this is show, don't just tell. So, providing 2 or 3 examples of input/output pairs... that helps the model understand your exact format and style requirements. So, if you want JSON output with specific field names, well, show it. Show it in the examples. Now, before we had reasoning models trained on reinforcement learning, a pretty popular prompt engineering technique was called COT or chain of thought prompting.
3:36 Now this forces the model to show its work. Adding "let's think step by step" or "explain your reasoning"—that prevents the LLM from jumping to conclusions. And it's particularly powerful for complex reasoning tasks. And then another technique is called constraint setting. Here you define boundaries explicitly. So, "limit your response to only 100 words" or "only use information from the provided context". And that helps prevent the model from going off on tangents.
4:08 Context engineering—that helps build dynamic, agentic systems to orchestrate the entire agentic environment. And let's take a look at some of the components of that. Well, agentic AI. First of all, it needs memory. And memory management can be thought of in two forms. So there's short-term memory... that might involve summarizing long conversations to stay within context windows so that past conversations are not forgotten.
4:38 And then there's also long-term memory, and that uses vector databases to retrieve things like user preferences and past trips and learned patterns. Then there is state management. Now, this says where are we in a multi-step process? So, if an agent is booking a complete trip—the flight, the hotel, the ground transportation, all of it— well, the agent needs to maintain state across these operations. Did the flight booking succeed? What's the arrival time for scheduling the airport transfer? Stuff like that.
5:12 So, state ensures that the agent doesn't lose context mid task. Now, another important component is retrieval augmented generation or RAG, that connects an agent to dynamic knowledge sources. So, RAG uses hybrid search which combines semantic and keyword matching based on context. So, when retrieving your company's travel policy, RAG isn't returning the entire travel policy document.
5:43 There's a lot of stuff that's just kind of irrelevant to the context in there. So instead, it's picking out the relevant sections and the relevant exceptions and returning only those contextually relevant parts back to the agent. And agents also need access to tools so they can actually go out and do stuff. So LLMs by themselves, they can't check real databases or call APIs or execute code. It's tools that bridge that gap, and a tool might query a SQL database, or it might fetch live pricing data, it might deploy infrastructure.
6:21 And where context engineering comes in is in defining the interfaces that guide the LLM toward the correct usage. And tool descriptions— they specify what the tool does, when to use it, and what constraints apply. And prompt engineering? Well, actually we should include that as well because that is also part of context engineering. You can take a base written prompt like "analyze security logs for anomalies". You can take that as your prompt and then at runtime, inject the prompt with current context, like recent alerts and known false positives.
6:58 And all of those variables in the prompt, they get populated from the states and the memory and the RAG retrievals. So, that final prompt might be 80% dynamic content from there and 20% static instructions. So, prompt engineering... it gives you better questions. Context engineering—that gives you better systems when you combine them properly. Hotel booked. Paris, France. Under budget. Near the venue. Excellent. Thank you, Agent Graeme. Pending approval from your manager, HR and finance.
7:30 Estimated approval time: 6 to 8 weeks. the conference is in two weeks. Have you tried prompt engineering your manager?
Summary
- **Prompt Engineering**: Focuses on the wording of instructions to guide LLM behavior.
- **Context Engineering**: Involves assembling all necessary information for the LLM to perform tasks effectively.
- **Agentic AI Example**: "Agent Graeme" demonstrates the importance of both prompt and context engineering in travel booking scenarios.
- **Key Techniques in Prompt Engineering**:
- **Role Assignment**: Defining the persona for the LLM to adopt.
- **Few-Shot Examples**: Providing examples to clarify desired output formats.
- **Chain of Thought (COT)**: Encouraging step-by-step reasoning for complex tasks.
- **Constraint Setting**: Explicitly defining boundaries for responses.
- **Memory Management**: Involves short-term and long-term memory to maintain context and user preferences.
- **State Management**: Tracks progress in multi-step tasks to ensure continuity.
- **Retrieval Augmented Generation (RAG)**: Connects agents to relevant knowledge sources dynamically.
- **Tool Access**: Enables LLMs to interact with databases and APIs, enhancing their capabilities.
Questions Answered
What is the difference between prompt engineering and context engineering?
Prompt engineering involves crafting the input text for a language model, while context engineering encompasses the broader system of assembling all necessary information for the model to function effectively.
Why is context important in AI interactions?
Providing sufficient context, such as company travel policies, is essential for the AI to make appropriate decisions and recommendations.
What are some key techniques in prompt engineering?
Techniques include role assignment, few-shot examples, chain of thought prompting, and constraint setting, each enhancing the model's ability to generate relevant outputs.
What are the key components of context engineering?
Key components include memory management (short-term and long-term), state management, and retrieval augmented generation (RAG) to ensure the AI maintains context and retrieves relevant information.
How do tools and context engineering enhance AI capabilities?
Tools enable AI to access databases and APIs, while context engineering defines how these tools are used, enhancing the AI's ability to perform complex tasks effectively.