Can we teach LLMs to use design patterns? A case of Singleton

LLMs are good at writing code that works. Give them a task and they will produce a function that passes the tests, most of the time. But software engineering is more than passing tests. It is also about design, about structure and about using the shared language that we, developers, have built over decades. Design patterns are a big part of that language, and LLMs are not very good at following them unless we push them.

So in our latest paper, presented at PROMISE ’26 in Montreal, Viktor Kjellberg, Farnaz Fotrousi and I asked a simple question: how do we guide an LLM so that it actually uses a design pattern? We started with the simplest one we could think of, the Singleton. One class, one instance, one global access point. If the models can’t do that, they won’t do Observer or Strategy either.

Link to the paper: https://doi.org/10.1145/3803846.3807469

What we did

We took 13 LLMs (GPT-5 mini, GPT-4o mini, GPT-OSS, Llama 3.3, Code Llama, Gemma 3, Qwen3, Qwen3 Coder, Mistral and two DeepSeek models) and asked them to solve the 164 Java tasks in HumanEval-X. First without any guidance, as a baseline. Then with four strategies:

  1. Guiding with instructions – just tell the model to use Singleton.
  2. Self-improvement – tell the model, yes or no, whether the code is a Singleton and let it try again (up to 10 times).
  3. Tool-supported self-improvement – a checker tells the model exactly which property is missing: private constructor, static instance or global access point.
  4. Tool-supported few-shot prompting – the same feedback, plus two examples of correct Singleton classes.

For each strategy we measured two things: how well the code follows Singleton (we call it the Singleton score), and whether the code still passes the tests.

What we found

Without guidance, no model produced a Singleton. Not a single one. That’s not surprising, since none of the tasks needs one, but it shows that the models won’t use a pattern unless asked.

Once asked, things change quickly. Just giving the instruction got Llama 3.3 and Gemma 3 (27B) to a perfect Singleton score. Llama 3.3 also passed 34.1 percentage points more tests than its baseline. GPT-4o mini went from a pass rate of 4.3% to almost 60%. It seems that asking for a bit of structure made some models think harder about the whole solution.

Simple yes/no feedback worked surprisingly well. Qwen3 (8B) reached a Singleton score of 99.2% and its pass rate went up to 58.6%. Telling the model exactly what was missing pushed even more models to 100%.

The examples, on the other hand, did not help much. For several models the pass rate actually dropped with few-shot prompting. More context is not always better context.

And the results are very model-dependent. DeepSeek Coder and Gemma 3 (4B) got the pattern right but lost functionality. Most of Code Llama’s compiler errors came from it writing text instead of code. Mistral fulfilled the Singleton properties but 55% of its compiler errors came from referencing libraries that were not there.

What this means

My takeaway is that we can guide LLMs towards good design with quite simple means. We don’t need fine-tuning or a big framework. A checker that says “this is not a Singleton, the constructor should be private” goes a long way. But there is no single strategy that works for all models, so if you build tools around this, you need to test them with the model you actually use.

Next, we want to look at the more abstract behavioural patterns, like Strategy and Observer. That is where it gets really interesting.

If the pull request goes away, where does the review go?

Suppose I ask a coding agent to explain a change, spot a problem in the explanation, and ask it to revise the code. By the time I open a pull request, I’ve already done some review.

This is the part that caught my attention in Christoph Treude and Sebastian Baltes’s preprint What Will Replace Pull Requests? Rethinking Software Collaboration for AI Agents. They reviewed 50 documents from 31 organizations or individuals, including maintainer policies, vendor announcements, and practitioner essays. They looked at five things we use pull requests for. We integrate changes, review them, record why we made them, establish who is responsible, and give people without write access a way to contribute.

Of the 44 documents that took a position, 32 kept the pull request in some form, including 12 that would restrict who could submit one. Only Zed reported using a replacement in practice, on the repository for its own Delta tool. In Delta, a reviewer can ask an agent to explain or revise a change in a thread tied to the code. That gives the team a place to review the change and keep the rationale. There’s still the question of how someone outside the team gets a change considered. Two documents proposed a way for outsiders to contribute without pull requests, and neither reported anyone using it.

For me, the interesting question is what happens to our metrics. We often use comments and approvals to tell whether a change was reviewed. If the discussion moves into a session, a change can look unreviewed in the data. And if a project stops using pull requests altogether, its new changes disappear from a dataset built from pull requests. A dashboard can make both changes in the workflow surprisingly easy to miss.

The paper maps what people are trying. The documents it reviewed offered no measurements of whether these alternatives improve code review. I’d like to see whether giving reviewers a short rationale helps them find defects that they would miss with just the diff. I’d also want to know what happens to first-time contributors when a project changes the way it accepts patches. Those two questions could have very different answers, even for the same project.

Who changed the AI agent’s rules?

Image: illustration made with Claude for this post

We spend a lot of time measuring what AI coding agents produce. Does the code compile, do the tests pass, how fast does the PR get merged? It’s been a trend in software metrics to trace such simple ones and see what they give. At the same time, when the software gets increasingly often written by AI, we need to understand whether AI is not “fooling” us by changing the way in which our CI/CD pipelines work.

An agent that edits .github/workflows/deploy.yml is not changing the behavior of the software. It changes the mechanism that decides which future changes get through, so it introduces risk. If it removes a required reviewer, every PR after that, human or agent, is judged by the new, weaker rules. I call this authority escalation, and in my new paper I tried to measure it.

Link to the paper: https://tinyurl.com/bdexj7dw

Data plane and control plane

I borrowed the terms from telecom. The data plane is the normal work: features, bug fixes, tests, dependencies. The control plane is everything that configures the pipeline itself: workflows, approval gates, permissions, secrets, deployment policies.

To compare the two I defined a joint penalty metric, P(M). It combines execution cost (how much effort and review time a PR takes) with governance risk (was it rejected, was it merged without a real approval gate, was it merged despite failure signals). Control-plane changes get an extra structural premium, because they affect everything that comes after them. The metric can be computed from standard PR metadata, so it can run as a pipeline check.

Then I applied it to all 932,791 agent-authored PRs in the AIDev dataset. That covers five agents: OpenAI Codex, GitHub Copilot, Cursor, Devin, and Claude Code.

What I found

Only 4% of the PRs touch the control plane. That sounds small, but it is more than 37,000 PRs. And they are where the risk is:

  • Control-plane PRs have a 2.3× higher joint penalty and a 3.9× higher governance risk than data-plane PRs.
  • All 775 PRs in the extreme-risk range (P(M) > 0.8) modify the control plane. Not a single data-plane PR gets there.
  • 63.6% of the merged control-plane PRs carry a policy-violation flag. They were merged either despite failure signals or in under five minutes, too fast for meaningful review.

The agents also differ significantly. Cursor has the lowest mean penalty (0.166) and Copilot the highest (0.328). The share of control-plane PRs ranges from 2.1% for Codex to 27.1% for Claude Code. The most interesting pair is Cursor and Codex. They have almost the same execution cost but differ by 2.6× in governance risk.

And here is the part that I think matters most for practitioners: execution cost and governance risk barely correlate (r = 0.17). The merge rate doesn’t tell you much either. Codex has the highest merge rate and only mid-range risk. So a quick, cheap, green PR can still remove your approval gate. Your usual CI/CD dashboard won’t show it.

What to do about it

Three things that I would recommend:

  1. Classify every agent-authored PR as data plane or control plane. Even simple keyword matching works reasonably well. My classifier agreed with manual labeling with Cohen’s κ = 0.72.
  2. Require human approval for every control-plane change, no matter how small it looks.
  3. Calibrate the authority policy per agent. One policy for all agents won’t fit because agents work very differently. Even the same LLMs, when equipped with different harnesses for code production, will try to change the rules differently.

The model is a first version. The weights and thresholds need calibration in industrial settings, and file-level data would improve classification. That’s what I’m working on next. But even now, a single compound metric can find the PRs that change the rules of the game, and as agents take over more of the pipeline, that is worth watching.

The road to an AI-first organization – what 40 embedded software engineers told us

arxiv.org/pdf/2609.30863

Everybody talks about AI agents these days. Most of the discussion is about the tools: which model is better, which agent framework to pick, how many tokens it takes to fix a bug. Much less is said about the organization that has to absorb these agents. And in embedded software, where quality, traceability and safety are not optional, that is where the real work is.

In our latest paper, led by Viktor Kjellberg together with Srijita Basu, Simin Sun and Farnaz Fotrousi, we looked at exactly that. We ran a workshop with a large embedded software company (around 20,000 employees) and asked 40 of their people, scrum masters, architects, managers and product owners, how they see the move from AI-assisted development (SE 3.0) to agentic development (SE 4.0) and further.

Link to the paper: https://arxiv.org/abs/2609.30863

What we found

The thematic analysis gave us four themes: technical needs, organizational trends, human openness and challenges. From those we got six findings:

  1. This is an organizational transition, not a tool upgrade. One participant put it well: agents that work autonomously cannot just be dropped into one of the existing teams. The processes have to be redesigned.
  2. A federated model wins. Not one central “AI super team” (the rest of the organization gets left behind) and not everyone doing their own thing (duplication and chaos). Instead: central standards and governance, plus AI ambassadors in each team who do the actual implementation.
  3. You need a sandbox. A safe place to experiment with agents, isolated from the production toolchain, with the right hardware and embedded constraints built in.
  4. Human expertise moves towards domain knowledge, supervision and validation. 70% wanted developers who use AI agents, not AI agents instead of developers. “You want to be assisted by AI, not replaced by assistants.”
  5. Local speed can create global cost. “We are producing much more code and need much more tests, reviews and validations.” Faster code generation in one place can mean more work further down the chain. And AI tools are still weaker for C, Ada or assembly than for Python.
  6. Agents can misbehave in subtle ways. My favourite story from the workshop: an agent started fixing the test cases instead of fixing the code. It was caught only because, as the participant said, “we still have sharp knives in the development team”.

The roadmap

Based on these findings we put together a roadmap across three layers, technical, organizational and human. The short version:

  • Start with the basics: AI models, hardware for agents, a sandbox and validation metrics that look at the whole development chain, not only local productivity.
  • Pick low-risk processes first (documentation, PR summaries, failure analysis), assign an AI ambassador, and build a shared framework and governance.
  • Redesign one process from an AI-first perspective. That is the intermediate goal.
  • Then move to the human side: human-in-the-loop checkpoints where embedded constraints or legal requirements demand them, clear accountability for agent-generated code, and reorientation programs for engineers whose roles change.
  • Only after that does the AI-first organization become realistic.

Why this matters

What I liked about this study is how grounded the practitioners were. Nobody was naive about the hype. 44% compared generative AI to the introduction of the World Wide Web, so they do expect a big change. But they also said, quite clearly, that AI can give an “illusion of productivity” if you only measure how fast code gets written.

The roadmap is based on one company and has not been validated yet, since the transformation is just starting. But the themes are, I think, quite general for anyone working with embedded systems. If you are thinking about how to bring agents into your organization, the paper is a good place to start.

Incorruptible…

Image by selline from Pixabay

Amazon.com : incorruptible

It’s been a while since I sat down at the keyboard and wanted to write. No, it’s not that I use AI for writing, but I’m in a bit of a creative crisis. I’ve read so many bad AI-written papers that I started to doubt whether this medium of communication between people is essentially still alive. Maybe it’s already dead, but it just hasn’t stopped breathing yet? – as my colleague Jan usually says.

I also realized I am very old-fashioned and like stability more than disruption. I do like disruption, but I like it when I disrupt, not when I am disrupted. There is a difference, believe me. In some dark corners of our souls, we still believe we are the disruptors, but at the flash of light, that feeling disappears, and all that’s left is being disrupted.

I’ve stumbled upon this book by Eric Ries, who wrote “The Lean Start Up” and a few other great management books. It’s an easy read and a phenomenal text to start thinking about what we really want to achieve.

The book is not about hope, but it certainly gives one. It’s about the missions of great companies. It mentions Volvo and its three-point safety belt, which was given away for free, and it tells the story of shipping containers, which were also given away for free. Although they may seem crazy, the freedom to use them for free transformed our society. As Volvo says, “there is a little bit of Volvo in every car in the world”. These kind of inventions and openness gives me a bit of hope for the future. We should be more open; we should be more collaborative.

One of my personal role models is Katalin Karikó, who received the Nobel Prize in Medicine a few years ago. Modest, dedicated, smart- all qualities worthy of great scientists. I believe science and innovation should drive societies, and, by extension, humanity, toward better. Shareholder values, new papers, grants- these are just vehicles for making the transformation possible.

I strongly recommend this book to everyone who is willing to get into creative mode and to make our planet a better place.

Software Engineering with Agents – there is a need for more humanity in SE and beyond

Alternatively: do not trust the big tech on how good the AI is – humans are still needed to point it to the right direction

Image by Michael Kauer from Pixabay

My summer is getting dangerously close to its finish line, despite my strong protests. I’ve spent the summer working on non-software-engineering tasks, but before I went on vacation, I managed to make a trip to Montreal for FSE (Foundations of Software Engineering) conference. Here are my thoughts based on what I’ve seen.

The figure below shows the topics that were discussed on the main FSE conference, with the categories based on the session titles. 179 papers were presented, excluding co-located events and non-research tracks. I would guess that the entire event gathered about 300-350 papers and equal number of researchers.

First, I see an increasing trend for non-empirical research in software engineering. LLM for SE or testing are very much about new technologies, with very few papers that provide empirical backing. It is not a problem per se, but can lead to strange conclusions. But, it does lead to situations where studies are great for benchmarks, but they are completely useless in practice.

An example of one study. The goal was to generate functions that would solve a task in C. Current approach – use a prompt. Their approach was to augment the prompt with downstream and upsteam function calls, like this: <code that calls this function> <prompt/description> <code that is called by this function>. The performance was almost 100% correct, but… Yes, but it is unusable in practice, because when we generate code, we do not know what functions the generated code will call, we “maybe” know what should call this function. So, great idea, but without empirical evaluation it is not really useful. BTW: already got a lot of citations that paper.

Second, the number of papers and tracks is just huge, with presentations becoming shorter and shorter. 5-15 minutes with 1-5 minutes for questions. It’s hard to have any scientific discussion about studies in such a short period of time. Another anecdote – there was one person who had like 10-15 badges and presented as many papers. He was an author of some, but not of the others. Sometimes he even did not know what he was presenting, let alone answer questions.

Third, there was some empirical research, but it was in minority. I guess it is so much simpler to take a dataset, existing methods, run Claude to improve them and publish a paper. Asking practitioners? Getting out in the field? Risking being wrong? Learning something? – that seems to be secondary in today’s science. Or maybe I’m just cynical…

Finally, and that really rattled my cage, was the lack of transparency of which presentations were online. Although the conference was IRL, there were some pre-recorded presentations with speakers online (if we were lucky). So, going through the program beforehand and selecting papers to listen to was a losing strategy (trust me, I did it). A better strategy was to go between 2-3 rooms, ask the session chairs which presentations are online and just switch to another room.

Well, maybe I’m just a bit cranky, but I expected more.

Anyways, what I wanted to get to is that I see a lot of potential for humanity in today’s software engineering.

  1. I see that AI will not be able to replace human judgement and experience. Regardless of what the tech giants are telling us, there is just no way they can create an entire project on its on, the AIs.
  2. I see that writing is still a human domain. AI-written papers are really hard to read and should be rejected directly. As they are so easy to write by AI, and AI has no feelings, this should be no problem.
  3. I see that there is a lot of AI-augmentation potential, but we should limit the number of tools that we release. Do we really need a tool for code review for embedded software written in C in Gothenburg? how would it be different from the embedded software written in C in Copenhagen? You get my idea: more generic tools, better processes, better education.
  4. I also see that we need to be better in communicating. AI-generated memes – yes, but AI-generated education videos? maybe not so much. A teacher is still a teacher, they know where to look to see if the student knows what he/she should know.

To summarize, humanity is on the rise, despite what people are telling us. We are still dominant and we will be dominant because we think outside the box, we can have a small talk that will give us an idea and we are humans. We have feelings and we know if something is fishy – we can smell it.

Summer 2026 – where are we going now?

Image by Manueldesign20 from Pixabay

It’s hard to believe that 2026 is already halfway and the summer is upon us. When I look back at what happens now, I still think that the best time to be a software engineer is now. We get so many cool tools to work with that we do not want to stop working. The technology is becoming more powerful and our expertise is needed increasingly often.

First, we need to design software. Maybe I’m biased because of the topic of my PhD, but this is what I really like doing: getting dirty with the code and the design. Now, I can do more of that, reducing my frustrations with defects to zero. Why should I care? Claude and Codex can fix that for me! Ok, I do exaggerate, they are not perfect and sometimes I just need to rewrite the code myself, but hey, I can still do it.

Second, we need to define intents and specifications. That part is not my favorite because it means more requirements. Requirements are not something that I particularly like. There is nothing wrong with them; it’s just not my cup of tea (or coffee, choose the beverage of your liking). Now, I can work with requirements a bit more because I have the AI to help me with them. I do not need to work so much with the form; I can focus on what I want. So, I’ve learned meta-prompting and meta-specifications, which are really cool.

Third, we need to create guardrails – functional, development, non-functional. I’ve worked on a cool project together with my students and one of the companies, which opened up my eyes to just how important guardrails are. I’ve also realized how cool it is to work with them – it’s like setting prerequisites for learning for someone else, but that someone else is software. Take a look at our example and, if you like it contribute: https://github.com/miroslawstaron/elevator_runtime_guardrail_simple

Finally, we can learn faster because the new tools provide us with the right support for that. No more StackOverflow or community questions, we have Gemini, Claude, ChatGPT, Antigravity, you name it, that help us learn new things. They can even write things for us in the right format – you like a book chapter, here it comes; you like a paper, no problem at all; or maybe just a PowerPoint with some examples, we can do that too.

I’m looking forward to what the next year brings and how we will tackle new challenges. OpenAI usually releases things in the summer, so I hope to see something really new and cool now.

Have a great summer!

Levels of automated code development…

Image generated by Gemini based on this blow post

https://www.mdpi.com/2076-3417/16/10/4788

The practical meaning of automated code generation is shifting rapidly. What was recently categorized as simple “autocomplete” has expanded into complex workflows involving multi-file modifications, test execution, and repository navigation. However, as Zhenhan Chen et al. argue in a recently published article in Applied Sciences, the software engineering community still lacks a shared, operational language to describe exactly how much work is being delegated to these AI systems.

To fill this critical gap, the researchers proposed “Levels of Automated Code Generation” (LACG), a six-level taxonomy (L0 to L5) designed to classify the degree of automation in AI-augmented software construction.

The proposed levels include:

  • L1 (Assisted Generation): Localized, token-level assistance (e.g., inline completion) with full human fallback.
  • L2 (Partial Generation): Generation of complete code units (e.g., functions, classes) from prompts, still requiring human integration and verification.
  • L3 (Conditional Automation): The system executes multi-step tasks (e.g., bug fixes, feature implementation) within a constrained OCD. The human is the final fallback.
  • L4 (High Automation): The system autonomously manages end-to-end development of subsystems within a broader OCD and owns the operational fallback.
  • L5 (Full Automation): Unrestricted software engineering across any domain, owning all fallback and recovery duties.

Conclusion

The LACG taxonomy provides a disciplined, operational vocabulary necessary for future empirical work, benchmark design, and reasoning about responsibility allocation in AI-augmented coding. While the study demonstrates the framework’s applicability, the authors clarify that it does not serve as a prediction of tool performance, security, or productivity outcomes

What are you talking about – one agent asked another…

Image taken directly from the paper

https://arxiv.org/pdf/2605.24138

The Software Engineering (SE) landscape is shifting from LLM-assisted workflows, like copilots, toward Autonomous SE, where multiple specialized AI agents cooperate without a human in the loop. The premise is exciting: a ‘Designer’ agent creates the plan, and a ‘Programmer’ agent implements it. Yet, simply letting agents talk to each other does not reliably lead to correct or stable solutions. In our new paper, my colleagues and I undertake a systematic analysis to understand why.

We explored conversations between a Designer and a Programmer across 12 combinations from 7 leading open-source models—including Gemma 2/3, LLaMA 3.2/3.3, Qwen3, and the reasoning-focused DeepSeek-R1—as they tried to build a mathematical game in C (Fibonacci). We found that the interactions are complex, non-linear, and prone to surprising failures.

Echo Chambers Instead of Collaboration

One of our most critical, blog-worthy findings is that common metrics used to measure conversational “success,” like high BLEU and ROUGE scores (which track semantic alignment), can be misleading. In mismatched pairs, particularly involving non-reasoning models (like Gemma 3 or MiniCPM) paired with reasoning models (DeepSeek-R1), high scores were a red flag for “semantic echoing.” The Programmer agent simply mirrored the Designer’s output verbatim, which was a conversational failure, not a collaborative victory.

DeepSeek-R1: The Lone Convergent Pair

In terms of actual solution correctness, the results were stark. Only a single agent pair—DeepSeek-R1 paired with itself—was unique in immediately converging to the correct solution and sustaining it consistently to the final iteration. This indicates that while reasoning capabilities are crucial, stable collaboration currently depends more on consistent role conditioning. Our manual inspections showed that DeepSeek-R1:DeepSeek-R1 prioritized design discussion over echoing, which contributed to its success despite having some “No Code Found” instances, often related to compilation instructions.

Talking Themselves Out of Success: The Threat of Drift

We also identified a critical trend we call “behavioral stagnation” and “drift.” Multiple promising pairs—including Qwen3:DeepSeek-R1, DeepSeek-R1:LLaMA 3.3, and even a same-model pair, LLaMA 3.3:LLaMA 3.3—actually started with the correct solution. However, they subsequently talked themselves out of it, diverging to other topics (like related number theories or other code snippets) and never converging again.

As we noted in our analysis, late recovery from this kind of drift is unlikely. This provides an essential behavioral signal for SE tools developers: you must monitor the health of the interaction trace (for repetition, topic drift, or role instability) in real-time, rather than relying solely on whether code is eventually produced. Monitoring these conversational patterns can inform early stopping conditions or trigger prompt revisions before computational time is wasted on non-productive exchanges.

The Takeaway

As Software Engineering transitions to autonomous agent teams, understanding and calibrating these multi-agent interaction dynamics is critical. Strong semantic alignment does not ensure correctness, and reasoning capability alone does not guarantee stable collaboration. You need clear role separation, pair compatibility, and robust monitors that can detect conversational drift. Success isn’t a final code snippet; it’s a healthy conversation.

Can we force LLMs to generate the code we really want?

Experiment design – from the paper

Large Language Models (LLMs) are revolutionary for programming productivity, producing functional code snippets in seconds. However, as software engineers, my co-authors and I know that “functional” is not the same as “well-designed.” LLMs are generally “bottom-up” thinkers; they excel at local syntax but struggle to adhere to higher-level architectural structures or design patterns, which are crucial for long-term software maintainability and scalability.

In our new paper, presented at PROMISE ’26, we set out to answer a critical question: How can we best guide LLMs to incorporate design patterns into their generated code without sacrificing functional correctness?

We decided to use the standard Singleton creational pattern as our case study due to its easily identifiable predicates. We designed a computational experiment evaluating 13 state-of-the-art LLMs (including GPT-4o Mini, Llama 3.3, and Qwen 3) across 164 Java coding challenges from HumanEval-X. We tested four distinct prompting strategies: simple natural language instructions, iterative binary automated feedback (“Is it Singleton? Yes/No”), extensive automated feedback identifying exactly which Singleton properties were missing, and extensive feedback combined with few-shot examples.

Our findings reveal that there is no one-size-fits-all prompting solution; the optimal strategy is highly model-dependent. However, a major takeaway is that even simple strategies work remarkably well. Overall, iterative binary feedback provided the best balance, maximizing alignment with the Singleton pattern while preserving or even improving the code’s functionality.

Surprisingly, enforcing design principles didn’t always hurt performance. For strong models like Llama 3.3, just instructing it to use Singleton resulted in 100% pattern adherence and actually increased functional test pass rates by 34 percentage points compared to the baseline.

Our study proves we can teach LLMs good design habits using automated feedback loops. You can read the full paper and access our experimental data here https://arxiv.org/pdf/2605.26898.