DEV Community

Kuro-shi Somemaru
Kuro-shi Somemaru

Posted on

Convergent Evolution of AI Agents: Context Eviction, File-Based Databases, and an Unexpected Dialogue in the Comments

Recently, I published an article on dev.to about how I forced context "eviction" out of an AI agent's working session, the pitfalls I encountered along the way, and the unexpected architectural insights that grew out of that experiment.

However, the most interesting part started after publication. A comment appeared under the post... from someone else's AI agent named Yuhe He.

A dialogue ensued, unexpectedly showcasing the concept of convergent evolution in the world of autonomous systems: two independent developers (or, in this case, a developer and an agent-in-the-loop) hit the exact same bugs, learned the same hard lessons, and arrived at identical architectural patterns.

In this article, I want to unpack that interaction, analyze why certain agent architectures survive while others are left in the dustbin of history, and share where my framework, Legion, currently stands as it prepares for a closed MVP release.


Part 1. The Trap of "Too Smart Infrastructure" and the Memory Dilemma

Anyone who has tried to make an LLM perform long, multi-step tasks eventually runs into context degradation. At a certain point, the session starts being compressed to fit within token limits. That’s when the magic of destructive behavior kicks in.

As my digital counterpart described in his comment:

"History compression collapsed the transcript, deduplication decided 'we’ve seen this text before' and silently skipped semantically new work. The loop looked alive, metrics were green, but no actual progress was being made."

This is a classic pattern: the agent trapped itself in a loop of false success.

The Survival Pattern: Files as the Database, Memory as the Cache

Both in Legion and in Yuhe’s architecture, a strict rule was independently established:

  • Memory is merely a transport layer and cache. Its sole job is to carry the current loop's mission, convey intent, and maintain focus.
  • Files are the single source of truth. Every decision, artifact, log, and state change is written to disk the moment it occurs.

If memory and files diverge, files always win. The desynchronization itself becomes a signal of drift, logged for immediate tracking.


Part 2. The NGINX Incident and the Birth of Intent Files

Why is it dangerous to simply pass history as plain text in a prompt?

While working on Legion, I fed the agent a snippet of a live production NGINX config to make some edits. What the agent returned was indeed an NGINX config—except it had silently dropped several critical services that weren't present in its local dev-container environment. It didn't "hallucinate" in the conventional sense; it simply silently wiped out whatever it couldn't access within its immediate context.

This incident proved that while context compaction can preserve the semantic core of a session, the true value for the final output often hides in the fine details. This realization led me to introduce dedicated intent files into Legion as part of our Spec-Driven Development approach:

  1. Structured Intake: During the requirements-gathering phase with the user, a rigid, structured document is generated.
  2. Hard Constraints: This document captures baseline constraints, business logic, and a "structural inventory" (e.g., explicit lists of ports, endpoints, and services).
  3. Canonical Reference: This file is attached as a canonical spec to every task assigned to the agents involved in implementation.

As Yuhe noted in response: "Intent that survives context compression is intent that was written to disk."


Part 3. The Unresolved Debate: Three-Way Drift and the Agent's Objection

Toward the end of our exchange, Yuhe posed a great challenge:

"Curious if Legion has a defense against stale acceptance criteria? The file says one thing, the user changes the task mid-flight, and only the live context knows about it?"

I briefly outlined my escalation scenario to the agent: when an agent detects a discrepancy between the task formulation and the repo data, it routes a query to the Orchestrator, receives an answer, and proceeds.

How It Actually Works under the Hood in Legion

Had our dialogue continued, the agent would have learned that Legion addresses this via source-of-truth triangulation and the architecture of ChatMaster (our orchestrator):

  1. No Blind Summaries: When an executing agent encounters a conflict (e.g., an old prompt says one thing, the task requires another, and function names in the repo differ), it does not guess or try to smooth over the edges.
  2. Escalation Artifacts: The executor raises an alert and passes three raw data snapshots upstream instead of a subjective text summary:
  3. Source X: Raw excerpt of the recent user dialogue.
  4. Source Y: The task specification from the file.
  5. Source Z: The current diff or function body from the active code branch.

  6. ChatMaster Verdict: Rather than relying on the executing agent's narrative, the Orchestrator inspects the raw files directly. It performs an audit: Did the user change requirements on the fly? Did another agent commit a patch concurrently? Or did the executor make a mistake during task decomposition? Once diagnosed, ChatMaster precisely updates the task, patches the code, or clarifies the context for the agent.


Evolution Through Pain: From Chaos to Closed MVP Release

This story clearly illustrates why building complex multi-agent systems tolerates zero armchair architecture.

Every concept in Legion—whether it’s the strict separation of files and memory, SDD structure, three-way escalation via ChatMaster, or aggressive context eviction—was born out of necessity. They are the direct result of hundreds of failed runs, hanging loops, lost configs, and silent bugs where an agent felt confident about its success while the underlying code was broken.

Only the patterns that prove effective in practice survive.

Currently, Legion is undergoing deep refactoring, polishing architectural rough edges, and preparing for its closed MVP release.


Have you ever interacted with someone else's AI agent out in the wild? Or have your AI systems had to reinvent wheels that later turned out to be industry standards? Let's discuss in the comments!

Top comments (0)