1 00:00:09,446 --> 00:00:13,046 Lee: Hello and welcome to Software Architecture Insights, your go-to 2 00:00:13,046 --> 00:00:17,186 resource for empowering software architects and aspiring professionals 3 00:00:17,456 --> 00:00:21,686 with the knowledge and tools they require to navigate the complex 4 00:00:21,686 --> 00:00:24,476 landscape of modern software design. 5 00:00:27,500 --> 00:00:29,526 Think about the last function you wrote. 6 00:00:30,747 --> 00:00:34,834 You called it a thousand times in a loop, and you never thought twice about it. 7 00:00:35,655 --> 00:00:36,565 Why would you? 8 00:00:36,944 --> 00:00:39,758 It ran in microseconds, and it cost nothing. 9 00:00:41,224 --> 00:00:42,803 Now change one thing. 10 00:00:43,855 --> 00:00:48,967 That function sends a request to an AI model, and each call takes a couple 11 00:00:48,974 --> 00:00:52,355 seconds, and each call sends you a bill. 12 00:00:53,604 --> 00:00:56,651 Your loop just became a budget decision. 13 00:00:57,651 --> 00:01:01,629 In September, I wrote an article called "Your Function Call Was Free. 14 00:01:01,801 --> 00:01:05,994 This One Isn't." It's part of my series on AI-native architecture. 15 00:01:06,691 --> 00:01:11,966 Today, I want to go past the article into the places that bites hardest. 16 00:01:12,781 --> 00:01:14,670 Here's the idea, in case you missed it. 17 00:01:15,168 --> 00:01:17,474 The original article is linked in the show notes. 18 00:01:18,398 --> 00:01:24,436 For most of our careers, calling a function has been free, fast and free. 19 00:01:25,552 --> 00:01:30,522 Then distributed systems came along and a call over the network wasn't free anymore. 20 00:01:31,265 --> 00:01:35,065 It could be slow, it could fail, and we had to design 21 00:01:35,065 --> 00:01:36,798 our systems around that fact. 22 00:01:38,200 --> 00:01:41,344 AI inference is the next version of that. 23 00:01:42,177 --> 00:01:47,887 Every call to a model costs real money and takes real time, so you 24 00:01:47,897 --> 00:01:49,815 can't treat it like a function call. 25 00:01:50,271 --> 00:01:52,188 It has to be part of the design. 26 00:01:53,511 --> 00:01:57,772 That's the second of the four properties I use to define an AI-native system. 27 00:01:58,181 --> 00:02:00,427 I call it inference economics. 28 00:02:01,427 --> 00:02:03,104 The article used an example. 29 00:02:03,284 --> 00:02:04,009 I'll keep it short. 30 00:02:04,825 --> 00:02:07,427 Picture a support assistant that handles fifty thousand 31 00:02:07,429 --> 00:02:08,948 customer conversations a month. 32 00:02:09,516 --> 00:02:14,703 Each conversation makes six model calls, one to classify the question, 33 00:02:15,342 --> 00:02:19,421 one to find the right documents, a few to draft the answer, and 34 00:02:19,422 --> 00:02:20,978 then one to verify the results. 35 00:02:21,678 --> 00:02:25,267 That's three hundred thousand model calls a month. 36 00:02:26,351 --> 00:02:29,412 Now, say every one of those calls goes to the biggest, 37 00:02:29,446 --> 00:02:31,212 most expensive model you have. 38 00:02:31,717 --> 00:02:35,561 Not because anyone decided that model was needed, just because that's the 39 00:02:35,562 --> 00:02:41,115 model the prototype used Classifying a question into one of 12 categories 40 00:02:41,159 --> 00:02:43,464 doesn't need your most expensive model. 41 00:02:44,518 --> 00:02:48,868 Writing a careful answer to an angry customer, well, that might. 42 00:02:50,323 --> 00:02:54,153 Which model handles which step is a design decision. 43 00:02:54,953 --> 00:02:59,289 The article called that model routing, and if nobody makes that decision on 44 00:02:59,300 --> 00:03:01,831 purpose, the prototype makes it for you. 45 00:03:02,894 --> 00:03:06,100 Here's what the article didn't go into, and it's where I'm seeing 46 00:03:06,101 --> 00:03:09,465 the biggest surprises now: agents. 47 00:03:10,335 --> 00:03:13,099 The support assistant makes six calls per conversation. 48 00:03:13,522 --> 00:03:14,423 You can count them. 49 00:03:14,806 --> 00:03:15,791 You can multiply. 50 00:03:16,053 --> 00:03:17,322 You can predict the bill. 51 00:03:18,390 --> 00:03:19,592 An agent is different. 52 00:03:20,188 --> 00:03:23,759 You give it a goal, and it decides how many steps to take. 53 00:03:24,292 --> 00:03:29,133 It calls the model, looks at the result, and decides what to do next. 54 00:03:30,258 --> 00:03:35,410 Sometimes that action can take three calls, sometimes it takes 55 00:03:35,410 --> 00:03:38,611 40, and sometimes it gets stuck. 56 00:03:39,140 --> 00:03:43,201 It tries something, it fails, it tries again, and it keeps trying. 57 00:03:44,148 --> 00:03:48,512 In a normal program, a loop like that burns some amount of CPU. 58 00:03:49,452 --> 00:03:51,430 Somebody notices eventually. 59 00:03:52,659 --> 00:03:56,810 With an agent, every pass through the loop costs real dollars. 60 00:03:57,764 --> 00:04:01,129 A stuck agent is a meter running with nobody watching it. 61 00:04:01,641 --> 00:04:06,161 So every agent needs limits, a maximum number of steps, a maximum 62 00:04:06,163 --> 00:04:11,136 spend per task, and a clear rule for what happens when it hits the limit. 63 00:04:11,736 --> 00:04:12,558 Does it stop? 64 00:04:13,322 --> 00:04:15,194 Does it hand the task to a person? 65 00:04:15,964 --> 00:04:18,217 Does it return its best answer so far? 66 00:04:19,319 --> 00:04:23,773 Those limits belong in the design of the application from the start, 67 00:04:24,368 --> 00:04:27,483 the same way a timeout is part of the design of a network call. 68 00:04:28,460 --> 00:04:33,660 If your agent has no step limit today, that's the first thing I'd fix. 69 00:04:34,812 --> 00:04:37,263 The second thing I'd change is the design review. 70 00:04:38,274 --> 00:04:41,661 Most teams have some kind of review before a big feature gets built. 71 00:04:42,431 --> 00:04:44,043 Someone asks about scale. 72 00:04:44,294 --> 00:04:46,080 Somebody asks about security. 73 00:04:46,526 --> 00:04:52,532 Someone asks about what happens when a dependency is down Add one more question. 74 00:04:53,104 --> 00:04:56,004 What does a single use of this feature cost? 75 00:04:56,863 --> 00:05:00,361 Not the monthly bill, one single use. 76 00:05:00,897 --> 00:05:03,892 One conversation, one document, one search. 77 00:05:05,258 --> 00:05:08,955 Back in November, in the level two episode, I talked about 78 00:05:08,964 --> 00:05:10,868 how to work out that number. 79 00:05:11,507 --> 00:05:18,643 The short version is you tag the calls, count what goes in and out, and divide. 80 00:05:19,525 --> 00:05:21,328 The point here is when you ask. 81 00:05:22,060 --> 00:05:26,069 Ask it before the feature is built as an estimate, then check 82 00:05:26,070 --> 00:05:27,633 the estimate once it's live. 83 00:05:28,633 --> 00:05:30,806 Something useful happens when you do that. 84 00:05:31,518 --> 00:05:33,722 The team starts designing for it. 85 00:05:34,324 --> 00:05:37,217 Somebody asks whether a step can use a smaller model. 86 00:05:37,769 --> 00:05:41,454 Somebody asks whether the same question gets asked a lot, and 87 00:05:41,454 --> 00:05:43,195 whether the answer can be reused. 88 00:05:44,281 --> 00:05:47,714 That last idea is basic caching, and the article made a point 89 00:05:47,714 --> 00:05:49,713 about it I want to repeat here. 90 00:05:50,523 --> 00:05:54,284 With normal caching, you match on the exact request. 91 00:05:55,067 --> 00:06:01,190 With AI, two people ask the same question in different words, so you match on 92 00:06:01,195 --> 00:06:04,422 meaning instead of the exact text. 93 00:06:05,681 --> 00:06:08,890 But then you have to decide how close is close enough. 94 00:06:09,914 --> 00:06:13,191 Get that decision wrong and you hand one customer the answer 95 00:06:13,191 --> 00:06:14,564 to someone else's question. 96 00:06:15,775 --> 00:06:19,190 The threshold is a correctness decision. 97 00:06:19,831 --> 00:06:26,008 It belongs in the design with a name next to it So far, I've talked about money. 98 00:06:26,743 --> 00:06:29,873 The property has a second half, and it's time. 99 00:06:30,804 --> 00:06:32,698 A model call can take seconds. 100 00:06:32,963 --> 00:06:35,140 Your user notices seconds. 101 00:06:36,049 --> 00:06:40,070 Chain six calls together, one after another, and your support assistant 102 00:06:40,076 --> 00:06:42,481 takes ten or fifteen seconds to answer. 103 00:06:43,492 --> 00:06:48,194 That can be the difference between a feature people use and one they avoid. 104 00:06:49,194 --> 00:06:52,514 This is where the distributed systems lessons come straight back. 105 00:06:53,136 --> 00:06:55,721 Which calls can run at the same time? 106 00:06:56,240 --> 00:06:59,431 Which ones can happen before the user asks? 107 00:07:00,169 --> 00:07:03,722 Which ones can a smaller, faster model handle? 108 00:07:04,207 --> 00:07:08,551 The same routing decision that saves money often saves time too. 109 00:07:09,283 --> 00:07:11,159 That's a nice bonus when it happens. 110 00:07:11,619 --> 00:07:13,325 Just don't count on it happening. 111 00:07:14,119 --> 00:07:20,097 Sometimes the cheaper path is the slower one, and somebody has to choose which. 112 00:07:21,097 --> 00:07:25,264 Now, one more thing from the article that surprises some people. 113 00:07:26,481 --> 00:07:30,346 Your AI costs can double without anyone shipping a line of code. 114 00:07:31,287 --> 00:07:33,545 Users start asking longer questions. 115 00:07:34,219 --> 00:07:39,806 Someone adds more documents to the search index, so every prompt gets bigger. 116 00:07:40,901 --> 00:07:44,027 A product change sends harder questions to the assistant. 117 00:07:45,311 --> 00:07:50,789 Now, none of that shows up in the deploy log, but it does show 118 00:07:50,791 --> 00:07:52,736 up on the invoice a month later. 119 00:07:53,803 --> 00:07:58,556 So watch the cost per use the way you watch latency, on a dashboard 120 00:07:58,605 --> 00:08:00,627 with an alert owned by a team. 121 00:08:01,135 --> 00:08:06,969 If you only look at the monthly bill, you'll find out a month too late Here's 122 00:08:06,992 --> 00:08:09,421 why I keep calling this architecture. 123 00:08:10,411 --> 00:08:13,967 Optimization is what you do after something works. 124 00:08:14,052 --> 00:08:16,865 You measure, you find the slow part, you fix it. 125 00:08:18,312 --> 00:08:23,060 Model routing, agent limits, caching thresholds, cost ownership. 126 00:08:24,185 --> 00:08:26,526 Those are hard to add later. 127 00:08:27,521 --> 00:08:30,205 They change how the pieces all fit together. 128 00:08:31,205 --> 00:08:36,004 A system that wasn't designed with them is what I call bolt-on AI. 129 00:08:36,520 --> 00:08:40,585 It works, it demos well, and it gets more expensive every month in 130 00:08:40,587 --> 00:08:42,548 ways that nobody can really explain. 131 00:08:43,563 --> 00:08:49,026 A system designed around them is what I mean by AI native, and in two weeks, 132 00:08:49,069 --> 00:08:53,497 I'm going to spend a whole episode on exactly what I mean by that term. 133 00:08:54,497 --> 00:08:58,691 So this week, find every agent you run. 134 00:08:59,581 --> 00:09:02,831 Check that each one has a step limit and a spending limit. 135 00:09:03,900 --> 00:09:05,960 Pick your busiest AI feature. 136 00:09:06,836 --> 00:09:12,186 Write down which model each step uses and write down why. 137 00:09:13,295 --> 00:09:17,400 If the answer is, "That's what the prototype used," you've found your 138 00:09:17,411 --> 00:09:22,839 first design decision And add one question to your next design review. 139 00:09:23,781 --> 00:09:27,579 What does one use of this feature cost? 140 00:09:28,640 --> 00:09:30,886 Your function calls used to be free. 141 00:09:31,987 --> 00:09:37,775 Your networking calls were a bit more expensive, but still not that expensive. 142 00:09:39,145 --> 00:09:41,622 This one isn't. 143 00:09:42,225 --> 00:09:46,544 It is expensive, both in cost and in time. 144 00:09:47,443 --> 00:09:51,477 Design like you know that The original article is linked in the 145 00:09:51,477 --> 00:09:55,233 show notes along with the rest of the AI Native Architecture series 146 00:10:13,787 --> 00:10:16,697 Lee: Thank you for joining us on Software Architecture Insights. 147 00:10:17,297 --> 00:10:21,407 If you found this episode interesting, please tell your friends and colleagues. 148 00:10:21,827 --> 00:10:24,437 You can listen to Software Architecture Insights on all 149 00:10:24,437 --> 00:10:26,357 of the major podcast platforms. 150 00:10:27,377 --> 00:10:31,297 And if you want more from me, take a look at some of my many articles 151 00:10:31,297 --> 00:10:34,157 at softwarearchitectureinsights.com. 152 00:10:34,157 --> 00:10:40,057 And while you're there, join the 2000 people who have subscribed to my 153 00:10:40,057 --> 00:10:44,917 newsletter, so you always get my latest content as soon as it's available. 154 00:10:50,124 --> 00:10:52,974 Thank you for listening to Software Architecture Insights.