AIAI EngineerJul 18, 2026· 17:39

Stop Burning Tokens: Why self-improvement needs domain expertise first - Annabell Schäfer, Langfuse

Annabell Schäfer, Growth Engineer at Langfuse, argues that successful auto-improvement loops require domain expertise and high-signal target functions, not just generic evaluators. She details an experiment classifying arXiv papers with a minimal loop using GPT-5 for nano and Claude Opus 4.8 as an optimizer, achieving a 15% accuracy jump from 68% to 83% in four iterations. The first iteration alone gained 10% by adding classification rules and examples based on error analysis of a 200-item dataset. Schäfer advises replacing vague metrics like correctness with yes/no quality criteria (e.g., 'answer uses knowledge base'), and working with domain experts to identify failure modes and define what 'good' means. She emphasizes validation to prevent overfitting and treating the system as generalizing from representative examples, not just burning tokens on endless loops.

Transcript

Intro0:00

Annabell Schäfer0:01

Hi everyone, my name is Annabell. I'm a Growth Engineer at Langfuse, and we're the largest Open Source Observability and Evaluation Platform for your AI system. And 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 application design, to make sure you're continuously improving and updating your application.

It is June 2026, and the whole internet is about loopsright now. So we have Boris Cherny saying he doesn't write any prompts anymore, he has loops, and Peter Steinberger being like, you should be designing loops and not prompt your agents.

Loops & Targets0:25

Annabell Schäfer0:38

And I mean, the whole Kapati auto-research and auto-improvement topic blew up earlier this year already. But all of them are coming a little bit from the developer perspective, and coding is one, for good reason, one of the cases where this whole

automatically reaching a goal worked quite well, because they've always had at least one target function that was quite clear, and this was, does the code compile or not. And of course, just because code compiles doesn't mean it's great, and doesn't mean that all the features are exactly how you wanted them, but you at least know that you shipped something that worked.

And of course, this was then expanded over time to expand this target function, but 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, these target functions are not nearly as clear.

And a target that you give an agent is actually also always incomplete. So you might initially think that you're trying to head down here, but actually your optimized destination is up there, and to get there and to understand this, it takes quite some time and to figure this out.

And it's, yeah, it's just inherently a difficult problem, especially if you're in a field where a clear yes or no, like does the code compile, doesn't really cut it. So it is very difficult, but at the same time, we at Langfuse see that the teams who are investing heavily here in the middle, so making sure they capture what they actually want to work, so the target function, and 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 it's working as you intended to, then you can also sleep well at night in case you push a code change. Okay, so now we know it's super important and you should be doing it, but at the same kind of time, it's almost impossible to actually get itright.

Our Experiment2:37

Annabell Schäfer2:37

So we were setting out and wondering, what's the clearest cut target function we can find for an agent to use? And also, if you run an auto-optimization on it, what can we learn about the role of target functions from running it on it?

And the clearest cut target function we could find was a single-label classification task that has a very clear cut, yes or no. So for example, let's say we have an item to categorize, there's a tool label, for example, oh, it's an order, and then we have a set of available labels, order complaint, inquiry, and our classifier then assigns one label, and you can very clearly say, is the true label equal to the predicted label, and if yes, then this one isright, and the next one might be wrong, and overall you can calculate an accuracy value and get a very clear signal from here.

So we put this target function together with an agent and also with an optimizer, and how this minimal loop looked like, I'm going to share with you now. So here's our minimal self-optimization loop. Up there in the first two rows, we can see our target function.

In our case, we opted for classified archive papers, so it's a set of papers that based on their primary, based on their title and abstract, got a primary label from the author to categorize it for the other people in research.

And yeah, we're going to, we have the ground truth here, and we have it in 200 items in a fit dataset, 100 in a validate dataset, and 300 in a test dataset, just to also make sure we're not overfitting.

Then we have our agent, which is more or less just a simple prompt based on GPT-5 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 over time.

And we have this flat list of labels, and then we have our optimization process that runs through Claude Code, leveraging Claude Opus 4.8, so one of the frontier models. And it proposes the prompt updates and has this context reference, the GPT-5 for prompting guide, as well as a task MD that is describing the loop.

Looking a little bit closer on how this looks like, here we can see our target function, in this case especially our fit dataset within Langfuse. So we see an input column where the title and the abstracts are inside, as well as an expected output column, so what kind of label should be applied.

And on those three different datasets, the idea is on the fit dataset, you run it, you look for the errors, and especially error clusters, and Opus should then formulate hypotheses 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 reaching a plateau or our stopping criteria, then we're running it on a test set to see how well we actually generalize for untouched data that was not part of the training process.

Our base prompt is a very flat list of labels, and just a simple task, classify this paper with a label. Of course, if we would write the prompt, we would probably add some pros, how to think about it, and all of this, but we just wanted to see what happens if we use the very base version of this prompt and how the system is dealing with it.

And our leap loop is a step-by-step instructed loop done through a task markdown file. So the overall idea of the loop is, first you run the base prompt on the fit and in the validate set to get a baseline accuracy, you score it per item and overall.

Then on the fit dataset, you do this error analysis, so you really look into what kind of categories frequently are doneright, what kind of item pairs are maybe often confused, and also what's then the underlying abstract and title belonging to it, so we can maybe find patterns there.

Then Claude proposes an update for the biggest error category and publishes a new prompt change, and then reruns and only accepts if this also improves on the validation set. And we have two stopping criteria, either it's 15 runs completed or we have 92% accuracy reached.

And as soon as this is happening, or it stops for some other reason, then we perform a final run on a test dataset to see it. So yeah, here on theright, you can see all of this is described in a markdown, we point at the datasets, and we not even give it the test dataset link, so it will not look into it before we want it to.

So what happened? Yeah, I mean, overall we can see here that there's a tendency to increase, but also we can see that, yeah, we reached a 15% uptake from our baseline, which is actually quite solid. The first run ended at 68% accuracy, and on our fourth iteration, we went all the way to 83%, which then also afterwards plateaued a bit.

Results7:01

Annabell Schäfer7:26

Overall, it kept this level around 80%, and we were wondering, okay, actually we wanted the perfect clear-cut target function, but then looking deeper into the data and how those labels are chosen, we realized, okay, there's some creative freedom for the authors to choose what kind of label they want.

So even though a description might make sense, 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. And we also saw this improvement then generalized to the test dataset on, yeah, to 80.2%, so the generalization was also on the 300 item unseen data quite good, and in a way that you could say, okay, this actually worked.

The First Jump8:10

Annabell Schäfer8:10

And the most interesting thing we thought is that the first iteration immediately gained 10%, and then it was only a little bit movement. So it somehow got a lot of information from this very first run already and made a big uptick that we can see here up until the, yeah, very close to the final result also.

And we wanted to look closer into what it actually did here. So here we can see on the left side the flat label list prompt. So here on the left, again, a screenshot from our platform where we managed the prompt, and on theright side we can see what happened.

So the very first thing it added is a general classification approach. So how should the model think about

the behavior of choosing one of these labels? So what's the main goal of doing so? Then there's some information on how to decide between two very similar classes, and then also some related confused patterns. So it's basically telling it 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 nesting in the label structure as well.

And then it also added some examples for the item pairs that it, yeah, frequently missed or frequently misclassified. So this is what we can see here. So overall, the approach was improvement loop, added rules and examples, and I would have probably, I was surprised, I would have probably spontaneously added descriptions to the labels, but the prompting guide, or the model together with the prompting guide, decided that actually theright approach is here, and I mean, it worked, so I'm not going to interfere here.

Yeah, what we wanted to dive deeper a bit more then is what actually happened in this one 10% uptick that we have. So let me remove myself a little bit, because we need the bottomright corner. So this is the reasoning step that Claude Opus 4.8 took in this one jump from 68% to 78%.

And what we can see here is that it has a very clear, okay, we have 64 errors, these are the dominating patterns, these are some number one answer sync, and this is the biggest confusion, so also what are the two labels that are most frequently confused, and where there's issues coming up.

And then it's forming a hypothesis and saying, okay, this loop will exactly address this pattern. So it got a very clear cut, clearly quantifiable and reliable failure mode, because they were just wrong on a yes/no,right/wrong basis. They also had, it had a lot of data to look at.

We had a 200 item fit dataset, which probably in most real cases, yeah, it takes some time to get there, and to also make sure that it was only 10 labels, so each of them got covered enough times that it can get a signal from it.

Yeah, and this could form a database hypothesis and ended up returning a 10% gain on the first run. And then, I mean, it was a bit of movement, and we also found a better version then, but the biggest jump was just the very first one from a very clear cut signal.

We could have probably stopped there and already have a very good baseline. So given thisright/wrong high signal feedback works really, really well on this classification task, but also knowing that this is not the case for all others, like there's barely any deterministic yes/no target functions.

Beyond Classification11:22

Annabell Schäfer11:40

In most cases, you will run it this time, and next time you get a different, next time you run the same evaluator, you get a different answer from the same kind of evaluation you ran, just because, yeah, LLM as a judge is also non-deterministic.

We were wondering how can we translate thisright/wrong high signal feedback into other applications, so how can we try to shape this in a way it also works for your vertical domain expert AI agent, or for your automation of requirements extraction in medicine device compliance, or whatever your use case might be.

And for this, we overall see the approach working, that while the market for good reason likes those evaluators like correctness, or helpfulness, or hallucination, which early in the days were a good thing to go for, this is actually, if you're trying to auto-improve against this, a rather low signal, especially also because it's put on a, often on a scale out of between 0 and 1, 1 and 10, 1 and 5.

And for this to really work properly, you need to define each of those numbers. What does it mean, in which context would you need which number, which kind of criteria need to be met? But this is most of the time also not done, so it's just choosing a number between 0 and 1, and depending on the context, it might just totally change perspective, and is therefore a rather low signal, and also probably inconsistent across runs.

What we see working instead is really looking into what are the quality criteria that you want to work for your application. So what does good mean? So for example, instead of correctness, the answer is based on a 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 retrieved context we did in the previous step? Or also, if you're frequently struggling with using your correct brand voice, you could look into, okay, is it this time correct?

Did we make sure that our name was written correctly? I've also seen companies that have English names that are checking for, did we not accidentally translate our name to Spanish, things like this. And also, one thing that works well, because it's also this categorization, yes/no, is maybe some known failure mode.

So which out of these five types of failures happened here, and can you categorize it? And these are only a few examples. We usually see that these are created by looking into the data, understanding what good means, what are the things that are important to you, and especially to your domain experts, and creating these high signal feedback loops, because if you can't do code compiles, you need to wrap your head a little bit differently around what is good and what is not.

So this is the one side. The other part is, of course, the volume that you need. We had a, like, luckily we could have used thousands of examples. There's so many papers out there. We opted for like 200 train, 100 validate, 300 test, just because we wanted to see that it properly generalizes.

But we made the experience that this already gave back a lot of high signal feedback, so depending on the complexity of your application and the steps in there, of course it might differ. But having the volume there and having the high signal feedback loops are the foundation.

Expert Input14:49

Annabell Schäfer15:04

So how do you get there? So 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. But here, it's something you can actually start to encode the domain expertise into very concrete examples.

So use them to create examples. What should come out of it? Look at those sample runs together with them, and also ask, okay, but why is it like this here and here the other way? Because like this, you can often also get information out of them that they implicitly think is clear, and also really understand how the decisions are taken there, and like this, identify failure modes of your application, and also define what good means, because you probably need both, and then use them to find these high signal evaluators.

Then, as soon as you have this baseline and you might hit production, review this data. And don't review it only with your coding agents, but review it as a human. Look through it, understand what is the scope initially, and

Production Mindset15:51

Annabell Schäfer16:07

what is then being done with this application. This can shift over time, the failure modes can change, people might try to do other things, and it's potential for feature expansion. And to really understand how this system works and fails in production is necessary to cover the typical failure modes and catch them before your customers do.

And then finally, think about the whole thing as a system that generalizes. So you're trying to build up examples that are representative of what you might want to hit in production at some point, and for this to properly generalize, you need to bake in mechanisms for validation.

So like in traditional machine learning context, the validation approach is actually quite typical. So people all the time make sure that they're actually validating if things don't overfit. And this combined with a real mechanism, combined with the instructions in your loop, and giving the system an escape hatch instead of having it work for hours and hours, hitting a wall and burning tokens, yeah, are very important device to actually make sure that you're not just burning tokens, but actually looping towards a system where a human and your agent together collaborate on an improving system.

Perfect. Thank you so much for listening to me. Very excited that you took the time, and if you want to know more about Langfuse and also how we think about these topics, you can find more on langfuse.com, and I'm super excited to meet some of you at some point in person.