This guide explains how coding agents can use hindsight—reviewing past decisions and outcomes—to remember and respect architectural constraints. You’ll learn a practical workflow for capturing, storing, and applying lessons learned, so your agent doesn’t repeat the same structural mistakes. No special tools are required beyond a way to store text notes.
What You’ll Need
- A text file, wiki, or note-taking app to store hindsight logs
- Access to your coding agent’s configuration or prompt files
- A way to review past code changes (e.g., git history, code review comments)
Step-by-Step
- Identify recurring architectural constraints. Look at past code reviews, bug reports, and refactoring discussions. What rules keep coming up? Examples: “never import from the data layer into UI components,” “all database access must go through the repository interface,” or “use the event bus for cross-module communication.” Write these down as clear, testable statements.
- Create a hindsight log. Start a new document called something like
architectural_constraints.md. Structure it with a simple table:Constraint|Why it matters|Example violation|Example fix. Keep it short—each row should be one or two sentences. - Record the context of past failures. For each constraint, note the situation where it was violated. Was it during a quick bug fix? A new feature with a tight deadline? This context helps the agent recognize similar situations in the future.
- Write constraints as explicit rules. Phrase each constraint as an imperative: “Always use the repository interface for data access” rather than “we should avoid direct DB calls.” This makes it easier for the agent to check against its own code.
- Add the log to your agent’s context. If you use a prompt-based agent, include the log in the system prompt or as a reference file. If you use an agent with memory, save the log as a persistent memory entry. The goal is to make the constraints visible before the agent starts coding.
- Review the log before each new task. Before asking the agent to implement a feature or fix a bug, have it read the relevant constraints. You can do this by adding a step in your prompt: “Before starting, review the architectural constraints in
architectural_constraints.md.” - Use hindsight to update the log after each task. After the agent finishes a task, ask it to reflect: Did it follow all constraints? If not, why? Update the log with any new lessons. For example, if the agent found a constraint ambiguous, rephrase it to be clearer.
- Automate checks where possible. If you have linting or static analysis tools, encode constraints as custom rules. For example, a lint rule that flags direct imports from a forbidden module. This gives immediate feedback, not just hindsight.
- Make the log part of code review. When reviewing the agent’s output, check it against the log. If a violation slipped through, add it to the log as a new example. This reinforces the learning loop.
- Periodically prune and refine. Every few weeks, review the log. Remove constraints that are no longer relevant, merge duplicates, and ensure each rule is still accurate. A cluttered log is less effective.
Common Mistakes
- Writing vague constraints. “Be careful with database performance” is too vague. Instead: “All queries that join more than three tables must be reviewed by a senior developer.”
- Forgetting to update the log. Hindsight only works if you actually record lessons. Set a reminder to update after each major task.
- Overloading the agent with too many rules. If you list 50 constraints, the agent will ignore most. Keep the log to the 10-15 most critical architectural rules.
- Not providing context. A constraint without a reason is easy to dismiss. Always include the “why” so the agent understands the tradeoff.
- Treating the log as static. Architecture evolves. If you don’t update the log, it becomes stale and misleading.
Tips
- Use concrete examples. For each constraint, include a snippet of violating code and the corrected version. This makes the rule unambiguous.
- Link the log to your version control. Store the log in the repo (e.g.,
docs/architecture/constraints.md) so it’s versioned and reviewed alongside code. - Make the log easy to parse. Use a consistent format (like the table above) so the agent can quickly scan it.
- Involve the whole team. If multiple developers use the same agent, share the log so everyone benefits from collective hindsight.
- Test the agent’s adherence. Occasionally ask the agent to explain how it followed a constraint in a completed task. This reinforces the behavior.
Troubleshooting
- The agent ignores the log. Check if the log is actually included in the prompt or memory. If it’s a separate file, make sure the agent has read access. Also, rephrase constraints to be more direct and imperative.
- The agent follows constraints too rigidly. Some constraints may have exceptions. Add a note to the log: “This rule may be broken if X, but only after approval.” This gives the agent guidance on when to ask.
- The log becomes too long. Prune aggressively. If a constraint hasn’t been violated in months, consider removing it. Keep only what’s essential.
- New developers don’t know about the log. Add a link to it in your onboarding docs and mention it in code review guidelines.
- The agent still makes the same mistake. If a constraint is repeatedly violated, it might be too complex. Break it into smaller, more specific rules. Or add a stronger enforcement mechanism, like a CI check.
Frequently Asked Questions
How is hindsight different from just giving the agent a list of rules?
Hindsight is about learning from specific past incidents. A static list of rules is abstract; hindsight adds concrete examples and context, making the rules more memorable and applicable.
Can I use this with any coding agent?
Yes, as long as you can provide text context to the agent. Most agents accept a system prompt, a reference file, or have a memory feature. The log is just text.
How often should I update the log?
After every significant task, or at least weekly. The more current the log, the more useful it is. But avoid updating it mid-task unless you discover a critical issue.
What if the agent disagrees with a constraint?
That’s a sign to review the constraint. If it’s outdated, update it. If it’s still valid, explain the reasoning more clearly in the log. You can also set a rule that the agent must flag disagreements rather than silently ignore.
Do I need to store the log in a specific format?
No, but a structured format like Markdown tables or bullet points works best. The key is consistency so the agent can parse it reliably.
Can I automate the hindsight process?
Partially. You can write a script that analyzes git commits for patterns (e.g., reverts, fixes) and suggests new constraints. But the final review still needs a human to judge relevance.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Hide PHP Version HTTP Header: How To
- CentOS Stream for Developers: A Practical Guide
- How to Replace a Game Controller Battery Safely
- Man-Sized 3D Printer? Why You Probably Don’t Need One100.0 cm³/h
- Scroll Horizontally with Mouse Wheel by Holding Shift5.00 min/km
- iPadOS 16 Supported Devices: Full List