YouTube2Text

Let Your AI Agent Do ITS OWN Harness Engineering (Here's How) — Transcript

by Cole Medin · 3,571 words · 507 segments · language en · Watch on YouTube

Full transcript

  1. 0:00So, on my YouTube channel this year,
  2. 0:01I've mostly been focusing on AI agents
  3. 0:04for coding. But, what a lot of people
  4. 0:06don't realize, maybe even including
  5. 0:07yourself, is that a lot of these
  6. 0:09strategies that go into making our
  7. 0:11coding agents more reliable over time,
  8. 0:13also translate over very well to other
  9. 0:16kinds of AI agents that we deploy to
  10. 0:18production for automation and business
  11. 0:20use cases. And one of those big ideas is
  12. 0:23harness engineering, making everything
  13. 0:26around the model, like the rules and the
  14. 0:28workflows, better over time. Now, of
  15. 0:30course, you wire agent to get better
  16. 0:32over time. But, what I'm referring to
  17. 0:33specifically here with harness
  18. 0:35engineering is tracking all the mistakes
  19. 0:37that your agent is making in production,
  20. 0:40and then going back retroactively,
  21. 0:41having that conversation with your agent
  22. 0:43to figure out what should we make better
  23. 0:45in your rules and skills so these
  24. 0:47mistakes don't happen again. I teach
  25. 0:49that all the time with harness
  26. 0:50engineering for coding agents, and
  27. 0:52really it's the same thing with your
  28. 0:54production agents. And the thing is this
  29. 0:55translates even better than you would
  30. 0:57think because these days production
  31. 0:59agents for the most part are built just
  32. 1:01like coding agents, where we manage the
  33. 1:03entire harness with a lot of markdown.
  34. 1:05And this keeps things very flexible. The
  35. 1:08quote-unquote old way of doing things
  36. 1:09with agents was a lot more of the
  37. 1:11plumbing directly in the code, like
  38. 1:12creating our Python and TypeScript
  39. 1:14functions for our tools, for example.
  40. 1:16But, now we have our skills as markdown,
  41. 1:18our global rules, like our instructions
  42. 1:20on MD, our memories. This should look
  43. 1:22very familiar. It's a very similar sort
  44. 1:24of harness setup to a coding agent. And
  45. 1:26this translation works so well that all
  46. 1:28the components of agentic engineering in
  47. 1:30our harness, they really have a
  48. 1:31one-to-one mapping with our agents in
  49. 1:33production. Like we have our rules,
  50. 1:36which for a traditional agent is the
  51. 1:37exact same thing as a system prompt. We
  52. 1:40have our sub-agents, that's the same
  53. 1:41thing as multi-agent workflows where
  54. 1:43we're doing any kind of delegation. We
  55. 1:45have MCP tools for our connections.
  56. 1:48Skills are our workflows, replacing a
  57. 1:50lot of our traditional tools. And then
  58. 1:52we have hooks for our guardrails. If you
  59. 1:54want to monitor or block things for each
  60. 1:57tool call or the start or end of
  61. 1:58conversations, we have our guardrails
  62. 2:00for that. And so today, I'm not only
  63. 2:02going to show you an example of building
  64. 2:04out this harness, but also improving it
  65. 2:06over time with our two core loops. We
  66. 2:08have the main memory of the agent, and
  67. 2:10then also improving it retroactively by
  68. 2:12looking at the traces as we are
  69. 2:14monitoring the agent in production
  70. 2:16talking to real users. That is the
  71. 2:18biggest goldmine of information that we
  72. 2:20can't ignore. Most people do. And so
  73. 2:22we'll get into all of this, but also I
  74. 2:23just want to show you at a high level
  75. 2:25how do we build an agent that takes on
  76. 2:27the coding agent harness. Because the
  77. 2:29thing is, as we create our markdown
  78. 2:31documents for our skills and our rules
  79. 2:33and everything, we need some kind of
  80. 2:34system that actually bundles it and
  81. 2:36connects it together when we deploy the
  82. 2:38agent to production. Now, for this
  83. 2:40platform, you can build it yourself if
  84. 2:42you want to manage your own deployment
  85. 2:43and harness engineering pipelines.
  86. 2:45That's totally fine. But a lot of the
  87. 2:47time it's more practical to use a
  88. 2:48platform that manages this for you. And
  89. 2:51so that's why for all these demos, I'm
  90. 2:52going to be using LangChain's managed
  91. 2:54deep agents, which sets up all this for
  92. 2:56us in the LangSmith. I've seen this work
  93. 2:59time and time again in production. And
  94. 3:01as we go through everything, you'll see
  95. 3:02how this is very universal. All the
  96. 3:04strategies apply no matter how you're
  97. 3:06building these agents. And for a quick
  98. 3:08shoutout, thanks to LangChain for
  99. 3:09working with me on this video. It is
  100. 3:11about time that I've collaborated with
  101. 3:12them because I'm using their platforms
  102. 3:14like managed deep agents all of the
  103. 3:16time. And for a super quick throwback
  104. 3:18here, this is one of the very first
  105. 3:19videos I put on my YouTube channel over
  106. 3:22two years ago when I first started my
  107. 3:24content. I was building AI agents coding
  108. 3:27them by hand with LangChain as my
  109. 3:29framework. And so it's always had a
  110. 3:31special place in my heart. I continue to
  111. 3:32use them because LangChain has always
  112. 3:34stayed on the cutting edge, especially
  113. 3:36now with managed deep agents helping you
  114. 3:38deploy your agents in the sort of coding
  115. 3:40agent fashion. And then the other thing
  116. 3:42that they have is the tracing and
  117. 3:44metrics to help us really get into the
  118. 3:46harness engineering figuring out where
  119. 3:47our agent is going wrong, and even
  120. 3:50giving us suggestions that we can
  121. 3:51automatically apply. So we'll talk about
  122. 3:53this once we get into the different
  123. 3:54improvement loops for our harness as
  124. 3:56well.
  125. 3:57Okay, cool. So I want to quickly show
  126. 3:58you what it looks like to build these
  127. 4:00kinds of agents now with LangChain's
  128. 4:02managed deep agents, and then we'll get
  129. 4:03into the learning loops, and I'll even
  130. 4:05give you a live demo. So, kind of like
  131. 4:07what I was saying earlier, back when we
  132. 4:09used to build our agents a year or two
  133. 4:10ago, it was a lot of that plumbing in
  134. 4:13the code. I mean, we had to write so
  135. 4:16much code to build out our guardrails
  136. 4:17and our tools and hook in our system
  137. 4:19prompt and everything. But now take a
  138. 4:21look at this agent.py file. It is 30
  139. 4:24lines of code. That is all it takes to
  140. 4:26create the definition for our agent, and
  141. 4:28this includes guardrails, sub-agents,
  142. 4:31all the tools that we have, the skills
  143. 4:32and the instructions, because all this
  144. 4:34is simply defined as markdown documents
  145. 4:37now. So, with some of the agent
  146. 4:38definition here, we are writing into
  147. 4:40code. There's a little bit of that
  148. 4:41plumbing still, but for the most part it
  149. 4:43works like coding agents, where things
  150. 4:45are picked up automatically. So, we have
  151. 4:47our instructions.md. As long as it's at
  152. 4:49the root of the agent folder, kind of
  153. 4:51like our claw.md or agent.md with the
  154. 4:54coding agent, then it's going to be
  155. 4:55picked up automatically. We have our
  156. 4:56skills in the skills folder, just like
  157. 4:58we have our, you know, dot claw or dot
  158. 5:00codex folder, whatever it is. And so,
  159. 5:03all these things when we package it up
  160. 5:05together to run it in development
  161. 5:06locally or deploy to production,
  162. 5:08LangChain handles stitching everything
  163. 5:10together behind the scenes. So, it's
  164. 5:12very easy for us to build and manage our
  165. 5:13agents, and it's all very flexible. So,
  166. 5:15if we're not happy with how the agent is
  167. 5:17performing, then we simply just change
  168. 5:19these markdown documents exactly like we
  169. 5:21do for the system evolution, as I call
  170. 5:23it, for our coding agents. There's also
  171. 5:25a lot more behind the scenes with the
  172. 5:27evals and learnings, making our harness
  173. 5:28better over time. So, let's get into
  174. 5:30that now. And I'll even give you a live
  175. 5:32demo here with the first loop, which is
  176. 5:34the memory for the agent. So, no matter
  177. 5:37the agent you have deployed to
  178. 5:38production, you're going to want a
  179. 5:40system like this. LangChain does it
  180. 5:41really well. There's a lot of
  181. 5:42inspiration we can take from this setup,
  182. 5:44and I'll show you with the live demo as
  183. 5:46well. We essentially just need a way for
  184. 5:48our agent to learn the lessons as it's
  185. 5:51running in production. And that does
  186. 5:52mean escalating some things to a human.
  187. 5:55So, whenever someone is talking to our
  188. 5:57agent and our agent is struggling, we
  189. 5:59want it to be able to recognize that and
  190. 6:01escalate the uncertainty. And so, we
  191. 6:03have some kind of inbox where we're
  192. 6:04managing the different things the agent
  193. 6:06is uncertain with. We give it the right
  194. 6:08answer and we make sure the agent writes
  195. 6:10that down as a lesson. So we have some
  196. 6:12kind of context hub as LangChain calls
  197. 6:15it where we're storing these memories.
  198. 6:16It can always retrieve that later so it
  199. 6:18can recognize like, "Oh yeah, this
  200. 6:19situation I handled before. This is how
  201. 6:22the human team corrected me. So I'm
  202. 6:24going to give the right answer this
  203. 6:25time." And this is so important because
  204. 6:28especially when we're first deploying
  205. 6:29our agent out to real users, we don't
  206. 6:31really know the gaps in its knowledge
  207. 6:33and process. And so LLMs, yes, they
  208. 6:36hallucinate, but they do a surprisingly
  209. 6:38good job at surfacing uncertainties. So
  210. 6:40we can correct these things and have
  211. 6:42these lessons build up over time. And of
  212. 6:44course, we have an efficient retrieval
  213. 6:46strategy here. So it's not like we're
  214. 6:47just dumping in all these lessons into
  215. 6:49context like our main instructions. Now
  216. 6:51of course, we can use these lessons to
  217. 6:53improve our instructions. We'll get into
  218. 6:55that with the second loop. But right
  219. 6:57here, it's all about building up a
  220. 6:59knowledge base of how we're handling the
  221. 7:01key situations with customers and users
  222. 7:03because generally there's a lot of
  223. 7:05commonalities between how people are
  224. 7:07using our agent. And so this knowledge
  225. 7:09base that we start to build up in what
  226. 7:10LangChain calls the context hub helps
  227. 7:13significantly. And as the agent gets
  228. 7:15better and better, there's also just
  229. 7:16less that is escalated over time. So
  230. 7:18it's not like this continues to become a
  231. 7:20huge burden for the humans managing the
  232. 7:22agents. So here we have the production
  233. 7:25bundle for my agent here in managed deep
  234. 7:27agents. And so within the memory folder,
  235. 7:29there's a couple of things that we have
  236. 7:30here. First of all, we have all of the
  237. 7:32cases, things where the agent was
  238. 7:34uncertain and it escalated to me in the
  239. 7:36team inbox that I'll show you in a
  240. 7:38little bit. And so I make that
  241. 7:39correction and then it's going to
  242. 7:40remember those things both per user and
  243. 7:43it's going to build up this sort of
  244. 7:44internal agents.md, the core rules that
  245. 7:47are all learned from the lessons that
  246. 7:49I've taught it with the escalations. All
  247. 7:51right, so let me show you this in action
  248. 7:53now. So this is a custom dashboard I
  249. 7:55built with a demo version of a real
  250. 7:58agent that I'm working on, the Dynamis
  251. 8:00member help desk. And so this here is
  252. 8:02proof. I've been running this and
  253. 8:03testing it before I made this video that
  254. 8:05we We able to improve the agent pretty
  255. 8:07autonomously over time. I'm just going
  256. 8:09to give you one example of this here.
  257. 8:11So, I kept the data set simple. I kept
  258. 8:13everything simple here just for the
  259. 8:14demo. And so, I have a help desk here
  260. 8:17where I've mocked different members of
  261. 8:18the community asking different questions
  262. 8:20about Arcan, my course content, whatever
  263. 8:22it is. And so, this is Nina. I'm going
  264. 8:24to act like I am a Nina here with the
  265. 8:26question to my support agent. So, "Hi
  266. 8:28Amina, I committed a fix my plan.md
  267. 8:31command locally and I ran the Arcan
  268. 8:33workflow, but the run used my old
  269. 8:34command text. I know that seems oddly
  270. 8:36specific, but this is a real question
  271. 8:39that I received about Arcan a couple of
  272. 8:41weeks ago." And so, all the things here
  273. 8:42that I've tested with is actually based
  274. 8:44on real questions that I've gotten. And
  275. 8:45so, the help desk agent is going to
  276. 8:47answer in a second here, but as you'll
  277. 8:49see, it isn't going to be confident in
  278. 8:51its answer. So, as you saw, it took a
  279. 8:53little bit to start thinking just cuz I
  280. 8:55had to compile the agent locally, but it
  281. 8:57only took about 10 seconds for it to do
  282. 8:59everything after, including searching
  283. 9:01the memories for this specific person,
  284. 9:04loading the skill for the diagnose
  285. 9:05setup, and then also updating the
  286. 9:07memories for this person. So, we have
  287. 9:09individual user memories that I'll show
  288. 9:11you more in a little bit as well.
  289. 9:13But, here's the most important thing.
  290. 9:15The help desk said, "I don't have enough
  291. 9:17yet to say for sure." So, it's still
  292. 9:19going to try to help. We don't want the
  293. 9:21agent to just block and wait for a human
  294. 9:23entirely, but it surfaced the
  295. 9:25uncertainty. And then take a look at my
  296. 9:27team inbox now. It was four right before
  297. 9:30I had this conversation. Now it's moved
  298. 9:31up to five because there's something
  299. 9:33that was just escalated to me. So,
  300. 9:35here's the question from the person. And
  301. 9:37then here's the answer from the help
  302. 9:39desk. And then I have to confirm the
  303. 9:41fix. And so, I can either correct the
  304. 9:43agent here or say that it did it right.
  305. 9:45Either way, it's going to update its
  306. 9:47memories. It's going to learn a lesson
  307. 9:49so it's confident the next time. So, for
  308. 9:51this case, I have the solution already.
  309. 9:52Arcan creates the work trees from origin
  310. 9:54main. So, the solution is to run get
  311. 9:56push and rerun. So, I'm going to send
  312. 9:57this into the agent, host the confirmed
  313. 10:00fix. And so, now it's going to learn a
  314. 10:02lesson from that. So, I'll come back
  315. 10:04once we have it. And boom, just 10
  316. 10:05seconds later, we have the confirmation
  317. 10:07that we have a new shared memory. We
  318. 10:09have learned a lesson. So, it updated
  319. 10:11that core agents.md file in the memory
  320. 10:14folder like I showed you earlier, and
  321. 10:15then also the private memory for Nina.
  322. 10:18This is the important one though,
  323. 10:19because now going forward, if someone
  324. 10:20else has a similar issue, it's going to
  325. 10:23be a lot more confident in its answers.
  326. 10:25So, let me show you that, too. So, back
  327. 10:27over in my chats here, I'm going to act
  328. 10:28as a different person now. So, I'm Omar.
  329. 10:30My Arkon run finished green and open a
  330. 10:32PR, but the diff is missing three
  331. 10:34commits I made this morning. Is this a
  332. 10:36bug or what? And for this, it's not
  333. 10:38quite the same as Nina's problem, but it
  334. 10:40is similar enough where it's going to be
  335. 10:41able to learn from that lesson. So, I
  336. 10:43also want to show you something that's
  337. 10:45not so cheesy where it's like literally
  338. 10:46the same exact problem, just to show
  339. 10:48that the agent is able to extrapolate
  340. 10:50based on memories. And so, there we go.
  341. 10:52This time it didn't say it was
  342. 10:54uncertain. It said likely not a bug.
  343. 10:55Here's exactly how Arkon works, right?
  344. 10:57This is the lesson that we just taught
  345. 10:59it, and that let it to giving a very
  346. 11:01solid answer now. If I go into the
  347. 11:03memory tab that's hooked directly into
  348. 11:05LangChain, I can take a look at that
  349. 11:06cases folder right here, and sure
  350. 11:09enough, we've got our new memory. Arkon
  351. 11:11builds the run work tree, so the members
  352. 11:12fix was get pushed and then rerun Arkon
  353. 11:14workflow run. There we go. This is the
  354. 11:16exact same thing that we're looking at
  355. 11:17here within the cases, right within
  356. 11:19managed deep agents. And then also, if
  357. 11:21we go into the context hub, we can see
  358. 11:23the per user memories as well. Like
  359. 11:25these are the memories for just Nina.
  360. 11:27And so, we also have that separation
  361. 11:29that's guaranteed with the guardrails in
  362. 11:31the agent, so we have per user memories
  363. 11:33that never have any overlap. And it's
  364. 11:34not like users can view other users'
  365. 11:36memories. Cool. So, the last thing I
  366. 11:38want to show you now is the second loop.
  367. 11:40We've talked a lot about the memory. And
  368. 11:43this is an important part to our context
  369. 11:45hub, but it really isn't the main part
  370. 11:47of our harness. The per case lessons,
  371. 11:50it's a good resource for the agent to
  372. 11:52search through when it needs, but we
  373. 11:54have the higher level harness, which is
  374. 11:56our core workflows and instructions. And
  375. 11:59we want to update these over time as we
  376. 12:01are learning from our lessons and the
  377. 12:03other traces that we have with our
  378. 12:05production data. And so, that's what I
  379. 12:07want to show you now. This is the other
  380. 12:08part of managed deep agents. This is the
  381. 12:10engine. Using LangSmith under the hood
  382. 12:13for all the trace data, but then using
  383. 12:15the engine to collect that and start to
  384. 12:17make suggestions for how we can improve
  385. 12:20our agent based on the failures that
  386. 12:22we're seeing with real data. So, this is
  387. 12:24a real example of the failure that came
  388. 12:26from my production runs. And so, we have
  389. 12:29the description at the top here getting
  390. 12:30quite detailed. If I'm interested, we
  391. 12:32have the evidence with the LangSmith
  392. 12:34trace. I can go into the exact
  393. 12:36conversation and see what the model was
  394. 12:38doing when this issue happened. And then
  395. 12:40my favorite part is at the bottom we
  396. 12:42have the proposed fix. All of this
  397. 12:44running behind the scenes with LangSmith
  398. 12:46engine. And so, it proposes, "Here's
  399. 12:48what we should change to the
  400. 12:49instructions.md."
  401. 12:51This is just like system evolution with
  402. 12:53our coding agents where it's surveying
  403. 12:55the entire harness, our rules and
  404. 12:57guardrails and instructions and
  405. 12:59everything. It's figuring out, "What
  406. 13:00should we adjust so this kind of issue
  407. 13:02doesn't happen again?" So, here is our
  408. 13:04proposed fix. It's nice and concise cuz
  409. 13:07I also don't want to just like bloat my
  410. 13:08rules by shoving a bunch of new context
  411. 13:10here. And then I can click apply and
  412. 13:13it'll immediately apply this to my
  413. 13:15production agent. So, I'm approving
  414. 13:17things and having it fix itself in real
  415. 13:19time, but only based on the fixes that I
  416. 13:22am overseeing, right? I don't really
  417. 13:23want my agent to autonomously improve
  418. 13:25itself because then I lose control of my
  419. 13:28agent and I don't really know the
  420. 13:29direction it's heading. That's really
  421. 13:31the big theme with everything here. We
  422. 13:33always want the agent to be surfacing
  423. 13:35and applying fixes automatically, but we
  424. 13:37still need to be in a loop approving
  425. 13:39things. So, if we go to the context sub,
  426. 13:41all of the memories that we've been
  427. 13:43creating for our agent for individuals,
  428. 13:44the main lessons that we're learning,
  429. 13:46we're always a part of every single one
  430. 13:48of these. And going into our skills and
  431. 13:50instructions, everything that we change
  432. 13:51here, again, we approve before anything
  433. 13:54is changed. Just like when we're working
  434. 13:56with our coding agents, generally we'll
  435. 13:57create pull requests to update our rules
  436. 14:00or our skills. We're doing the same kind
  437. 14:02of thing here, but just directly in
  438. 14:04LangSmith with managed deep agents as
  439. 14:06our platform to do so. And so, no matter
  440. 14:08how you end up doing this sort of
  441. 14:09harness engineering for your production
  442. 14:11agents, you need a platform where you
  443. 14:13have the trace data and you have the
  444. 14:16dashboard for you to approve things as
  445. 14:18your agent is working and surfacing
  446. 14:19thing. And continuing with that pull
  447. 14:21requests for a coding agent analogy, we
  448. 14:23literally have the commits right here in
  449. 14:25managed deep agents. And so, I can go
  450. 14:27through each one of these and see what
  451. 14:29exactly the different parts of my
  452. 14:30harness look like here. I can promote
  453. 14:32different versions, roll things back if
  454. 14:34I need. So, it's also not the end of the
  455. 14:35world if we make our agent worse by
  456. 14:38applying the fixes that it's proposing.
  457. 14:40We have full control of our system here.
  458. 14:42It's also incredibly easy to deploy this
  459. 14:44anywhere. Like I've even deployed it to
  460. 14:46my Slack environment, so I can talk to
  461. 14:48the managed deep agent right here.
  462. 14:50Now, of course, I have worked with much
  463. 14:52larger data sets before, but for just
  464. 14:54for this demonstration, I had a set of
  465. 14:5614 questions where the initial agent
  466. 14:58that I created with the first version of
  467. 15:00rules and skills and everything, it only
  468. 15:01got four out of the 14 questions right.
  469. 15:04But, after I went through the learning
  470. 15:05process of applying lessons, using the
  471. 15:07LangSmith traces with the engine to
  472. 15:09apply its suggested improvements, I got
  473. 15:11to 13 out of 14 right. So, LLMs aren't
  474. 15:15always going to be perfect. It's not
  475. 15:16going to be 100% of the time. You can
  476. 15:18get really close though, and we're using
  477. 15:20both of these loops to get there. So,
  478. 15:22that is how you let your agent do its
  479. 15:24own harness engineering with you still
  480. 15:26in the loop approving everything. And
  481. 15:28so, I hope this video showed you the
  482. 15:29power of LangChain's managed deep
  483. 15:31agents, but just also generally the
  484. 15:33high-level ideas here for how we want to
  485. 15:35engineer our agents that we're deploying
  486. 15:37to production. Just taking all these
  487. 15:39ideas from coding agents, so what makes
  488. 15:41them work so well. And the biggest
  489. 15:43lesson here is harness engineering is
  490. 15:44not a one-time job, and that's what
  491. 15:46managed deep agents helps with. It's
  492. 15:48giving your agent a bespoke harness
  493. 15:50where you can use any model, and then
  494. 15:51layering on top the LangSmith engine, so
  495. 15:53you can use LangSmith to keep improving
  496. 15:55your harness. All the while, you
  497. 15:57maintaining full control. And so, I'll
  498. 16:00have a link in the description to try
  499. 16:01out LangSmith. You get $50 in credits if
  500. 16:03you use the code Cole M. And thanks to
  501. 16:06LangChain for working with me on this.
  502. 16:07And so, if you appreciate this video,
  503. 16:09you're looking forward to more things on
  504. 16:11agentic engineering and harness
  505. 16:12engineering, I would really appreciate a
  506. 16:14like and a subscribe. And with that, I
  507. 16:16will see you in the next video.

About this transcript

This page contains the full transcript of Let Your AI Agent Do ITS OWN Harness Engineering (Here's How) by Cole Medin, generated from the public captions YouTube serves with the video. The transcript has 3,571 words across 507 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.