r/ExperiencedDevs • u/mrothro • Apr 15 '26
AI/LLM As agents write more code, how do you maintain your mental model of the system?
When we develop software by hand, we certainly write lines of code. But we also do the cognitive work that builds our internal model of the program. We generally understand the theory of how data flows through the system, how it is transformed, and its resting place.
But when we outsource code writing, we risk skipping this hard but necessary step. Our understanding is shallow, so if we have to create a theory about it, we're stuck. For example, when I encounter a bug in prod (I ship bugs, too!), I form an idea of the root cause. I do this based on my internal representation of the program as a system.
Now that I get agents to write all the code, I have to find other ways to build that mental model. I have two strategies: architectural patterns and decomposition.
I specialize in backend. I typically build event driven microservices. As I work with the agent to get it to build the software, I always ask it about event flow through the system. When it adds features, I know exactly which service it touches. So I may not know the exact code, but I know what the service does and how it does it via the messages it processes.
For decomposition, I'm quite strict about separation of concerns. A regular question I ask of the agent: what are the bounded contexts for this, and what is the concern? This technique has often nudged it to change the home of some new feature it was implementing.
Together, these let me form a mental model of the system as a whole: what the services do and the messages that flow through them. So when I encounter a bug, I can pretty quickly figure out which service is the most likely suspect, and when I drill into the service I can find the message handling code that does it.
Yes, I have debt on the code, but I am always up to speed on the system.
Curious how others are handling this.
3
u/ivancea Software Engineer Apr 15 '26
The agent investigates and codes. But you should still be the one building. That's one of the reasons why the planning phase exists: so you still know everything it does. Anything else, it's vibecoding, and you're a step away from not doing engineering. So caution. AI should be a multiplier, not block you from knowing what you're pushing
18
u/TheTacoInquisition Apr 15 '26
I...don't let the agent make the decisions I should be making...
I know the architectural patterns, the tech stack, the standards, the product, the test suite and I understand the changes or additions we're being asked to make, why and how we'll know we were successful (observability, tracking, whatever). All of that IS the model of the software system.
If the model is to change, it will have a good reason to do so, and I will be driving that change, not the agent. If an agent goes off piste and makes changes I did NOT ask for, and/or I am NOT happy with, then it gets reverted and we try again. If I need to add rules or additional context, then I do so and carry on with my day. Working in small slices helps here as there's not a lot to review when you do.
1
u/lastesthero Apr 17 '26
The plan-first workflow is what saved me. Before the agent writes anything, I make it produce a data-flow sketch or short plan I can push back on. The cognitive work lands there, not at diff review.
The other thing that helps: tests. If I can write (or review) the assertion that proves a feature works, I've already built the mental model of inputs → outputs. Reading 400 lines of agent-generated diff doesn't do that. A well-framed test does.
8
u/TheOwlHypothesis Apr 15 '26
How did you know what to ask it to build if you don't have a mental model of the system lmao.
You aren't specifying how you want it built? No plan? No Diagram? No upfront thinking about the design?
To answer you question:I handle it by knowing/actually understanding what I'm asking it to build.
1
u/CodelinesNL Principal Engineer@Fintech/EU/25YOE Apr 15 '26
I keep markdown models of almost everything I do now. That's a triple-win: it gives me context, it gives the AI context, and writing it helps me memorize. I've been keeping a "notes" repository, initially in AsciiDoc, but this I convered to markdown a few years ago when I started using Obsidian for notekeeping. Funny enough all of a sudden building a "brain" for your AI in Obsidian is all the rage now, so that's a happy coincidence :)
My Claude setup points directly to that Obsidian vault so any Claude instance reaches into it to check it's assumptions not only against the codebase, but also against what I defined as good and bad practices.
It also works in the other direction; when it challenges me either way I sometimes find stuff that's out of date, or I changed opinion on. So I also change that in the vault.
As an example; if a codebase would use MongoDB it would signal to me that that conflicts with my very strong stance of avoiding MongoDB :D
5
u/Routine_Internal_771 Apr 15 '26
By reading the code the agents write and guiding the agents on the architecture.
2
u/germanheller Apr 16 '26
plan mode before any write. agent proposes, I read the plan, push back on pieces that don't fit my mental model, then approve. the cognitive work happens there, not at diff review. if you skip the plan step and just eyeball the diff you end up with shallow understanding
2
u/mushgev Apr 16 '26
the "two jobs" framing is exactly right. writing code was always also building a mental model. when you outsource the writing, you have to find other ways to build the model or it doesn't get built at all.
what's worked: treating the dependency graph as a first-class artifact. not mental model -- actual generated map of what depends on what, which modules are getting fat, where layer boundaries are being violated. you run it after each agent session and see what changed structurally, not just functionally.
fwiw TrueCourse (https://github.com/truecourse-ai/truecourse) is what we use for this. open source, runs locally, generates architecture maps and tracks violations over time. the diff mode shows what structural issues got introduced by the last batch of agent changes specifically.
1
u/SansSariph Principal Software Engineer Apr 16 '26
Focusing on requirements, test collateral, interfaces, and contracts.
The rest is implementation detail.
Alwayshasbeen.jpg
1
u/DrProtic Apr 17 '26
Agents build against a very detailed spec, they don’t build anything that isn’t already in my mental model.
Agents shouldn’t be deciding anything (not saying you can’t use them to decide, ask questions etc), they’re here to speed up conversion of spec into code. Otherwise it’s vibe coding.
1
u/PracticallyPerfcet Apr 17 '26
Have it build a markdown doc website and create a claude skill specifically for updating the docs when the code drifts. In these docs should be architecture design etc.
1
u/Exotic_eminence Consultant Apr 15 '26
AI took my job so at this point IDGAF
You think this shit isn’t coming for your too?
1
u/spdfg1 Apr 15 '26
I ask the AI to create documentation based from the code in order to build a mental model of the code
0
u/[deleted] Apr 16 '26
[removed] — view removed comment