How to Move AI Agents from Prototype to Production — Transcript
Full transcript
- 0:00Getting an AI agent to work on your
- 0:01laptop is the easy part. Getting it to
- 0:03work for real customers every day is a
- 0:05different job. So today I'm showing you
- 0:07how to move AI agents from prototype to
- 0:09production with N. And for that I built
- 0:11the same support agent twice. This is
- 0:13the prototype. It answers customer
- 0:15support messages. And when I tested it
- 0:17works every time. And this is the
- 0:19production. The same agent ready for
- 0:21real customers. It does the same job. It
- 0:24just has a lot more around it. Now why
- 0:26all the extra parts you ask? Because the
- 0:28simple version on the left breaks as
- 0:31soon as real people use it. A customer
- 0:33writes something you never planned for.
- 0:35AI sends back an answer with a piece
- 0:36missing. It gets stuck and tries the
- 0:38same thing a 100 times or it gives
- 0:40someone a refund they shouldn't get. In
- 0:42this video I'll show you six fixes that
- 0:44turn the left side into the right side.
- 0:45And I'll build each one in nan step by
- 0:48step. Step one, split the agent into
- 0:50smaller parts. Right here I have the
- 0:52prototype example. It's basically a
- 0:54support agent for online shop that sells
- 0:56coffee gear. And if you read through the
- 0:58system prompt, the instructions that I'm
- 1:00giving over to the agent, you'll see
- 1:01that I'm giving it a lot of context.
- 1:04There's refund policy, shipping times,
- 1:06opening hours, and this is a great
- 1:08example of what not to do because you'll
- 1:10find yourself in trouble once you need
- 1:12to maintain this agent. At the end of
- 1:14the day, what you want to do with an
- 1:15agent is provide it ways that it fetch
- 1:17for context to accomplish a task. So,
- 1:20initially it might seem like just
- 1:21placing all that context inside of the
- 1:23system prompt might be a good idea, but
- 1:25you'll see in just a bit why it's not.
- 1:27I've also given this agent two tools.
- 1:29So, one of them can run any database
- 1:31query and the other tool would
- 1:32effectively send the refund. So, we're
- 1:34just using a dummy JavaScript here, but
- 1:36it should work for our example. So,
- 1:38let's test this agent. To do so, click
- 1:40this button up here, send your prompt,
- 1:42and this prompt is specific to an
- 1:44example that should work with how this
- 1:47agent is configured. Notice that it's
- 1:49successfully using all the tool calls.
- 1:50And now it correctly answered back the
- 1:53user with the refund for the
- 1:55corresponding order processed. Now let's
- 1:58see what happens if a user makes a
- 1:59question that you weren't prepared for.
- 2:01And remember, we're building an AI agent
- 2:03here. It should be flexible, dynamic
- 2:05enough to give the user an answer for
- 2:08any question. If it doesn't have enough
- 2:09context to answer them, it should be
- 2:11able to ask a human before answering or
- 2:14give a fallback answer, ensuring that
- 2:16the user gets a response. So, there it
- 2:18is. Unfortunately, our policy doesn't
- 2:21cover accidental damage. Although it
- 2:23tried to give an answer here, it's not
- 2:24accurate. We didn't tell it any of this
- 2:27anywhere in the instructions. So, it's a
- 2:29madeup answer that we probably don't
- 2:31want. And also, if you're not adding the
- 2:33correct tools to fetch for context,
- 2:35someone could just ask for a refund
- 2:37after the 30-day policy and get the
- 2:40refund. In this example, I tried to do
- 2:41that, but maybe because I mentioned 3
- 2:43months, it got up to me and didn't allow
- 2:45the refund. But still, you might test
- 2:47this 20 times and only the 21st time,
- 2:50the agent will randomly select and apply
- 2:52the refund. And that's why we need to
- 2:54set everything up so the agent isn't
- 2:55always fully in control of things that
- 2:57are more important. Another example is
- 2:59just prompt injection. I can tell it
- 3:01that I'm the store manager and make the
- 3:03agent do something in behalf of the
- 3:05manager while not being the manager. It
- 3:08did fail this time, but what guarantees
- 3:09that a future attack won't be
- 3:11successful? And honestly, this system
- 3:13prompt is quite small. If you have to
- 3:14change a policy, for example, how would
- 3:16you do that if it's this big or even
- 3:19like this with maybe hundreds of lines
- 3:22of instructions? And whenever you do
- 3:23find it and change that, who guarantees
- 3:25that that change won't affect the way
- 3:28that the agent works and force you to
- 3:30check the entire agent to see what
- 3:31broke? So what do we do here? We split
- 3:33it up. A normal workflow receives the
- 3:35customer's message, flux up the
- 3:37customer, and sends the refund. The
- 3:39agent only does the thinking. Read the
- 3:41message, look at the orders, and decide
- 3:43what to do. Here's a simple rule. The
- 3:45agent decides, and workflows do the
- 3:47work. The agent figures out what the
- 3:49customer wants and which tool to use.
- 3:51The actual steps like looking up an
- 3:53order or sending a refund each live in
- 3:56their own small workflow which I can
- 3:58test and change on its own. The same
- 4:00goes for information that changes often
- 4:02like prices, policies, or opening hours.
- 4:06If it's pasted into the instructions,
- 4:08every update means editing the agent. If
- 4:10the agent looks it up instead, I just
- 4:13update the information and the next
- 4:15answer uses it. Now, this is how your
- 4:17production agent should look like. First
- 4:18of all, knowledge. In here is where
- 4:20you'd place something like the refund
- 4:22policy. This can be a CSV, a PDF
- 4:24markdown, or just plain text. Now,
- 4:26whenever you want to update the refund
- 4:28policy or any other similar files, you
- 4:30could do so from the knowledge base
- 4:32inside of this section of the agent,
- 4:34which now removes the need to go through
- 4:35that huge block of instructions and is
- 4:38also a nice guide for the agent to only
- 4:40access this whenever it actually needs
- 4:42that information. That being said, to
- 4:44make sure the agent knows that it could
- 4:46fetch for this refund policy, we can add
- 4:48a skill. So this skill is called handle
- 4:51a complaint. The when to use this skill
- 4:53description says it all. So use when the
- 4:55customer is unhappy, a damaged, missed
- 4:58or wrong item, a late delivery or a
- 5:00refund request. This points it to the
- 5:03refund policy as well as gives further
- 5:06instructions of how to use that policy.
- 5:09So again, now the only thing that goes
- 5:10inside of the system prompt for your
- 5:12agent is this description so that it
- 5:14then grabs the necessary context to
- 5:16handle this situation. And by the way,
- 5:18this is a quick demonstration for a
- 5:19support agent. It could have much more
- 5:21skills here to deal with different
- 5:23support agent tasks as well as different
- 5:26files inside of the knowledge base.
- 5:28Another way to give tools to your agent
- 5:29is inside of capabilities. This allows
- 5:32it to effectively run a workflow inside
- 5:35of your nan instance. For example, here
- 5:38I added the nan motion demo get shipping
- 5:41status. I can click on this button right
- 5:42here and it'll take me to that workflow
- 5:44which if I just click on execute all it
- 5:47does is run this JavaScript node which
- 5:49simulates how it would work in
- 5:50production. But this already screams at
- 5:52the idea that you don't need to test
- 5:53your AI agent every single time for
- 5:55every single part of the agent
- 5:57implementation. For example, searching
- 6:00for data inside of the database. You can
- 6:02have that sub workflow and test these
- 6:04nodes without running the main agent
- 6:06every single time. I can just add a
- 6:08dummy data up here. Let's pin that
- 6:10there. of order 4431. Save it. And now
- 6:14execute it. I'll get a response back. So
- 6:17there's the output. It could have also
- 6:20been a database lookup or any other way
- 6:22to fetch for this specific data. Before
- 6:24we test the agent, let me show you the
- 6:26refund policy which clearly says that
- 6:28the refunds are possible within 30 days.
- 6:30Let's check if it successfully uses that
- 6:33information. We can already see from the
- 6:34tool calls that it successfully loaded
- 6:37the skill. It understood it needed to
- 6:38use it. And then from that skill, it
- 6:40found the file which is inside of the
- 6:43knowledge base. Read the file and now
- 6:45answers us based on the refund policy
- 6:48that now it has context to. And there it
- 6:50is. Since you reported the damage within
- 6:5230-day refund window, we're issuing a
- 6:54full refund. And now we'll just change
- 6:56the refund policy to 14 days. Let's
- 6:58upload that and send the same message.
- 7:01And there it is. The action now is
- 7:02escalate. The refund amount is clearly
- 7:04zero. And the reply text includes that
- 7:07our refund window is 14 days. As you can
- 7:10see, the fix for this was specifically
- 7:12inside of the knowledge base for refund
- 7:14policy. So remember, split your agents
- 7:17into smaller parts. Step two, make the
- 7:19agents answers predictable. You might
- 7:21already know this, but a good way to
- 7:22make your agents predictable is by
- 7:24having it answer with JSON. To do that,
- 7:27just toggle on the require specific
- 7:28output. And here is where you'll
- 7:30instruct how you want the output schema
- 7:33to be like. We have five main parameters
- 7:35here. The intent which is what the
- 7:37customer wants, order ID, the action,
- 7:39and we've seen all of this before in the
- 7:41previous example where in the first
- 7:43attempt when it submitted the refund,
- 7:45this was the action used, and then when
- 7:47it didn't apply the refund, it went with
- 7:49escalate. We also saw the refund amount
- 7:51and the reply text. So these five
- 7:54parameters are very important for our
- 7:56overall workflow, not only the agent.
- 7:58And although we have that added to the
- 8:00agent, it may not respond in that
- 8:02specific structure. And here is where we
- 8:04check for that valid output. This way we
- 8:07can handle two errors. One that can
- 8:08happen inside of the agent for whichever
- 8:10reason and that needs to be handled. So
- 8:13the error stream guarantees that won't
- 8:15go silent and will actually receive a
- 8:17message in Slack saying that there was
- 8:19an error. And if it didn't have a valid
- 8:21output, this would still be a success.
- 8:24So here is where we validate that. If
- 8:26it's not a successful output, it then
- 8:29also triggers a message to Slack. Let's
- 8:31test this workflow. Hitting execute now.
- 8:34Going over to the terminal since it's a
- 8:36web hook. And pasting this curl in. Let
- 8:38me hit enter. Just got a message back
- 8:40saying the workflow has started. And
- 8:42that's it. All of those five parameters
- 8:44were successfully validated and went
- 8:46through the entire pipeline with
- 8:48success. Ultimately leading to this log
- 8:50run down here. Now watch what happens if
- 8:52I turn off the require specific output
- 8:54format. Let's toggle this off. Hit
- 8:56execute and send a new curl. Workflow
- 8:59has started. But as you may see, as soon
- 9:02as it hit the valid output node, it went
- 9:04through the false route. So it's now
- 9:06successfully preventing it from silently
- 9:08having an error without anyone being
- 9:10aware of it. AI models don't promise a
- 9:12format. They usually give you what you
- 9:14asked for and usually is fine in a demo.
- 9:17But with real customers, the one time it
- 9:19adds an extra sentence is the time your
- 9:21refund step gets no order number. Step
- 9:24three, put a cap on loops and costs. An
- 9:26agent works in a loop. It thinks, use
- 9:29the tool, looks at the result, and
- 9:31decides whether to go again. Most of the
- 9:33time, it stops after two or three
- 9:35rounds. But if a tool keeps giving back
- 9:37something it doesn't expect, it keeps
- 9:39trying, and you pay for every single
- 9:41round. So, I set limits, a maximum
- 9:43number of rounds and a maximum spend for
- 9:46each conversation. If it hits a limit,
- 9:48it stops. And I handle that like any
- 9:50other error. You can find the
- 9:51configuration for that right here. I can
- 9:53change the maximum number of iterations
- 9:55per agent by going over to settings,
- 9:57scrolling down, and here where it says
- 9:59100, I can change it over to eight, for
- 10:02example, for a support agent. Now, be
- 10:03aware that each agent you're building
- 10:05has a specific case. For a support
- 10:07agent, it probably doesn't need to use
- 10:09that much tools, but a financial agent
- 10:12that does multiple calculations and
- 10:14would require tool usage multiple times
- 10:17might need a much bigger number of max
- 10:20iterations. Let's set this to two and
- 10:22I'll quickly show you what happens if
- 10:24the agent goes past the max number of
- 10:27iterations. All right, apparently it
- 10:29already executed two tool calls and then
- 10:31when it almost executed the third one,
- 10:32it got that warning. the agent has
- 10:34reached the maximum number of iterations
- 10:36and has stopped. Now, as for a cap on
- 10:38the cost, you can scroll up here where
- 10:40it says cost cap per session. And
- 10:42clicking here will allow you to decide
- 10:44what is that maximum cost. And we can
- 10:47also define a monthly budget that the
- 10:49agent can spend. Setting the budget
- 10:51alert to 80% guarantees that we'll get
- 10:53an alert for that before running out of
- 10:55budget and leading to the agent being
- 10:58offline. And while we're in advance, you
- 11:00can also set up the maximum parallel sub
- 11:03aents as well as tool call concurrency,
- 11:06which are also ways to cap and have a
- 11:07better control of your agent. Another
- 11:09way to save money, not every message
- 11:11needs your smartest, most expensive
- 11:13model. Where's my order is a simple
- 11:15lookup. A long complaint about a broken
- 11:17item and a missing refund needs more
- 11:20thinking. So, a cheap model handles the
- 11:22easy ones and only the hard ones go to
- 11:24the expensive model. So, for example,
- 11:26for our support agent, we're using
- 11:27Gemini 4 argon. But if I want to handle
- 11:30complaints with a different model with a
- 11:32different agent, I can add a sub agent
- 11:35down here. Opening that shows a quick
- 11:37description of when to use this agent.
- 11:40And clicking this button takes us to
- 11:41that agent where we're using the Claude
- 11:44Fable 5 model. Let's quickly test the
- 11:46main agent to see it using the sub
- 11:48agent. As you can see, it already used
- 11:50five tool calls. And there it is, sub
- 11:52agent being used. As soon as it realized
- 11:54it couldn't solve that with the
- 11:56information it had previously, it's
- 11:58referring to the sub agent to get that
- 12:00done. The sub agent should then have the
- 12:01necessary tools to accomplish that task.
- 12:03So, let's go to step four. Limit what
- 12:05the agent can see. Imagine your user
- 12:07sends a message like this. List every
- 12:09order from last week. They'd get a full
- 12:12table with all of the customers orders.
- 12:14And we don't really want them having
- 12:17access to this data. But this is what
- 12:19happens in most agent prototypes. Here's
- 12:21the rule for this step. The agent
- 12:22decides what should happen. The workflow
- 12:25decides what it's allowed to touch. If
- 12:27the AI writes the database query, then
- 12:29whatever the customer types can change
- 12:31that query. So, one clever message can
- 12:33get somebody else's orders. And a
- 12:35separate lookup tool doesn't fully fix
- 12:37this. A workflow tools inputs come from
- 12:39the AI, a fixed value or an expression.
- 12:42But the expression only sees what the AI
- 12:45sent. There's no way to pass in the real
- 12:47customer's ID. So, the tool still has to
- 12:49trust the AI. So the agent never touches
- 12:52the database. The workflow already knows
- 12:54who sent the message. So it gets that
- 12:56customer's orders and gives only those
- 12:59to the agent. And when the agent wants
- 13:01to give a refund, it just asks for one.
- 13:03The workflow checks that the order
- 13:04belongs to that customer before any
- 13:06money moves. Let's check what happens
- 13:08when I send the same prompt over to the
- 13:10main support ticket agent. All right,
- 13:12workflow has started. It's going through
- 13:14the pipeline. The agent worked on that,
- 13:16but because it didn't get a valid
- 13:18output, we were notified and the user
- 13:20didn't get the full list of orders. Now,
- 13:22let's go to step five. Know when it
- 13:24fails and why. We just saw this in the
- 13:27last example. It didn't only fail, but
- 13:29we also got notified about that failure.
- 13:31We just need to always make sure to know
- 13:33when and more importantly why it failed.
- 13:36In the message being sent to Slack, it
- 13:38has a static text saying needs a person
- 13:40customer followed by the customer's ID
- 13:42because we want to know who is doing
- 13:45what and if we need to follow up with
- 13:47any further messages. And here it's also
- 13:49including the user's prompt. Most times
- 13:51to find out where the issue is, you just
- 13:53head over to executions, find that red
- 13:55node that had the error, and you're all
- 13:57set. The why is harder. Was the AI slow
- 14:00or the order system? Did the agent call
- 14:02the same tool six times? Did it run out
- 14:05of rounds? The answers are all in the
- 14:07run data. And if I save a few numbers
- 14:09from every run, I can spot a problem
- 14:11before a customer complains. So if you
- 14:14head over to the support agent, you can
- 14:15find sessions. Inside of sessions, click
- 14:18on any past executions and you will see
- 14:21the agents trace. This is basically a
- 14:24timeline for the agents's execution.
- 14:26Tool usage. It took 2 milliseconds to
- 14:29get environment, 4 milliseconds to find
- 14:31a file, and then proceeded to probably
- 14:33generate the JSON in 5.8. 8 seconds.
- 14:36Just a few minutes ago, we limited the
- 14:38amount of tools that it could use, and
- 14:40that error is clearly reported right
- 14:42here. After using two tools, it
- 14:44recognized it reached its limits and
- 14:47simply reported it back. Aside from the
- 14:49trace, there's the workflow. The finish
- 14:51reason tells me when a run stopped
- 14:53because it hit a limit. Every message
- 14:55the agent handles is one execution, one
- 14:57run. I filter for failed runs and open
- 14:59the message and agent step. Its output
- 15:01has the reply and next to it the tokens
- 15:04used, the tool calls, the finish reason,
- 15:06and the session. At the end of every
- 15:08run, I save those with how long it took
- 15:10and how it ended to a data table. The
- 15:12finish reason tells me when a run
- 15:14stopped because it hit a limit. When the
- 15:16agent fails, the message in agent node
- 15:19shows an error. So, I set an error
- 15:21workflow, an error trigger, then a Slack
- 15:24message with the error, and a link to
- 15:25the run. And for cost, the agent
- 15:27settings show the estimated monthly
- 15:29usage. And every conversation shows its
- 15:32tokens and what it cost. And when it's
- 15:34low, the timeline shows where the time
- 15:36went. The AI, a tool, or the agent
- 15:38calling the same tool over and over.
- 15:41Step six, the last one. Let a person
- 15:43approve the risky stuff. Not everything
- 15:45needs a person to check it. Answering a
- 15:47question about shipping doesn't. Sending
- 15:49money back does. At least above a
- 15:52certain amount. So, I draw a line. Below
- 15:54it, the agent acts on its own. Above it,
- 15:57the workflow pauses, sends the request
- 15:59to someone in Slack, and waits. Then the
- 16:01refund only happens after a person
- 16:03clicks approve. This example right here
- 16:05is pretty perfect. That was my prompt.
- 16:08And a single node guarantees that the
- 16:11step asking for approval was avoided and
- 16:13it just issued the refund since it was
- 16:16below €75. But now, if I send a
- 16:18different prompt where the price is
- 16:20€340, let's see what happens. Well,
- 16:22actually, these single quotes might be a
- 16:25problem. Let me remove them. Submit. And
- 16:28yeah, now it's started. All right, the
- 16:29agent is working on that. And as soon as
- 16:31it's done, should go through the
- 16:32workflow and as soon as it hits the
- 16:35refund above 75 should go through the
- 16:38true route and ask for approval before
- 16:41submitting the refund. 3 2 1. There it
- 16:45is. By the way, this is a simple
- 16:46example. It already has pin data and
- 16:48that's why the workflow continued. But
- 16:50in production, the operation here is
- 16:51send and wait for response. So only when
- 16:53we answer that, then it would catch our
- 16:56answer and decide either to issue the
- 16:58refund or not. So here's the six steps
- 17:00again as a checklist. One, split the
- 17:03agent into parts. It decides workflow
- 17:05does the work and information that
- 17:07changes lives outside the prompt. Two,
- 17:10predictable answers in a fixed format
- 17:13checked before anything uses them.
- 17:15Three, limits on rounds and spending and
- 17:18a backup reply when a call fails. Four,
- 17:20the agent only sees this customer's data
- 17:23and anything risky happens in the
- 17:25workflow, not the agent. Five, logs and
- 17:28alerts so you know where it failed and
- 17:30why. Six, big refunds and other risky
- 17:33actions, wait for a person to approve
- 17:35them. The agent and workflow from this
- 17:37video are linked below with N's guide to
- 17:39running agents in production. And if you
- 17:41want me to go deeper in any of these
- 17:42steps, let me know which one down in the
- 17:44comment section. Thanks for watching and
- 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.