Stop Burning Tokens: Why self-improvement needs domain expertise first - Annabell Schäfer, Langfuse
AI Engineer · 17 min · 161 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.
- 00:00Hi everyone, my name is Annabelle.
- 00:02I'm a growth engineer at Lenfuse and we're the largest open source observability and evaluation platform for your AI system.
- 00:08And today I'm going to share about how you should stop burning your tokens and why you should start building in domain expertise early in into your loop design, but also into your overall um application design
- 00:19to make sure you're continuously improving and updating your application.
- 00:24It is June 2026 and the whole internet is about uh loops right now.
- 00:29So we have Boris Journey saying he doesn't write any prompts anymore.
- 00:32He has loops and Peter Steinberger being like you should be designing loops and not prompt your agents.
- 00:37And I mean the whole Kapathy auto research and auto improvement topic blew up earlier this year already.
- 00:43But all of them are coming a little bit from this de developer perspective.
- 00:46And um coding is one for for a good reason.
- 00:49One of the cases where this whole um automatically reaching a goal uh worked quite well because they've always had a at least one um target function that wasite quite clear.
- 00:59And this was uh does the code compile or not.
- 01:02And of course just because code compiles doesn't mean it's great and doesn't mean um that all the features are exactly how you wanted them.
- 01:08But you at least know that you shipped something that worked.
- 01:11And of course this was then expanded over time to to expand this target function.
- 01:15But essentially it's a does it work or does it not in all other fields and especially if you're building AI applications for some kind of domains like medicinal compliance or healthcare or all kinds of chatbots
- 01:30these target functions are uh not nearly as clear and a target that you give an agent is actually also always incomplete.
- 01:38So um you might initially think that you're trying to head down here uh but actually your optimal destination is up there and to get there and to understand this it takes quite some time and to figure this out
- 01:49and it's yeah it's just inherently a difficult problem especially if you are in a field where a clear yes or no like does the code compile um doesn't really uh cut it.
- 02:00So it is very difficult but at the same time we at length you see that the teams who are investing heavily here in the middle so uh making sure they capture what they actually want to work so the target function
- 02:11and build this out and make sure they have good evaluators that are evaluating this are the ones who manage to continuously upgrade and improve their application over time and also ship with confidence because if you know um it's working as you intended to h then you can also sleep um well at night in case you push a
- 02:27code change.
- 02:28Okay, so now we know it's super important and you should be doing it, but at the same kind it's time it's almost impossible to actually h get it right.
- 02:36Uh so we were setting out and wondering what's the clearest cut target function we can find um for an agent to use and also if you run an auto optimization
- 02:45on it h what can we learn about the role of target functions from from running it on it and the clearest cut target function we could find was a single label classification task that has has a very clearcut
- 02:57yes or no. So for example, let's say we have an item to categorize.
- 03:01There's a true label.
- 03:02For example, oh, it's an order.
- 03:03And then we have a set of available labels, order, complaint, inquiry.
- 03:06And our classifier then assigns um one label.
- 03:09And you can very clearly say is the true label equal to the predicted label.
- 03:13And if yes, um then this one is right and the next one might be wrong.
- 03:17And overall you can calculate an accuracy value and get a very clear signal from here.
- 03:23So we put this target function together with an agent and also with an optimizer.
- 03:28And how this minimal loop looked like I'm going to share with you now.
- 03:32So here's our minimal self-optimization loop.
- 03:35Up there in the first two rows we can see our target function.
- 03:39In our case we opted for classified um archive papers.
- 03:42So it's a set of papers that based on their primary um based on their title and abstract h got a primary label from the author um to categorize it for the other people in research.
- 03:55And um yeah, we're going to uh we have the the ground truth here and we have it in 200 um items in a fit data set, 100 in a validate data set, and 300 in a test data set.
- 04:05Um just to also make sure we're not overfitting.
- 04:07Then we have our agent, which is more or less just a a simple prompt.
- 04:12um uh based on GPD5 for nano because we wanted to see how a very small and cheap model performs on the auto improvement because the good ones actually got really really good but also very expensive
- 04:22um over time and we have this flash list of labels and then we have our optimization process that runs through uh cloud code leveraging cloud us 4.8 eight.
- 04:30So one of the frontier models and it proposes the prompt updates and has this context reference the GPT54 prompting guide as well as a task MD that is describing the loop.
- 04:40Looking a little bit closer on how this looks like.
- 04:42Here we can see our target function in this case especially our fit data set uh within length view.
- 04:48So we see an input column where the title and the abstracts are inside as well as an expected output column.
- 04:53So what kind of uh label should be applied and um on the those three different data sets the the idea is on the fit data set you run it you look for the errors and especially error clusters
- 05:05and um opus should then formulate hypothesis for prompt updates in the validation set we then check if those prompt updates actually also generalize to unseen data and then finally when we're like reaching a plateau or our stopping criteria
- 05:20um then we're running it on a test set to see how well we actually um generalize for untouched data that was not part of the training process.
- 05:28Our base prompt is a very flat list of labels and just a simple task classify this paper with a label.
- 05:34Um of course if uh if we would write the prompt we would probably add some pros how to think about it and all of this.
- 05:39But we just wanted to see what happens if we use the very base version um of this prompt and how the the system is dealing with it.
- 05:48And our leap loop is a step-by-step instructed uh loop um done through a task markdown file.
- 05:55Uh so the overall idea of the loop is first you run the base prompt on the fit and in the validate set to get like a baseline accuracy.
- 06:02You score it per item and overall then on the fit data set you do this error analysis.
- 06:07So you really look into what kind of categories frequently are done right?
- 06:10what kind of um item pairs are maybe often confused and also what's then the uh underlying abstract and title um belonging to it.
- 06:19So we can maybe find patterns there.
- 06:21Then the uh then float um proposes an update uh for the biggest error category and publishes a new prompt change and then reruns and only um accepts if this uh also improves on the validation set.
- 06:34And we have two stopping criteria.
- 06:36Either it's 15 runs uh completed or we have 92% accuracy reached.
- 06:40And as soon as this is happening or um it stops for some other reason, then we perform a final uh run on a test data set to see it.
- 06:48So yeah, here on the right you can see all of this is described in a markdown.
- 06:51We point at the data sets and we not even give it the test data set link.
- 06:55Um so it will not look into it before we wanted to.
- 07:00So what happened?
- 07:01Um yeah, I mean overall we can see here that there's a a tendency to increase uh but also we can see that um yeah we reached a 15% uptake uh from our baseline which is actually quite solid.
- 07:12Um the first run ended at uh 68% accuracy and on our third fourth iteration um we went all the way to 83% which then also afterwards um plateaued a bit.
- 07:25Overall it kept this level around 80% and we wondering okay actually we wanted the perfect clearcut target function.
- 07:32Uh but then looking deeper into the data and how those labels are chosen we realize okay there's um some creative freedom for the authors to choose what kind of label they want.
- 07:41Uh so even though description might make sense uh they might have chosen in that moment that they actually want to go for a different label and that's then also of course not recorded in here.
- 07:52And we also saw this uh improvement then generalized to the um test data set on yeah to 80.2%.
- 08:00Um so the generalization was also on the 300 item unseen data um quite good and uh in a way that you could say okay this actually worked and um the most interesting thing uh we thought is that the first iteration
- 08:14immediately gained 10% and then it was only a little bit movement.
- 08:17So uh it somehow got a lot of information from this very first run already and made a made a big uptick uh that we can can see here um up until the yeah very close to the final result also
- 08:29and we um wanted to look closer into what it actually did here.
- 08:33So here we can see on the left side the um flat label list prompt.
- 08:38So here on the left again a screenshot from our platform where we managed the prompts and on the right side we can see what happened.
- 08:45So the very first thing it um added is a general classification approach.
- 08:50So how should the model think about um the behavior of uh choosing one of these labels?
- 08:56So when what's what's the main goal of doing so?
- 09:00Then there's some information on how to decide between two very similar classes and then also some um related confused patterns.
- 09:07So it's uh basically telling it um when to choose which and under which conditions and how to go about it and to rather go for the more specific label than for the more broad label because there's some implicit testing in the label structure as well.
- 09:21And then it also added some um examples for the the item pairs that it um yeah frequently missed or frequently mclassified.
- 09:30So this is what uh we can see here.
- 09:32Uh so overall the approach was um improvement loop added rules and examples and I would have probably I was surprised I would have probably um spontaneously added descriptions to the labels.
- 09:42Uh but the prompting guide or the model together with prompting guide um decided that actually the right approach is here and I mean it worked.
- 09:49So uh I'm not going to going to interfere here.
- 09:53Um yeah what we wanted to dive deeper a bit more then is what actually happened in this one 10% uptick uh that we have.
- 10:01So let me remove myself a little bit because we need the bottom right corner.
- 10:05So this is the um the reasoning step that clude oppus 4.8 took uh in this one jump from 68% to 78%.
- 10:13And what we can see here is that it has a very clear okay we have 64 errors.
- 10:18These are the dominating patterns.
- 10:20These are the number one answer sync and this is the biggest confusion.
- 10:24So also what are the two labels that are most frequently confused and where there's like um issues coming up.
- 10:30And then it's forming a hypothesis and saying okay this loop will extract ex exactly address this pattern.
- 10:36So it got a very clearcut um clearly quantifiable and reliable failure mode because they were just wrong on a yes no right wrong basis.
- 10:46Um they also had it had a lot of data to look at.
- 10:49we had a 200 item um fit data set which probably in most real cases um yeah it takes some time to get there and to also like make sure that it was only 10 labels so each of them got covered like
- 11:02um enough times that that it can get a signal from it um yeah and like this it could form a datab hypothesis and ended up uh returning a 10% gain on the first uh run and then I mean it was a bit of movement and we also found a better version then uh but the biggest jump was
- 11:18uh just the very first one from a very clear-cut signal, we could have probably stopped there and already have very good baseline.
- 11:26So um given this right wrong high signal feedback works really really well on this classification test but also knowing that this is not um the case for all others like there's barely any deterministic
- 11:38yes no target functions in most cases you will run it this time and next time you get a different um next time you run the same evaluator you get a different
- 11:47answer from the same kind of evaluation you ran um just because yeah LLM as a judge is also the nondeterministic we were wondering how can we translate this right wrong high signal feedback into other applications.
- 11:59So how can we try to shape this in a way it also works for your um vertical domain expert AI agent or for your uh automation of requirements extraction in
- 12:10medicine device um compliance or whatever your use case might be.
- 12:14[snorts]
- 12:14And um for this um we overall see the approach working that um while the market for for a good reason likes those um evaluators like correctness or helpfulness or hallucination
- 12:27which like early in the days um were were a good um thing to go for.
- 12:32Um this is actually if you're trying to um autoimprove against this a rather low signal especially also because it's put on a often on a scale out of like between zero and one and 10 one and five and
- 12:46for this to really work properly you need to define each of those numbers.
- 12:49What does it mean in which context would you need which number?
- 12:52Uh which kind of criteria need to be met.
- 12:54Uh but this is most of the time also not done.
- 12:56So it's just choosing a number between zero and one and um depending on the uh context it might just uh totally change perspective and is therefore rather low signal and also probably inconsistent
- 13:08um across runs.
- 13:09What we see uh working instead is uh really looking into um what are the quality criteria that you want to work uh for your application.
- 13:18So what does good mean?
- 13:20Uh so for example instead of correctness the answer is based on the knowledge base yes no. So for example, if there's a snippet about internal information in the answer and you can check is it actually also in the ret retrieved context we did in the previous step or also if you're frequently struggling with cor using your correct
- 13:38brand voice you could look into okay um is it this time correct?
- 13:43Did we make sure that our name was written correctly?
- 13:45I've also seen companies that have English names that are checking for did we not accidentally translate our name to Spanish?
- 13:52things like this.
- 13:53And also um uh one thing that works well because it's also this categorization yes no is maybe some known failure modes.
- 14:01So which out of these five types of failures uh happened here and um can you categorize it?
- 14:08And these are only a few examples.
- 14:10Um we usually see that these are created by looking into the data, understanding what good means, what are things that are important to you and especially to your domain experts and creating these high signal um feedback loops.
- 14:23Um because if you can't do code compiles, you need to wrap your head a little bit differently around um what is good and what is not.
- 14:31So um this is the one side.
- 14:33The other part is of course um the volume that you need.
- 14:35We had a like luckily we could have used thousands of examples.
- 14:39there's so many papers out there.
- 14:41We opted for like 200 train 100 validate um 300 test um just because we wanted to see that it properly generalizes um but we made the experience that this already got gave back a lot of um high signal feedback
- 14:54um so depending on the complexity of your application and the steps in there of course it might differ um but having the volume there and having the high signal feedback
- 15:01um oops are the foundation.
- 15:03So how do you get there?
- 15:05So the most important thing we see is working with your experts and this is like repeated advice and everyone's saying it and everyone's saying talk to your customers.
- 15:14Um but here it's something you can actually start to encode the domain expertise into very concrete examples.
- 15:21So use them to create examples what should come out of it.
- 15:24Look at those samples run sample runs together with them and also ask okay but why is it like this here and here um the other way?
- 15:31Uh because like this you can often also get information out of them that they implicitly think is clear and also um really understand um how the decisions are taken there and like this identify failure modes of your application
- 15:43and also define what good means because you probably need both and then use them to find these high signal evaluators.
- 15:50Then um as soon as you have this baseline and um you might hit production um review this data and don't review it only with your coding agents but review it as a human.
- 15:59look through it, understand like what is the the scope initially and um uh what is then being done with this application.
- 16:08This can shift over time.
- 16:09The failure modes can change.
- 16:11Um people might try to do other things and it's potential for feature um expansion and to really understand how the system works and fails in production um is necessary to to cover the typical failure modes and catch them uh before your customers do.
- 16:26And then um finally um think about the whole thing as a system that generalizes.
- 16:31So you're trying to build up examples that are representative of what you might want to hit uh in production at some point.
- 16:38And um for this to properly generalize, you need to uh bake in mechanisms for validation.
- 16:44Uh so like in traditional machine learning context, um the validation approach is actually quite typical.
- 16:49So people um all the time make sure that they're actually validating if uh things don't overfitit.
- 16:55And um this combined with like a real mechanism combined with like the instructions in your loop and giving the system an escape hatch instead of having it work for hours and hours uh hitting a wall and uh burning tokens.
- 17:08Um yeah are very important divas um to actually uh make sure that you're not um just burning tokens but actually looping towards um a system where a human and your agent together collaborate on an improving system.
- 17:23Perfect.
- 17:24Thank you so much for uh listening to me.
- 17:26Um very excited that you took the time.
- 17:28And if you want to know more about Lenfuse and also how we think about these topics, you can find more on length.com.
- 17:33And I'm super excited to meet some of you at some point in person.