4 ms·
Here's an easier solution that actually works, gives any agent FREE long term memory (platform agnostic and zero infrastructure!), always accurate context that
by CharlieDigital 7mo ago
Here's an easier solution that actually works, gives any agent FREE long term memory (platform agnostic and zero infrastructure!), always accurate context that is self-maintained by the LLM.
Use the idiomatic comments for your language.
Here is a snippet of our prompt for C# (and similar one for TS):
- Use idiomatic C# code comments when writing public methods and properties
- `<summary>` concise description of the method or property
- `<remarks>` the "why"; provide domain or business context, chain of thought, and reasoning; mention related methods, types, and files
- `<param>` document any known constraints on inputs, special handling, etc.
- `<return>` note the expected return value
- `<example>` provide a brief example of correct usage
- Use inline comments sparingly where it adds clarity to complex code
- Update comments as you modify the code; ensure they are consistent with the intent of the code
What happens: when the LLM stumbles upon this code in the future, it reads the comments and basically "re-hydrates" some past state into context. The `<remarks>` one is doing heavy lifting here because it is asked to provide its train of thought and mention related artifacts (future LLM knows where else to look).
You already know the agents are going to read your code again when it gathers context so just leave the instructions and comments inline.
The LLM is very good at keeping these up-to-date on refactors (we are still doing human code reviews) and a bonus is that it makes it very easy to review the code to see why the LLM generated some function or property because the reasoning is right there for the human as well.
- qntmfred 7mo agoI wish IDEs had better support for quick toggling the display of comments. You make a good point about it making sense for the docs to live alongside the code, I just don't usually want to see giant comment blocks everywhere while I'm operating in a codebase.
- CharlieDigital 7mo agoJetBrains Rider has this as does VS Code: CMD+K, CMD+/ to fold, CMD+K, CMD+J to unfold.