YouTube2Text

How to Move AI Agents from Prototype to Production — Transcript

by n8n · 3,557 words · 498 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Getting an AI agent to work on your
  2. 0:01laptop is the easy part. Getting it to
  3. 0:03work for real customers every day is a
  4. 0:05different job. So today I'm showing you
  5. 0:07how to move AI agents from prototype to
  6. 0:09production with N. And for that I built
  7. 0:11the same support agent twice. This is
  8. 0:13the prototype. It answers customer
  9. 0:15support messages. And when I tested it
  10. 0:17works every time. And this is the
  11. 0:19production. The same agent ready for
  12. 0:21real customers. It does the same job. It
  13. 0:24just has a lot more around it. Now why
  14. 0:26all the extra parts you ask? Because the
  15. 0:28simple version on the left breaks as
  16. 0:31soon as real people use it. A customer
  17. 0:33writes something you never planned for.
  18. 0:35AI sends back an answer with a piece
  19. 0:36missing. It gets stuck and tries the
  20. 0:38same thing a 100 times or it gives
  21. 0:40someone a refund they shouldn't get. In
  22. 0:42this video I'll show you six fixes that
  23. 0:44turn the left side into the right side.
  24. 0:45And I'll build each one in nan step by
  25. 0:48step. Step one, split the agent into
  26. 0:50smaller parts. Right here I have the
  27. 0:52prototype example. It's basically a
  28. 0:54support agent for online shop that sells
  29. 0:56coffee gear. And if you read through the
  30. 0:58system prompt, the instructions that I'm
  31. 1:00giving over to the agent, you'll see
  32. 1:01that I'm giving it a lot of context.
  33. 1:04There's refund policy, shipping times,
  34. 1:06opening hours, and this is a great
  35. 1:08example of what not to do because you'll
  36. 1:10find yourself in trouble once you need
  37. 1:12to maintain this agent. At the end of
  38. 1:14the day, what you want to do with an
  39. 1:15agent is provide it ways that it fetch
  40. 1:17for context to accomplish a task. So,
  41. 1:20initially it might seem like just
  42. 1:21placing all that context inside of the
  43. 1:23system prompt might be a good idea, but
  44. 1:25you'll see in just a bit why it's not.
  45. 1:27I've also given this agent two tools.
  46. 1:29So, one of them can run any database
  47. 1:31query and the other tool would
  48. 1:32effectively send the refund. So, we're
  49. 1:34just using a dummy JavaScript here, but
  50. 1:36it should work for our example. So,
  51. 1:38let's test this agent. To do so, click
  52. 1:40this button up here, send your prompt,
  53. 1:42and this prompt is specific to an
  54. 1:44example that should work with how this
  55. 1:47agent is configured. Notice that it's
  56. 1:49successfully using all the tool calls.
  57. 1:50And now it correctly answered back the
  58. 1:53user with the refund for the
  59. 1:55corresponding order processed. Now let's
  60. 1:58see what happens if a user makes a
  61. 1:59question that you weren't prepared for.
  62. 2:01And remember, we're building an AI agent
  63. 2:03here. It should be flexible, dynamic
  64. 2:05enough to give the user an answer for
  65. 2:08any question. If it doesn't have enough
  66. 2:09context to answer them, it should be
  67. 2:11able to ask a human before answering or
  68. 2:14give a fallback answer, ensuring that
  69. 2:16the user gets a response. So, there it
  70. 2:18is. Unfortunately, our policy doesn't
  71. 2:21cover accidental damage. Although it
  72. 2:23tried to give an answer here, it's not
  73. 2:24accurate. We didn't tell it any of this
  74. 2:27anywhere in the instructions. So, it's a
  75. 2:29madeup answer that we probably don't
  76. 2:31want. And also, if you're not adding the
  77. 2:33correct tools to fetch for context,
  78. 2:35someone could just ask for a refund
  79. 2:37after the 30-day policy and get the
  80. 2:40refund. In this example, I tried to do
  81. 2:41that, but maybe because I mentioned 3
  82. 2:43months, it got up to me and didn't allow
  83. 2:45the refund. But still, you might test
  84. 2:47this 20 times and only the 21st time,
  85. 2:50the agent will randomly select and apply
  86. 2:52the refund. And that's why we need to
  87. 2:54set everything up so the agent isn't
  88. 2:55always fully in control of things that
  89. 2:57are more important. Another example is
  90. 2:59just prompt injection. I can tell it
  91. 3:01that I'm the store manager and make the
  92. 3:03agent do something in behalf of the
  93. 3:05manager while not being the manager. It
  94. 3:08did fail this time, but what guarantees
  95. 3:09that a future attack won't be
  96. 3:11successful? And honestly, this system
  97. 3:13prompt is quite small. If you have to
  98. 3:14change a policy, for example, how would
  99. 3:16you do that if it's this big or even
  100. 3:19like this with maybe hundreds of lines
  101. 3:22of instructions? And whenever you do
  102. 3:23find it and change that, who guarantees
  103. 3:25that that change won't affect the way
  104. 3:28that the agent works and force you to
  105. 3:30check the entire agent to see what
  106. 3:31broke? So what do we do here? We split
  107. 3:33it up. A normal workflow receives the
  108. 3:35customer's message, flux up the
  109. 3:37customer, and sends the refund. The
  110. 3:39agent only does the thinking. Read the
  111. 3:41message, look at the orders, and decide
  112. 3:43what to do. Here's a simple rule. The
  113. 3:45agent decides, and workflows do the
  114. 3:47work. The agent figures out what the
  115. 3:49customer wants and which tool to use.
  116. 3:51The actual steps like looking up an
  117. 3:53order or sending a refund each live in
  118. 3:56their own small workflow which I can
  119. 3:58test and change on its own. The same
  120. 4:00goes for information that changes often
  121. 4:02like prices, policies, or opening hours.
  122. 4:06If it's pasted into the instructions,
  123. 4:08every update means editing the agent. If
  124. 4:10the agent looks it up instead, I just
  125. 4:13update the information and the next
  126. 4:15answer uses it. Now, this is how your
  127. 4:17production agent should look like. First
  128. 4:18of all, knowledge. In here is where
  129. 4:20you'd place something like the refund
  130. 4:22policy. This can be a CSV, a PDF
  131. 4:24markdown, or just plain text. Now,
  132. 4:26whenever you want to update the refund
  133. 4:28policy or any other similar files, you
  134. 4:30could do so from the knowledge base
  135. 4:32inside of this section of the agent,
  136. 4:34which now removes the need to go through
  137. 4:35that huge block of instructions and is
  138. 4:38also a nice guide for the agent to only
  139. 4:40access this whenever it actually needs
  140. 4:42that information. That being said, to
  141. 4:44make sure the agent knows that it could
  142. 4:46fetch for this refund policy, we can add
  143. 4:48a skill. So this skill is called handle
  144. 4:51a complaint. The when to use this skill
  145. 4:53description says it all. So use when the
  146. 4:55customer is unhappy, a damaged, missed
  147. 4:58or wrong item, a late delivery or a
  148. 5:00refund request. This points it to the
  149. 5:03refund policy as well as gives further
  150. 5:06instructions of how to use that policy.
  151. 5:09So again, now the only thing that goes
  152. 5:10inside of the system prompt for your
  153. 5:12agent is this description so that it
  154. 5:14then grabs the necessary context to
  155. 5:16handle this situation. And by the way,
  156. 5:18this is a quick demonstration for a
  157. 5:19support agent. It could have much more
  158. 5:21skills here to deal with different
  159. 5:23support agent tasks as well as different
  160. 5:26files inside of the knowledge base.
  161. 5:28Another way to give tools to your agent
  162. 5:29is inside of capabilities. This allows
  163. 5:32it to effectively run a workflow inside
  164. 5:35of your nan instance. For example, here
  165. 5:38I added the nan motion demo get shipping
  166. 5:41status. I can click on this button right
  167. 5:42here and it'll take me to that workflow
  168. 5:44which if I just click on execute all it
  169. 5:47does is run this JavaScript node which
  170. 5:49simulates how it would work in
  171. 5:50production. But this already screams at
  172. 5:52the idea that you don't need to test
  173. 5:53your AI agent every single time for
  174. 5:55every single part of the agent
  175. 5:57implementation. For example, searching
  176. 6:00for data inside of the database. You can
  177. 6:02have that sub workflow and test these
  178. 6:04nodes without running the main agent
  179. 6:06every single time. I can just add a
  180. 6:08dummy data up here. Let's pin that
  181. 6:10there. of order 4431. Save it. And now
  182. 6:14execute it. I'll get a response back. So
  183. 6:17there's the output. It could have also
  184. 6:20been a database lookup or any other way
  185. 6:22to fetch for this specific data. Before
  186. 6:24we test the agent, let me show you the
  187. 6:26refund policy which clearly says that
  188. 6:28the refunds are possible within 30 days.
  189. 6:30Let's check if it successfully uses that
  190. 6:33information. We can already see from the
  191. 6:34tool calls that it successfully loaded
  192. 6:37the skill. It understood it needed to
  193. 6:38use it. And then from that skill, it
  194. 6:40found the file which is inside of the
  195. 6:43knowledge base. Read the file and now
  196. 6:45answers us based on the refund policy
  197. 6:48that now it has context to. And there it
  198. 6:50is. Since you reported the damage within
  199. 6:5230-day refund window, we're issuing a
  200. 6:54full refund. And now we'll just change
  201. 6:56the refund policy to 14 days. Let's
  202. 6:58upload that and send the same message.
  203. 7:01And there it is. The action now is
  204. 7:02escalate. The refund amount is clearly
  205. 7:04zero. And the reply text includes that
  206. 7:07our refund window is 14 days. As you can
  207. 7:10see, the fix for this was specifically
  208. 7:12inside of the knowledge base for refund
  209. 7:14policy. So remember, split your agents
  210. 7:17into smaller parts. Step two, make the
  211. 7:19agents answers predictable. You might
  212. 7:21already know this, but a good way to
  213. 7:22make your agents predictable is by
  214. 7:24having it answer with JSON. To do that,
  215. 7:27just toggle on the require specific
  216. 7:28output. And here is where you'll
  217. 7:30instruct how you want the output schema
  218. 7:33to be like. We have five main parameters
  219. 7:35here. The intent which is what the
  220. 7:37customer wants, order ID, the action,
  221. 7:39and we've seen all of this before in the
  222. 7:41previous example where in the first
  223. 7:43attempt when it submitted the refund,
  224. 7:45this was the action used, and then when
  225. 7:47it didn't apply the refund, it went with
  226. 7:49escalate. We also saw the refund amount
  227. 7:51and the reply text. So these five
  228. 7:54parameters are very important for our
  229. 7:56overall workflow, not only the agent.
  230. 7:58And although we have that added to the
  231. 8:00agent, it may not respond in that
  232. 8:02specific structure. And here is where we
  233. 8:04check for that valid output. This way we
  234. 8:07can handle two errors. One that can
  235. 8:08happen inside of the agent for whichever
  236. 8:10reason and that needs to be handled. So
  237. 8:13the error stream guarantees that won't
  238. 8:15go silent and will actually receive a
  239. 8:17message in Slack saying that there was
  240. 8:19an error. And if it didn't have a valid
  241. 8:21output, this would still be a success.
  242. 8:24So here is where we validate that. If
  243. 8:26it's not a successful output, it then
  244. 8:29also triggers a message to Slack. Let's
  245. 8:31test this workflow. Hitting execute now.
  246. 8:34Going over to the terminal since it's a
  247. 8:36web hook. And pasting this curl in. Let
  248. 8:38me hit enter. Just got a message back
  249. 8:40saying the workflow has started. And
  250. 8:42that's it. All of those five parameters
  251. 8:44were successfully validated and went
  252. 8:46through the entire pipeline with
  253. 8:48success. Ultimately leading to this log
  254. 8:50run down here. Now watch what happens if
  255. 8:52I turn off the require specific output
  256. 8:54format. Let's toggle this off. Hit
  257. 8:56execute and send a new curl. Workflow
  258. 8:59has started. But as you may see, as soon
  259. 9:02as it hit the valid output node, it went
  260. 9:04through the false route. So it's now
  261. 9:06successfully preventing it from silently
  262. 9:08having an error without anyone being
  263. 9:10aware of it. AI models don't promise a
  264. 9:12format. They usually give you what you
  265. 9:14asked for and usually is fine in a demo.
  266. 9:17But with real customers, the one time it
  267. 9:19adds an extra sentence is the time your
  268. 9:21refund step gets no order number. Step
  269. 9:24three, put a cap on loops and costs. An
  270. 9:26agent works in a loop. It thinks, use
  271. 9:29the tool, looks at the result, and
  272. 9:31decides whether to go again. Most of the
  273. 9:33time, it stops after two or three
  274. 9:35rounds. But if a tool keeps giving back
  275. 9:37something it doesn't expect, it keeps
  276. 9:39trying, and you pay for every single
  277. 9:41round. So, I set limits, a maximum
  278. 9:43number of rounds and a maximum spend for
  279. 9:46each conversation. If it hits a limit,
  280. 9:48it stops. And I handle that like any
  281. 9:50other error. You can find the
  282. 9:51configuration for that right here. I can
  283. 9:53change the maximum number of iterations
  284. 9:55per agent by going over to settings,
  285. 9:57scrolling down, and here where it says
  286. 9:59100, I can change it over to eight, for
  287. 10:02example, for a support agent. Now, be
  288. 10:03aware that each agent you're building
  289. 10:05has a specific case. For a support
  290. 10:07agent, it probably doesn't need to use
  291. 10:09that much tools, but a financial agent
  292. 10:12that does multiple calculations and
  293. 10:14would require tool usage multiple times
  294. 10:17might need a much bigger number of max
  295. 10:20iterations. Let's set this to two and
  296. 10:22I'll quickly show you what happens if
  297. 10:24the agent goes past the max number of
  298. 10:27iterations. All right, apparently it
  299. 10:29already executed two tool calls and then
  300. 10:31when it almost executed the third one,
  301. 10:32it got that warning. the agent has
  302. 10:34reached the maximum number of iterations
  303. 10:36and has stopped. Now, as for a cap on
  304. 10:38the cost, you can scroll up here where
  305. 10:40it says cost cap per session. And
  306. 10:42clicking here will allow you to decide
  307. 10:44what is that maximum cost. And we can
  308. 10:47also define a monthly budget that the
  309. 10:49agent can spend. Setting the budget
  310. 10:51alert to 80% guarantees that we'll get
  311. 10:53an alert for that before running out of
  312. 10:55budget and leading to the agent being
  313. 10:58offline. And while we're in advance, you
  314. 11:00can also set up the maximum parallel sub
  315. 11:03aents as well as tool call concurrency,
  316. 11:06which are also ways to cap and have a
  317. 11:07better control of your agent. Another
  318. 11:09way to save money, not every message
  319. 11:11needs your smartest, most expensive
  320. 11:13model. Where's my order is a simple
  321. 11:15lookup. A long complaint about a broken
  322. 11:17item and a missing refund needs more
  323. 11:20thinking. So, a cheap model handles the
  324. 11:22easy ones and only the hard ones go to
  325. 11:24the expensive model. So, for example,
  326. 11:26for our support agent, we're using
  327. 11:27Gemini 4 argon. But if I want to handle
  328. 11:30complaints with a different model with a
  329. 11:32different agent, I can add a sub agent
  330. 11:35down here. Opening that shows a quick
  331. 11:37description of when to use this agent.
  332. 11:40And clicking this button takes us to
  333. 11:41that agent where we're using the Claude
  334. 11:44Fable 5 model. Let's quickly test the
  335. 11:46main agent to see it using the sub
  336. 11:48agent. As you can see, it already used
  337. 11:50five tool calls. And there it is, sub
  338. 11:52agent being used. As soon as it realized
  339. 11:54it couldn't solve that with the
  340. 11:56information it had previously, it's
  341. 11:58referring to the sub agent to get that
  342. 12:00done. The sub agent should then have the
  343. 12:01necessary tools to accomplish that task.
  344. 12:03So, let's go to step four. Limit what
  345. 12:05the agent can see. Imagine your user
  346. 12:07sends a message like this. List every
  347. 12:09order from last week. They'd get a full
  348. 12:12table with all of the customers orders.
  349. 12:14And we don't really want them having
  350. 12:17access to this data. But this is what
  351. 12:19happens in most agent prototypes. Here's
  352. 12:21the rule for this step. The agent
  353. 12:22decides what should happen. The workflow
  354. 12:25decides what it's allowed to touch. If
  355. 12:27the AI writes the database query, then
  356. 12:29whatever the customer types can change
  357. 12:31that query. So, one clever message can
  358. 12:33get somebody else's orders. And a
  359. 12:35separate lookup tool doesn't fully fix
  360. 12:37this. A workflow tools inputs come from
  361. 12:39the AI, a fixed value or an expression.
  362. 12:42But the expression only sees what the AI
  363. 12:45sent. There's no way to pass in the real
  364. 12:47customer's ID. So, the tool still has to
  365. 12:49trust the AI. So the agent never touches
  366. 12:52the database. The workflow already knows
  367. 12:54who sent the message. So it gets that
  368. 12:56customer's orders and gives only those
  369. 12:59to the agent. And when the agent wants
  370. 13:01to give a refund, it just asks for one.
  371. 13:03The workflow checks that the order
  372. 13:04belongs to that customer before any
  373. 13:06money moves. Let's check what happens
  374. 13:08when I send the same prompt over to the
  375. 13:10main support ticket agent. All right,
  376. 13:12workflow has started. It's going through
  377. 13:14the pipeline. The agent worked on that,
  378. 13:16but because it didn't get a valid
  379. 13:18output, we were notified and the user
  380. 13:20didn't get the full list of orders. Now,
  381. 13:22let's go to step five. Know when it
  382. 13:24fails and why. We just saw this in the
  383. 13:27last example. It didn't only fail, but
  384. 13:29we also got notified about that failure.
  385. 13:31We just need to always make sure to know
  386. 13:33when and more importantly why it failed.
  387. 13:36In the message being sent to Slack, it
  388. 13:38has a static text saying needs a person
  389. 13:40customer followed by the customer's ID
  390. 13:42because we want to know who is doing
  391. 13:45what and if we need to follow up with
  392. 13:47any further messages. And here it's also
  393. 13:49including the user's prompt. Most times
  394. 13:51to find out where the issue is, you just
  395. 13:53head over to executions, find that red
  396. 13:55node that had the error, and you're all
  397. 13:57set. The why is harder. Was the AI slow
  398. 14:00or the order system? Did the agent call
  399. 14:02the same tool six times? Did it run out
  400. 14:05of rounds? The answers are all in the
  401. 14:07run data. And if I save a few numbers
  402. 14:09from every run, I can spot a problem
  403. 14:11before a customer complains. So if you
  404. 14:14head over to the support agent, you can
  405. 14:15find sessions. Inside of sessions, click
  406. 14:18on any past executions and you will see
  407. 14:21the agents trace. This is basically a
  408. 14:24timeline for the agents's execution.
  409. 14:26Tool usage. It took 2 milliseconds to
  410. 14:29get environment, 4 milliseconds to find
  411. 14:31a file, and then proceeded to probably
  412. 14:33generate the JSON in 5.8. 8 seconds.
  413. 14:36Just a few minutes ago, we limited the
  414. 14:38amount of tools that it could use, and
  415. 14:40that error is clearly reported right
  416. 14:42here. After using two tools, it
  417. 14:44recognized it reached its limits and
  418. 14:47simply reported it back. Aside from the
  419. 14:49trace, there's the workflow. The finish
  420. 14:51reason tells me when a run stopped
  421. 14:53because it hit a limit. Every message
  422. 14:55the agent handles is one execution, one
  423. 14:57run. I filter for failed runs and open
  424. 14:59the message and agent step. Its output
  425. 15:01has the reply and next to it the tokens
  426. 15:04used, the tool calls, the finish reason,
  427. 15:06and the session. At the end of every
  428. 15:08run, I save those with how long it took
  429. 15:10and how it ended to a data table. The
  430. 15:12finish reason tells me when a run
  431. 15:14stopped because it hit a limit. When the
  432. 15:16agent fails, the message in agent node
  433. 15:19shows an error. So, I set an error
  434. 15:21workflow, an error trigger, then a Slack
  435. 15:24message with the error, and a link to
  436. 15:25the run. And for cost, the agent
  437. 15:27settings show the estimated monthly
  438. 15:29usage. And every conversation shows its
  439. 15:32tokens and what it cost. And when it's
  440. 15:34low, the timeline shows where the time
  441. 15:36went. The AI, a tool, or the agent
  442. 15:38calling the same tool over and over.
  443. 15:41Step six, the last one. Let a person
  444. 15:43approve the risky stuff. Not everything
  445. 15:45needs a person to check it. Answering a
  446. 15:47question about shipping doesn't. Sending
  447. 15:49money back does. At least above a
  448. 15:52certain amount. So, I draw a line. Below
  449. 15:54it, the agent acts on its own. Above it,
  450. 15:57the workflow pauses, sends the request
  451. 15:59to someone in Slack, and waits. Then the
  452. 16:01refund only happens after a person
  453. 16:03clicks approve. This example right here
  454. 16:05is pretty perfect. That was my prompt.
  455. 16:08And a single node guarantees that the
  456. 16:11step asking for approval was avoided and
  457. 16:13it just issued the refund since it was
  458. 16:16below €75. But now, if I send a
  459. 16:18different prompt where the price is
  460. 16:20€340, let's see what happens. Well,
  461. 16:22actually, these single quotes might be a
  462. 16:25problem. Let me remove them. Submit. And
  463. 16:28yeah, now it's started. All right, the
  464. 16:29agent is working on that. And as soon as
  465. 16:31it's done, should go through the
  466. 16:32workflow and as soon as it hits the
  467. 16:35refund above 75 should go through the
  468. 16:38true route and ask for approval before
  469. 16:41submitting the refund. 3 2 1. There it
  470. 16:45is. By the way, this is a simple
  471. 16:46example. It already has pin data and
  472. 16:48that's why the workflow continued. But
  473. 16:50in production, the operation here is
  474. 16:51send and wait for response. So only when
  475. 16:53we answer that, then it would catch our
  476. 16:56answer and decide either to issue the
  477. 16:58refund or not. So here's the six steps
  478. 17:00again as a checklist. One, split the
  479. 17:03agent into parts. It decides workflow
  480. 17:05does the work and information that
  481. 17:07changes lives outside the prompt. Two,
  482. 17:10predictable answers in a fixed format
  483. 17:13checked before anything uses them.
  484. 17:15Three, limits on rounds and spending and
  485. 17:18a backup reply when a call fails. Four,
  486. 17:20the agent only sees this customer's data
  487. 17:23and anything risky happens in the
  488. 17:25workflow, not the agent. Five, logs and
  489. 17:28alerts so you know where it failed and
  490. 17:30why. Six, big refunds and other risky
  491. 17:33actions, wait for a person to approve
  492. 17:35them. The agent and workflow from this
  493. 17:37video are linked below with N's guide to
  494. 17:39running agents in production. And if you
  495. 17:41want me to go deeper in any of these
  496. 17:42steps, let me know which one down in the
  497. 17:44comment section. Thanks for watching and
  498. 17:46we'll see you in the next video.

About this transcript

This page contains the full transcript of How to Move AI Agents from Prototype to Production by n8n, generated from the public captions YouTube serves with the video. The transcript has 3,557 words across 498 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.