Building the AI Agent Is Easy. Proving It's Safe Isn't - Jonathan Osborne, NatWest

AI Engineer · 18 min · 257 sentences · from YouTube's caption track

Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.

  1. 00:01[music]
  2. 00:12Hi guys.
  3. 00:13So my name is Jonathan Osborne.
  4. 00:15I am a lead AI engineer from that west group.
  5. 00:18I'll tell you more about what that is in a second.
  6. 00:21And today I'm going to be talking about taking agents from prototype to production customerf facing that is in a regulated banking environment.
  7. 00:28And I guess maybe some spoilers with the access to coding assistants and tools that we have today.
  8. 00:33The actual creation of the agent that's kind of the easy part.
  9. 00:36The much harder part I think is proving that it's safe.
  10. 00:41So let me tell you a bit about Nat West Group.
  11. 00:44So Nat West is the second largest retail bank in the UK and currently we have somewhere in the range of 19 million retail customers.
  12. 00:5219 million.
  13. 00:53Hold on to that number because it's really what makes everything else in this talk matter.
  14. 00:57Kora is our customer's primary point of contact.
  15. 01:00So it's our digital assistant and it serves somewhere in the realm of a 100,000 conversations a day.
  16. 01:06And until now the vast vast bulk of those answers were scripted.
  17. 01:10So if a customer comes to us and they ask a conversation then if we haven't fought to script that then uh you know we're not going to be able to answer.
  18. 01:19Customers going to get frustrated.
  19. 01:20They're probably going to have to cue to speak to a human agent.
  20. 01:23That's changing.
  21. 01:24So as of this year we are now working to bring approximately a third of the journeys within Kora to AI generated answers backed by Rag and our knowledge bases
  22. 01:34and agents agents that are able to take action on the behalf of customers.
  23. 01:38So for example helping them make a payment or change their address.
  24. 01:43I guess the scary part here really isn't the model like by and large models are quite good.
  25. 01:48They provide good answers.
  26. 01:49Now it's the blast radius.
  27. 01:51So with 19 million customers, if we get a few of these utterances wrong, that isn't a bug ticket.
  28. 01:57That isn't kind of a maybe a funny headline, it's a real customer and they're real money.
  29. 02:02It's slightly very difficult question from the regulator and it's reputational damage for us as a company.
  30. 02:08So this talk is about what we had to go through to get the approval to go live and I guess what it took us to maybe trust some of our own metrics as well because as I say the interesting part it's not the agent it's proving and making it safe.
  31. 02:24Let's maybe make that more concrete by considering an example here.
  32. 02:27So kind of same question two very different conversations.
  33. 02:30So customer comes, they ask, "Can I overpay my mortgage without being charged?"
  34. 02:35Today in the scripted solution, that's going to recognize that keyword mortgage, and we're going to present the customer with a menu.
  35. 02:41So apply rates, my mortgage, customer is going to have to select none of the above.
  36. 02:45Maybe we'll ask them to rephrase their question, but more than likely, game over.
  37. 02:49This customer is going to have to cue, speak to a human agent.
  38. 02:51They're going to be frustrated.
  39. 02:53On the right hand side, bit of a different story.
  40. 02:55So AI has been able to answer that question using our knowledge bases.
  41. 02:59You can overpay up to 10% of your balance in a year.
  42. 03:01No early repayment charges.
  43. 03:03Shall I check your deal?
  44. 03:05But then the customer does something which is very normal but is can be frustrating.
  45. 03:09So they change this topic.
  46. 03:11So actually can I close the account instead?
  47. 03:14This happens all the time and a traditional decision tree is really really bad at this type of digression.
  48. 03:20It's worth mentioning that digressions are going to come back.
  49. 03:22So we'll hold on to that point.
  50. 03:25I guess the key point though is if we build an agent that can answer any question, it can also answer any question wrong.
  51. 03:31So that 10% if that doesn't apply to this particular customer's deal, it's a real customer, is their real mortgage, and is there real money at stake?
  52. 03:40So why is it so much harder to make an agent back solution, you know, more, you know, how do we protect against it as opposed to that scripted bot?
  53. 03:49Well, it's because it reasons, it decides, it generates.
  54. 03:51And there are at least kind of four failure mode here, which we wouldn't have in that scripted solution.
  55. 03:56One, it can be confidently wrong.
  56. 03:59Hallucination against a fictitious source and sound absolutely sure of itself while it does it.
  57. 04:04Two, it can be talked into things, prompt injection.
  58. 04:07The input itself can become adversarial.
  59. 04:10Three, right, but unhelpful, so it can provide accurate on policy answers that just go round and around and around and never actually answer the customer's conversation.
  60. 04:18incredibly frustrating.
  61. 04:20And four, it can be nondeterministic.
  62. 04:22Same inputs, completely different output.
  63. 04:25That means that your traditional software engineering assertions just don't really work very well here.
  64. 04:29And as a consequence of that, regression tests that have been built up over years by the existing core team, they really no longer apply.
  65. 04:37A scripted systems failure surface is completely bounded.
  66. 04:40We can write out every situation that might occur.
  67. 04:43we can test it and we can be really confident it's going to do what we want it to with an agent that's really not possible and we can't really traditionally
  68. 04:50test our way to safety.
  69. 04:52So how do we deal with this?
  70. 04:53Well, the first part for us was shrinking the attack surface before we actually then thought about hardening it introducing what we call the routing funnel.
  71. 05:03So every customer conversation comes in at the top here.
  72. 05:06First we apply a contextual filter and that allows us to remove kind of common events like button clicks.
  73. 05:11That's about 20%.
  74. 05:13Next, we have some deterministic pre-classification rules.
  75. 05:17So, with these rules, we're kind of using the customer's utterance and some metadata to route them to a destination with no ML or AI involved at all.
  76. 05:24At this point, it's only utterances that make it past these first two gates that we then actually start the models on.
  77. 05:30First, there's a relevancy and rephrasing step that's kind of gated.
  78. 05:33It helps with those really detailed multicontext questions.
  79. 05:36And then our intent classifier.
  80. 05:38This is actually a neural network over embeddings.
  81. 05:40This isn't generative AI which is able to use a customer's utterance to predict the right back end.
  82. 05:45Finally, there's some policy rules to ensure that this customer should actually be getting into that particular backend.
  83. 05:52Why do we build it this way?
  84. 05:53Well, four reasons a lot of them about being a bank.
  85. 05:56Firstly, access control.
  86. 05:57So, we need to enforce that to ensure the customer should be getting to this act this this back end.
  87. 06:02Auditability.
  88. 06:03So, every decision here needs to carry a code.
  89. 06:06It needs to be fully auditable and reproducible.
  90. 06:08The regulator ensures this resilience.
  91. 06:10In the case that a model or the gender isn't available, we still need to provide the customer an answer and I guess governance.
  92. 06:17So all of this is version config.
  93. 06:18We can make changes to it without a full redeployment.
  94. 06:21That's really important because it means that we can react fast to changing market conditions.
  95. 06:25We didn't just take a language model, slap some context into it, and point it at 19 million customers.
  96. 06:30We first thought really hard about what actually needed a model to solve.
  97. 06:34This brings us on to the really important question of is this actually working?
  98. 06:38And the key metric that they looked at in kind of traditional Kora was accuracy when doing this.
  99. 06:42So if I told you this intent writer is 94% accurate, that probably sounds really good.
  100. 06:47But does that actually answer the important question?
  101. 06:50So is it grounded in a real source?
  102. 06:52Did the customer's question actually get resolved?
  103. 06:54Did it know when it was out of its depth?
  104. 06:56When to stop bring in a human?
  105. 06:58You can't embody that with one single score.
  106. 07:01And that's why we've moved away from quality as a score, started treating it more as a vector.
  107. 07:07Uh, every score, every kind of answer we score across three different categories.
  108. 07:11So, safety, could it harm the customer?
  109. 07:13Task, did it actually do its job?
  110. 07:15Experience, how did it feel to deal with?
  111. 07:17All of these can be monitored and alarmed independently.
  112. 07:20And they allow us to differentiate between is it hallucinating versus is it right but just insufferable to deal with.
  113. 07:27There are different answers and they require really different solutions.
  114. 07:31It's what the key point here is a routter that's 94% accurate but 100% confident the 6% of the time it's wrong is way more dangerous than one that's 85%
  115. 07:41confident and knows it.
  116. 07:43The first thing we did here before we worried about automating this is what we always do and we started off with some human validation.
  117. 07:48Uh the numbers that you see here are some June validation that we did on our payment agent.
  118. 07:53111 conversations over 37 different payment journeys.
  119. 07:57Four brands, three independent human scorers per conversation.
  120. 08:01Headline here, 83% pass rate across the board.
  121. 08:04But as ever, the headline's pretty useless.
  122. 08:06Let's dig into some of that data.
  123. 08:08So 97% at on the happy path scenarios.
  124. 08:11That's great.
  125. 08:1276% edge cases, not quite so good.
  126. 08:15Topic changes like that mortgage example that we discussed earlier, only 43%.
  127. 08:20So that single 83% score was hiding that 54% spread.
  128. 08:25The second point on the right is probably more nuanced and less talked about and that's do human validators actually agree with each other
  129. 08:31[snorts]
  130. 08:31on something objective like bias and fairness you do actually see a 95% agreement rate which is great but on something more subjective intent understanding so you know are does the bot actually understand what they what the user wants
  131. 08:45only a 64% agreement rate.
  132. 08:48The common thing when we start automating this bringing LLM as a judge is that we want to make our judge match our human validators.
  133. 08:55But what are they meant to be matching here?
  134. 08:56There's only a 60 form agreement rate between humans.
  135. 09:00So that can't simply be the target here essentially.
  136. 09:03One one caveat by the way like the two biggest causes of failure here actually turned out to be engineering issues.
  137. 09:08Not problem with the model at all, but nevertheless that proves useful value of the human validation because it caught them.
  138. 09:15So let's turn to actually automating this then.
  139. 09:18So LLM as a judge.
  140. 09:19So core plus that's not live yet.
  141. 09:22So I'm going to turn to another internal project.
  142. 09:24So this is an internal complaints agent that we have.
  143. 09:27Essentially the goal here is that customers will occasionally complain.
  144. 09:30This will take the complaint.
  145. 09:32It has access to a load of tools to then be able to write a summary for complaint handlers to essentially explain why has this particular user complained and how we can help them with it.
  146. 09:41It went live in February and we've got around 14,000 of these cases which have been scored by both a human validator and an LLM as a judge.
  147. 09:48If we dive into the data, so this is the faithfulness score here on the right.
  148. 09:52So you can see upper bar in the red there, that's the LM as a judge mean.97 right up at the top very little spread.
  149. 09:59Human mean 083 much much wider spread.
  150. 10:04Key point here is that if you look at that average error versus the human it's 2. you might conclude that the judge is doing okay but the correlation is almost zero.
  151. 10:15Uh in in this case like a judge which doesn't discriminate between the actually good cases and the bad cases is basically worthless.
  152. 10:21You don't want your judge to be generous and that is what LLMs want to do by default.
  153. 10:26Maybe one other point to make here is that so that amber dotted line that represents the threshold for this particular metric for this judge model.
  154. 10:34You can see we're comfortably above that.
  155. 10:36However, we made a change to that model.
  156. 10:38Didn't change anything else.
  157. 10:39Same inputs, same outputs.
  158. 10:40Just change the actual model behind it.
  159. 10:42And that dropped all the way from point 8 above to 2 above.
  160. 10:46That means that the judge model itself actually becomes part of your configuration.
  161. 10:50And it can lead to breaking changes.
  162. 10:52A key point we took here, by the way, is that we moved our judge to a different model family from that of the uh, you know, the actual agent.
  163. 10:59So, judged and judged, different blind spots, and that's actually been really effective in pinning the two scores closer together.
  164. 11:07Coming back to the core example.
  165. 11:08So how does this scoring actually run?
  166. 11:10So live conversations between the agents and its guardrails.
  167. 11:14All of those are captured ving open source standards like hotel and open inference.
  168. 11:18All of that detail is then sampled.
  169. 11:20So by default we take 5% random sample but we also want to look at everything interesting.
  170. 11:25By interesting I mean conversations are handoff fail those are particularly long ones where the user is angry.
  171. 11:31We then score these with our LLM as a judge.
  172. 11:33So that's that raft and dimension of metrics that I talked about earlier.
  173. 11:36And then absolutely all of this ends up in comedic.
  174. 11:39So traces, scores, experiments.
  175. 11:42It's governed by a couple of bank constraints here.
  176. 11:44So we work in a completely airgapped environment.
  177. 11:46So no internet access to anything.
  178. 11:48So judge model is reached over a private path.
  179. 11:50We have an internal geni gateway.
  180. 11:52Comet a SAS product.
  181. 11:53We're consuming that as a signed partner app via AWS.
  182. 11:57Second around personally identifiable information.
  183. 11:59We have a zero tolerance policy for any PII leaving our network.
  184. 12:02So that means a lot of this evaluation happens without that present different cadences here.
  185. 12:08So tracers are being captured as they happen.
  186. 12:10We're doing offline scoring every four hours.
  187. 12:13And then regress this is also built into our CI/CD.
  188. 12:16So if we make changes to prompts or to context that can have like an outsized impact on what the agent is actually responding.
  189. 12:22So we need to constantly be comparing versus a known good baseline.
  190. 12:27We do that in CI/CD.
  191. 12:28There's a hard regression gate.
  192. 12:30So changes can't be merged in without us understanding exactly what's going to occur.
  193. 12:34I guess key point is that continuous evaluation is part of your production infrastructure.
  194. 12:39It's not a notebook that you run a couple of times when your model goes live.
  195. 12:44So there's different models here and they've got different failure modes.
  196. 12:47So on the right hand side we've got the agents, we've got the generative AI.
  197. 12:50So generative AI regresses.
  198. 12:52So as we've just talked about, somebody can make changes to a prompt and that can have outsized impact on the behavior.
  199. 12:57That's why we have the CI/CD in place.
  200. 12:59You can see here a real opic trace which is looking from our payment agent.
  201. 13:03Every node in the LAN graph uh becomes a different span and when the agent is slow or is breaking in a particular place, this allows us or an agent to jump in and investigate exactly why
  202. 13:14on the classical.
  203. 13:15So the intent classifier is traditional ML and thus we've got to monitor it in a more classical way.
  204. 13:20It drifts over time, right?
  205. 13:21So human conversation will naturally evolve from the point at which the model was trained.
  206. 13:25So we need to look at more traditional things like input feature drift, F1 score based off human scores, sorry, human labels.
  207. 13:32And then you know we have rag thresholds defined as to exactly when we need to trigger retraining for that model.
  208. 13:38On the right you can see an npm data drift chart.
  209. 13:40I I really wouldn't underestimate like input feature drift here.
  210. 13:43It's a really good canary as to when your model is starting to decline before your F1 score does implying the need for retraining.
  211. 13:50So two different problems, two different instruments, but what we don't want is two different observability and evaluation frameworks.
  212. 13:57Comet's really useful there because it brings in both OPIC for the Genai and MPM model performance monitor for the ML.
  213. 14:03So one platform how do we actually deploy this then without kind of breaking the bank and creating a load of headlines.
  214. 14:11We start off with a shadow deployment.
  215. 14:12So what I mean by that is we put this live uh we use it to start classifying cutter utterancerances but this existing scripted solution is what will actually respond to the customer
  216. 14:21and that means that we can get a sense of the real data you know the the input uh the input space for different customer queries with almost zero risk.
  217. 14:30I think this shadow mode is like one of the more transferable bits of this project for us because often we have this deadlock in a regulated industry where obviously we can't go live and get production data without the approval to do so.
  218. 14:42But equally to actually enable us to go live in many cases our model risk colleagues increasingly want to see how our models are going to react to that actual production data.
  219. 14:52This allows us to kind of break that apart so we can break apart observe safely from actually answer customer queries.
  220. 15:00uh and it takes one really big decision point, a big bang release into a series of smaller ones which we can make confidently.
  221. 15:06We then go brand by brand.
  222. 15:07So we have like percentage based rollout within the brand and we have kind of KPIs which allow us to determine go no-go at various points along there.
  223. 15:15Some of those decisions are automated and some of those require manual approval.
  224. 15:20Um I think and yeah some of those require manual approval.
  225. 15:24What kind of makes that possible is that we make a lot of use of feature flagging here.
  226. 15:28So there's like a global flag that we can trigger to send everything back to the scripted solution, but also every single backend can be isolated either globally or on a particular dimension such as brand
  227. 15:39and all of that can be done in seconds.
  228. 15:42Before I wrap up, let me maybe just talk very briefly and pull this back to that complaints project.
  229. 15:47So just to remind you that was the colleague facing agent which writes investigation summaries for summaries for complaint handlers.
  230. 15:53In that project, human feedback is a gate.
  231. 15:55It's not a thumbs up.
  232. 15:56It's not a tickbox activity.
  233. 15:58So if a complaint handler wants to rerun their investigation, they can't do so until they provided human feedback.
  234. 16:04We want to understand why they felt the need to do that rerun.
  235. 16:07But also it's allowed us to build up this quality data set of 14 14,000 customer of uh of colleague labels I guess in this case and that's really valuable in a lot of projects.
  236. 16:18We struggle to get a tenth of that number and I think the projects have also traded nicely here.
  237. 16:23So you know they found that judge problem in production we have judge calibration and regression checks because of that but equally the architecture that we built which relies heavily on commodopic
  238. 16:32they don't use that yet and they're going to be adopting that for their production monitoring I guess it's a glimpse inside an enterprise right so the the agent was the cheap part here that's code that we can produce to solve the business problem the valuation spine is the bit that we can then reuse again and again
  239. 16:48so to wrap up like if you are going to be shipping customerf facing agents in a regulated environment, then these are probably the points I would give you.
  240. 16:56I'm not going to go through everything.
  241. 16:57I'll maybe just pick a couple.
  242. 16:59So, three and four here, they're the they're the points with the actual production judge data, right?
  243. 17:04So, that judge pinned near the top, it's a broken instrument.
  244. 17:08Your judges are going to want to be overly positive.
  245. 17:10You need to fight against that.
  246. 17:11Compare the spans, not just the averages.
  247. 17:13Ensure the judge is actually matching the human reviewer.
  248. 17:16Fourth, the judge model itself does become part of that threshold config, right?
  249. 17:21So if you are going to be making changes to the judge model then uh you know you can introduce a breaking change without knowing it.
  250. 17:29Comet is obviously absolutely key here.
  251. 17:30So we have that for both halves both the generative AI and the traditional ML which we do still use a little bit.
  252. 17:36So and I guess the the final point here is next month I'll find out how much of this is actually true when we go live.
  253. 17:43So thanks a lot for listening.
  254. 17:44It was really a pleasure to get to speak to all of you.
  255. 17:47So I'll be at the comment booth after this.
  256. 17:48So if you do have any questions, you know, disagreements, etc., really happy to hear them.
  257. 17:52But thanks a lot for your time.