← Back
JetBrains TV July 24, 2026 12m

How AI Agents Work: Prompt, Context, Harness & Loop Explained

Read full transcript 10 segments
  1. The AI world loves buzzwords. New terms The AI world loves buzzwords. New terms are popping up faster than most people are popping up faster than most people are popping up faster than most people can track, and it's getting hard to tell can track, and it's getting hard to tell can track, and it's getting hard to tell which ones actually mean something and which ones actually mean something and which ones actually mean something and which are just noise. That confusion is which are just noise. That confusion is which are just noise. That confusion is a problem. When everything sounds a problem. When everything sounds a problem. When everything sounds important, nothing does. But, a few of important, nothing does. But, a few of important, nothing does. But, a few of these terms are worth knowing because these terms are worth knowing because these terms are worth knowing because they genuinely build on each other in a they genuinely build on each other in a they genuinely build on each other in a useful way. Prompt engineering, context useful way. Prompt engineering, context useful way. Prompt engineering, context engineering, harness engineering, and engineering, harness engineering, and engineering, harness engineering, and loop engineering. So, today, instead of loop engineering. So, today, instead of loop engineering. So, today, instead of adding to the noise, I'm going to walk adding to the noise, I'm going to walk adding to the noise, I'm going to walk you through all four with simple you through all four with simple you through all four with simple examples so that by the end, you'll examples so that by the end, you'll examples so that by the end, you'll actually know what people are talking actually know what people are talking actually know what people are talking about. Prompt engineering, in simple words, is Prompt engineering, in simple words, is just how to talk to AI. And, like any just how to talk to AI. And, like any just how to talk to AI. And, like any conversation, how you frame it matters conversation, how you frame it matters conversation, how you frame it matters as much as what you ask. Quick example, as much as what you ask. Quick example, as much as what you ask. Quick example, I'll open AI chat and turn off I'll open AI chat and turn off I'll open AI chat and turn off code-based mode so the model has zero code-based mode so the model has zero code-based mode so the model has zero access to my project Netflix movies access to my project Netflix movies access to my project Netflix movies analyzer.

  2. analyzer. analyzer. This is purely for demo reasons. I want This is purely for demo reasons. I want This is purely for demo reasons. I want to show prompt engineering on its own to show prompt engineering on its own to show prompt engineering on its own without any other concept interfering. without any other concept interfering. without any other concept interfering. What makes a Netflix show successful? What makes a Netflix show successful? What makes a Netflix show successful? Generic. It's giving me a paragraph Generic. It's giving me a paragraph Generic. It's giving me a paragraph about popular genres and viewership about popular genres and viewership about popular genres and viewership trends. Could have been copied from a trends. Could have been copied from a trends. Could have been copied from a blog post. No structure, no hypotheses, blog post. No structure, no hypotheses, blog post. No structure, no hypotheses, nothing I can actually act on. And nothing I can actually act on. And nothing I can actually act on. And that's not the model's fault. I gave it that's not the model's fault. I gave it that's not the model's fault. I gave it nothing. No role, no specific question, nothing. No role, no specific question, nothing. No role, no specific question, no output format. That's a prompt no output format. That's a prompt no output format. That's a prompt engineering problem. You are a data engineering problem. You are a data engineering problem. You are a data analyst looking at Netflix content. What analyst looking at Netflix content. What analyst looking at Netflix content. What are three hypotheses for why TV shows are three hypotheses for why TV shows are three hypotheses for why TV shows might get renewed more often than might get renewed more often than might get renewed more often than movies? For each hypothesis, suggest one movies? For each hypothesis, suggest one movies? For each hypothesis, suggest one metric I could use to test it. Same metric I could use to test it. Same metric I could use to test it. Same model, same blank slate, completely model, same blank slate, completely model, same blank slate, completely different answers. Now, it's giving me different answers. Now, it's giving me different answers. Now, it's giving me three structured hypotheses, each with a three structured hypotheses, each with a three structured hypotheses, each with a specific metric I can test. This is specific metric I can test. This is specific metric I can test. This is actually useful. Nothing changed except actually useful. Nothing changed except actually useful. Nothing changed except the message I sent. And that is prompt the message I sent. And that is prompt the message I sent. And that is prompt engineering. Role, specific question, engineering. Role, specific question, engineering. Role, specific question, output format. Three things, and that's output format. Three things, and that's output format. Three things, and that's all it took. It works great for one-off all it took. It works great for one-off all it took. It works great for one-off questions like this, but notice, the questions like this, but notice, the questions like this, but notice, the model still knows nothing about my model still knows nothing about my model still knows nothing about my actual project. It doesn't know my actual project. It doesn't know my actual project. It doesn't know my column names, my data quality issues, column names, my data quality issues, column names, my data quality issues, the specific words of my CSV, or my the specific words of my CSV, or my the specific words of my CSV, or my code. And every time I need something code. And every time I need something code. And every time I need something specific to my project, I'm starting

  3. specific to my project, I'm starting specific to my project, I'm starting from zero. Prompt engineering answers from zero. Prompt engineering answers from zero. Prompt engineering answers one question, how should I phrase this? one question, how should I phrase this? one question, how should I phrase this? But there is a second important But there is a second important But there is a second important question, what does the model actually question, what does the model actually question, what does the model actually need to know right now, and how do I need to know right now, and how do I need to know right now, and how do I stop having to repeat it every single stop having to repeat it every single stop having to repeat it every single time? And that's where context engineering And that's where context engineering comes into play. While prompt comes into play. While prompt comes into play. While prompt engineering focuses on how instructions engineering focuses on how instructions engineering focuses on how instructions are phrased, context engineering manages are phrased, context engineering manages are phrased, context engineering manages what information is made accessible to what information is made accessible to what information is made accessible to the model when generating a response. the model when generating a response. the model when generating a response. Prompt instructions, data, chat history, Prompt instructions, data, chat history, Prompt instructions, data, chat history, documents. Now, let me turn code base documents. Now, let me turn code base documents. Now, let me turn code base mode on for this one, and also feed it mode on for this one, and also feed it mode on for this one, and also feed it specifically the main notebook file and specifically the main notebook file and specifically the main notebook file and CSV file. I have the hypothesis from CSV file. I have the hypothesis from CSV file. I have the hypothesis from before that TV shows get added to before that TV shows get added to before that TV shows get added to Netflix more recently than movies, and Netflix more recently than movies, and Netflix more recently than movies, and how I want to test it against my real how I want to test it against my real how I want to test it against my real data. I'll ask it to write a function data. I'll ask it to write a function data. I'll ask it to write a function that does exactly that. Now it has that does exactly that. Now it has that does exactly that. Now it has context on the data from the CSV, so context on the data from the CSV, so context on the data from the CSV, so it's using the real column names. It's it's using the real column names. It's it's using the real column names. It's handling the edge cases I actually care handling the edge cases I actually care handling the edge cases I actually care about, and it's also following my coding about, and it's also following my coding about, and it's also following my coding style request, because it's fed with all style request, because it's fed with all style request, because it's fed with all the project files. Without these, it the project files. Without these, it the project files. Without these, it wouldn't be able to do the job. And wouldn't be able to do the job. And wouldn't be able to do the job. And that's context engineering on a high that's context engineering on a high that's context engineering on a high level. Andrej Karpathy defined it as the level. Andrej Karpathy defined it as the level. Andrej Karpathy defined it as the delicate art and science of filling the delicate art and science of filling the delicate art and science of filling the context window with just the right context window with just the right context window with just the right information for the next step. The information for the next step. The information for the next step. The context window is everything the model context window is everything the model context window is everything the model sees at inference time. Having project

  4. sees at inference time. Having project sees at inference time. Having project access gives a model a lot of signal, access gives a model a lot of signal, access gives a model a lot of signal, but signal isn't the same as direction. but signal isn't the same as direction. but signal isn't the same as direction. Context engineering is a skill of Context engineering is a skill of Context engineering is a skill of deciding what's relevant for this task deciding what's relevant for this task deciding what's relevant for this task right now and making sure that's what right now and making sure that's what right now and making sure that's what the model is working from. And one the model is working from. And one the model is working from. And one important constraint, more is not always important constraint, more is not always important constraint, more is not always better. There is a name for this now, better. There is a name for this now, better. There is a name for this now, context rot. Groma research tested 18 context rot. Groma research tested 18 context rot. Groma research tested 18 frontier models in 2025 and found every frontier models in 2025 and found every frontier models in 2025 and found every single one gets worse as input length single one gets worse as input length single one gets worse as input length grows. Not some of them, all of them. grows. Not some of them, all of them. grows. Not some of them, all of them. And the degradation starts well before And the degradation starts well before And the degradation starts well before the context window is even close to the context window is even close to the context window is even close to full. A model with a 200k token window full. A model with a 200k token window full. A model with a 200k token window can start losing quality at 50k. More can start losing quality at 50k. More can start losing quality at 50k. More context is not better context. The right context is not better context. The right context is not better context. The right context is. Prompt engineering got the context is. Prompt engineering got the context is. Prompt engineering got the model to understand what you want, model to understand what you want, model to understand what you want, context engineering gets it to context engineering gets it to context engineering gets it to understand what's relevant, but both understand what's relevant, but both understand what's relevant, but both still have the same ceiling. After every still have the same ceiling. After every still have the same ceiling. After every exchange, you're back reading the exchange, you're back reading the exchange, you're back reading the output, deciding what to do next, typing output, deciding what to do next, typing output, deciding what to do next, typing again.

  5. What if AI could just get things done? What if AI could just get things done? Run the notebook, catch what's broken, Run the notebook, catch what's broken, Run the notebook, catch what's broken, fix it, and tell you when it's done, fix it, and tell you when it's done, fix it, and tell you when it's done, while also keeping context better while also keeping context better while also keeping context better organized. Up until now, the AI has just organized. Up until now, the AI has just organized. Up until now, the AI has just been responding to us. We ask, it been responding to us. We ask, it been responding to us. We ask, it answers. answers. answers. Harness engineering changes that. A Harness engineering changes that. A Harness engineering changes that. A harness gives the model tools so we can harness gives the model tools so we can harness gives the model tools so we can actually act. It gives it guardrails to actually act. It gives it guardrails to actually act. It gives it guardrails to keep it safe and feedback loops. keep it safe and feedback loops. keep it safe and feedback loops. Read files, execute code, observe what Read files, execute code, observe what Read files, execute code, observe what happened, react to it. It turns a model happened, react to it. It turns a model happened, react to it. It turns a model that talks into an agent that works. And that talks into an agent that works. And that talks into an agent that works. And not all harnesses are equal. Cloud agent not all harnesses are equal. Cloud agent not all harnesses are equal. Cloud agent and CodeX are opinionated. They handle and CodeX are opinionated. They handle and CodeX are opinionated. They handle context compaction, memory, and tool context compaction, memory, and tool context compaction, memory, and tool orchestration largely behind the scenes. orchestration largely behind the scenes. orchestration largely behind the scenes. Something like Pie, which is a minimal Something like Pie, which is a minimal Something like Pie, which is a minimal agent harness, takes the opposite agent harness, takes the opposite agent harness, takes the opposite approach. Four core built-in tools, a approach. Four core built-in tools, a approach. Four core built-in tools, a system prompt under 1,000 tokens, and system prompt under 1,000 tokens, and system prompt under 1,000 tokens, and full transparency over everything the full transparency over everything the full transparency over everything the agent does. One gives you speed and agent does. One gives you speed and agent does. One gives you speed and convenience, the other gives you control convenience, the other gives you control convenience, the other gives you control and auditability. And neither is wrong.

  6. and auditability. And neither is wrong. and auditability. And neither is wrong. It's basically a dial between autonomy It's basically a dial between autonomy It's basically a dial between autonomy and control. And here is something that and control. And here is something that and control. And here is something that harness does that often gets overlooked. harness does that often gets overlooked. harness does that often gets overlooked. It takes over context management. It takes over context management. It takes over context management. Instead of you deciding what to pass in Instead of you deciding what to pass in Instead of you deciding what to pass in at each step, the harness handles it. at each step, the harness handles it. at each step, the harness handles it. LangChain's docs describe this as LangChain's docs describe this as LangChain's docs describe this as compression isolation and memory working compression isolation and memory working compression isolation and memory working together so the agent can run for hours together so the agent can run for hours together so the agent can run for hours without you manually trimming anything. without you manually trimming anything. without you manually trimming anything. Let me show you a very simple example of Let me show you a very simple example of Let me show you a very simple example of harness engineering in action. My harness engineering in action. My harness engineering in action. My notebook has a bug. One of the cells is notebook has a bug. One of the cells is notebook has a bug. One of the cells is failing. Instead of pasting the error failing. Instead of pasting the error failing. Instead of pasting the error and asking what's wrong, I'm going to and asking what's wrong, I'm going to and asking what's wrong, I'm going to give Cloud agent one instruction and give Cloud agent one instruction and give Cloud agent one instruction and step back. I will also add this Python step back. I will also add this Python step back. I will also add this Python skill that improves how Jupyter skill that improves how Jupyter skill that improves how Jupyter notebooks are written. Run the Netflix notebooks are written. Run the Netflix notebooks are written. Run the Netflix analysis notebook from top to bottom. If analysis notebook from top to bottom. If analysis notebook from top to bottom. If any cells fail, identify the error, fix any cells fail, identify the error, fix any cells fail, identify the error, fix it, and rerun until the entire notebook it, and rerun until the entire notebook it, and rerun until the entire notebook executes cleanly. Watch what's executes cleanly. Watch what's executes cleanly. Watch what's happening. I haven't typed anything happening. I haven't typed anything happening. I haven't typed anything else. It's reading the notebook. That's else. It's reading the notebook. That's else. It's reading the notebook. That's a tool call. Executing it, another tool a tool call. Executing it, another tool a tool call. Executing it, another tool call. Reading the actual error output, call. Reading the actual error output, call. Reading the actual error output, editing the broken cell, rerunning to editing the broken cell, rerunning to editing the broken cell, rerunning to verify the fix. This is harness verify the fix. This is harness verify the fix. This is harness engineering. The harness is a layer engineering. The harness is a layer engineering. The harness is a layer around the model that gives it tools, around the model that gives it tools, around the model that gives it tools, lets it act on a real environment, and lets it act on a real environment, and lets it act on a real environment, and crucially, lets it observe the result crucially, lets it observe the result crucially, lets it observe the result and react to it. It fixed it. I didn't and react to it. It fixed it. I didn't and react to it. It fixed it. I didn't touch a thing after the message. So, in touch a thing after the message. So, in touch a thing after the message. So, in prompt engineering, I got an answer. In prompt engineering, I got an answer. In prompt engineering, I got an answer. In context engineering, I got better code.

  7. context engineering, I got better code. context engineering, I got better code. In both cases, nothing actually ran. I In both cases, nothing actually ran. I In both cases, nothing actually ran. I was still the executor. With a harness, was still the executor. With a harness, was still the executor. With a harness, the model executed, observed the real the model executed, observed the real the model executed, observed the real result, reacted to it, and verified the result, reacted to it, and verified the result, reacted to it, and verified the fix. But, I was still the trigger. I fix. But, I was still the trigger. I fix. But, I was still the trigger. I decided when to start it, and when it decided when to start it, and when it decided when to start it, and when it finished, it stopped and waited for me. finished, it stopped and waited for me. finished, it stopped and waited for me. The data set I'm using gets updated. The data set I'm using gets updated. The data set I'm using gets updated. Kaggle pushes new Netflix titles or Kaggle pushes new Netflix titles or Kaggle pushes new Netflix titles or updates entries often. My analysis needs updates entries often. My analysis needs updates entries often. My analysis needs to stay current. Am I really going to to stay current. Am I really going to to stay current. Am I really going to come back here and kick this off come back here and kick this off come back here and kick this off manually every time? This is where loop engineering would be This is where loop engineering would be a great solution. Let me give you the a great solution. Let me give you the a great solution. Let me give you the clearest definition. Loop engineering is clearest definition. Loop engineering is clearest definition. Loop engineering is designing the system that prompts your designing the system that prompts your designing the system that prompts your AI agent instead of prompting it AI agent instead of prompting it AI agent instead of prompting it yourself. If we stack all four side by yourself. If we stack all four side by yourself. If we stack all four side by side, prompt engineering, you craft the side, prompt engineering, you craft the side, prompt engineering, you craft the perfect message. Context engineering, perfect message. Context engineering, perfect message. Context engineering, you assemble the perfect information or you assemble the perfect information or you assemble the perfect information or context around that message. Harness context around that message. Harness context around that message. Harness engineering, the agent has guardrails, engineering, the agent has guardrails, engineering, the agent has guardrails, feedback loops, skills, and tools so it feedback loops, skills, and tools so it feedback loops, skills, and tools so it can act, not just respond. Loop can act, not just respond. Loop can act, not just respond. Loop engineering, you build a thing that engineering, you build a thing that engineering, you build a thing that triggers all of that automatically while triggers all of that automatically while triggers all of that automatically while you're doing something else entirely. In you're doing something else entirely. In you're doing something else entirely. In Cloud, you can trigger a loop via the Cloud, you can trigger a loop via the Cloud, you can trigger a loop via the {slash} loop command like this.

  8. {slash} loop command like this. {slash} loop command like this. Loop every 50 minutes if the Kaggle Net- Loop every 50 minutes if the Kaggle Net- Loop every 50 minutes if the Kaggle Net- flix data set has new rows or any flix data set has new rows or any flix data set has new rows or any changes in the entries since the last changes in the entries since the last changes in the entries since the last run. Then, rerun the analysis notebook run. Then, rerun the analysis notebook run. Then, rerun the analysis notebook and append the summary of what changed and append the summary of what changed and append the summary of what changed to updates.log. That's it. Cloud now has to updates.log. That's it. Cloud now has to updates.log. That's it. Cloud now has a background task. Every 50 minutes, it a background task. Every 50 minutes, it a background task. Every 50 minutes, it wakes up, checks if the data set has any wakes up, checks if the data set has any wakes up, checks if the data set has any changes, pulls the update if it does, changes, pulls the update if it does, changes, pulls the update if it does, reruns the notebook, and logs what reruns the notebook, and logs what reruns the notebook, and logs what changed. No script, no writing your own changed. No script, no writing your own changed. No script, no writing your own cron job. I describe what I want in cron job. I describe what I want in cron job. I describe what I want in plain language and the loop handles it. plain language and the loop handles it. plain language and the loop handles it. My session stays open. I go work on My session stays open. I go work on My session stays open. I go work on something else and the pipeline stays something else and the pipeline stays something else and the pipeline stays current without me. That's {slash} loop, current without me. That's {slash} loop, current without me. That's {slash} loop, time-triggered. But, there is a more time-triggered. But, there is a more time-triggered. But, there is a more powerful primitive called goal. Loop powerful primitive called goal. Loop powerful primitive called goal. Loop runs on a timer. Goal runs until a runs on a timer. Goal runs until a runs on a timer. Goal runs until a condition is true. condition is true. condition is true. So, I can write So, I can write So, I can write {slash} goal {slash} goal {slash} goal notebook runs end-to-end with no errors notebook runs end-to-end with no errors notebook runs end-to-end with no errors and updates.log contains one new entry and updates.log contains one new entry and updates.log contains one new entry from today's date. And here is something from today's date. And here is something from today's date. And here is something clever about how the agent implements clever about how the agent implements clever about how the agent implements this. It uses a separate evaluator that this. It uses a separate evaluator that this. It uses a separate evaluator that checks whether your condition is checks whether your condition is checks whether your condition is actually met.

  9. actually met. actually met. The worker and the checker are kept The worker and the checker are kept The worker and the checker are kept apart on purpose because whatever just apart on purpose because whatever just apart on purpose because whatever just wrote the code has every reason to wrote the code has every reason to wrote the code has every reason to believe it's good. An independent check believe it's good. An independent check believe it's good. An independent check doesn't. Observe, decide, act, verify, doesn't. Observe, decide, act, verify, doesn't. Observe, decide, act, verify, repeat. That's the loop. Before I send repeat. That's the loop. Before I send repeat. That's the loop. Before I send you off to build loops everywhere, some you off to build loops everywhere, some you off to build loops everywhere, some quick reminders. First, token costs quick reminders. First, token costs quick reminders. First, token costs compound fast. A single agent loop on a compound fast. A single agent loop on a compound fast. A single agent loop on a medium task burns many tokens compared medium task burns many tokens compared medium task burns many tokens compared to a normal chat interaction. Run it on to a normal chat interaction. Run it on to a normal chat interaction. Run it on a schedule, add subagents, let it retry a schedule, add subagents, let it retry a schedule, add subagents, let it retry failures, and that multiplies again. So, failures, and that multiplies again. So, failures, and that multiplies again. So, always set a hard token budget and a always set a hard token budget and a always set a hard token budget and a maximum iteration count before you start maximum iteration count before you start maximum iteration count before you start a loop. Second, a vague goal is a a loop. Second, a vague goal is a a loop. Second, a vague goal is a runaway loop. Make this goal better, may runaway loop. Make this goal better, may runaway loop. Make this goal better, may never stop. The agent can't tell when never stop. The agent can't tell when never stop. The agent can't tell when it's done because you can't tell when it's done because you can't tell when it's done because you can't tell when it's done. Every loop needs a condition it's done. Every loop needs a condition it's done. Every loop needs a condition you can actually verify. Test passed, you can actually verify. Test passed, you can actually verify. Test passed, file exists, column count matches. If file exists, column count matches. If file exists, column count matches. If you can't write a binary check for it, you can't write a binary check for it, you can't write a binary check for it, it's not a loop goal. It is a it's not a loop goal. It is a it's not a loop goal. It is a conversation. Third, loops are not for conversation. Third, loops are not for conversation. Third, loops are not for everything. If the task isn't everything. If the task isn't everything. If the task isn't repetitive, doesn't have a clear done repetitive, doesn't have a clear done repetitive, doesn't have a clear done condition, or requires judgment calls a condition, or requires judgment calls a condition, or requires judgment calls a test can't catch, stay in the harness.

  10. test can't catch, stay in the harness. test can't catch, stay in the harness. Loop engineering earns its complexity Loop engineering earns its complexity Loop engineering earns its complexity only when the work genuinely repeats and only when the work genuinely repeats and only when the work genuinely repeats and the definition of done is crisp. The the definition of done is crisp. The the definition of done is crisp. The tool is real, the leverage is real, just tool is real, the leverage is real, just tool is real, the leverage is real, just don't skip the guardrails. In this don't skip the guardrails. In this don't skip the guardrails. In this video, we went through writing prompts, video, we went through writing prompts, video, we went through writing prompts, managing context, writing with managing context, writing with managing context, writing with harnesses, and writing loops. Each step harnesses, and writing loops. Each step harnesses, and writing loops. Each step didn't replace the one before, it didn't replace the one before, it didn't replace the one before, it wrapped it. The prompt is still inside wrapped it. The prompt is still inside wrapped it. The prompt is still inside the loop. The context is still being the loop. The context is still being the loop. The context is still being assembled on every run. The harness is assembled on every run. The harness is assembled on every run. The harness is still giving the agent its tools, but still giving the agent its tools, but still giving the agent its tools, but the leverage point moved. We went from the leverage point moved. We went from the leverage point moved. We went from crafting a sentence to curating crafting a sentence to curating crafting a sentence to curating information to building an agent to information to building an agent to information to building an agent to designing a system that runs without designing a system that runs without designing a system that runs without you. If this was useful, subscribe. If you. If this was useful, subscribe. If you. If this was useful, subscribe. If you want to help me get promoted, leave you want to help me get promoted, leave you want to help me get promoted, leave a comment with a salary expectation. If a comment with a salary expectation. If a comment with a salary expectation. If you want a more in-depth video on this you want a more in-depth video on this you want a more in-depth video on this concept, let me know. See you in the concept, let me know. See you in the concept, let me know. See you in the next one.

Summary

The main theme is demystifying AI buzzwords by focusing on practical prompt engineering concepts like prompt engineering, context engineering, harness engineering, and loop engineering. Key subjects discussed include effectively communicating with AI through structured prompts and the limitations of one-off questions versus ongoing project context. The takeaway is that understanding these concepts allows for more precise and actionable AI interactions.

View original episode ↗