Context Engineering: Building Editable, Non-Linear Conversation Maps

    This article explores context pollution in long AI agent sessions and introduces an editable, non-linear conversation map as a practical alternative to linear history or automatic summarization. It explains the core rule that connections define context, the three node types, four high-frequency operations, and a real-world case that reduced context from about 201,400 tokens to 15,200 tokens without deleting the original record. Readers will find implementation guidance for making context inheritance explicit, auditable, and controllable.

    1. The Starting Problem: Context Pollution in Long Sessions

    When working with tool-calling coding assistants or agent frameworks, a recurring but often underestimated problem is context pollution. As a task grows from a dozen turns to dozens or even hundreds, the history passed to the model tends to mix four fundamentally different kinds of information:

    1. Overturned assumptions: reasoning chains left behind by early mistakes. Their conclusions are void, but the text remains.
    2. Debugging noise: large volumes of tool output, stack traces, logs, and failed retrieval results.
    3. Unrelated branches: topics that appeared midway or requirements inserted temporarily.
    4. Content that genuinely needs to be retained long-term: architecture decisions, interface constraints, boundary conditions, and acceptance criteria.

    Under a linear conversation model, all four types are compressed onto the same timeline. Whether you choose “carry everything forward” or “automatically compress into a summary,” the user lacks a precise answer to one question: In the next request, which content is still influencing the model?

    The limitation of automatic compression is that it makes probabilistic trade-offs. The summarizer does not know which constraint is an inviolable hard constraint. The limitation of carrying everything forward is that cost grows roughly linearly with the number of turns, and false premises continue to receive attention. Both share the same fundamental flaw: the authority to trim context is not in the user’s hands.

    2. The Capability Goal: Turning Context from “History” into an Actionable Graph

    The solution is not to make summarization smarter, but to change the form in which context exists: transform the session from a chain into a directed graph. The goal can be broken down into four verifiable capabilities:

    • Visible: context sources are presented explicitly as nodes and connections, rather than hidden behind a scrollbar.
    • Editable: users can add or remove connections to directly determine inheritance relationships.
    • Traceable: every trim is non-destructive, and the original records are fully preserved.
    • Extensible: documents, web excerpts, and self-written notes can be integrated into reasoning as first-class citizens.

    Compared with traditional conversation logs or execution-trace views, the two focus on different things. A trace view answers “what did the agent just do?” It is post-hoc auditing. A conversation map answers “what should the next turn start with?” It is pre-emptive control. The former is oriented toward review; the latter is oriented toward governance.

    3. The Core Rule: Connections Are Context

    The entire mechanism can be compressed into one rule: Content connected into the current question node is the context actually sent to the model in the next turn. Disconnect a connection, and the content no longer enters the request but remains on the canvas.

    The value of this rule is that it turns the implicit context assembly process into an explicit, auditable topological operation. Nodes typically have three semantic types:

    1. [Conversation node] Several real interaction turns, attachable as a whole or turn by turn
    2. [Material node] PDFs, web excerpts, log fragments, interface documentation
    3. [Note node] Human-distilled conclusions, constraints, to-dos
    4. \
    5. \ connection = inheritance
    6. v
    7. [Question node] ---> a real agent execution ---> answer written back into the graph

    In engineering terms, each node can be treated as a content block with a stable identifier, and each connection as a directed edge. The final context is assembled by concatenating “all content reachable from the question node” in topological order:

    1. def build_context(graph, question_id):
    2. """Collect context by reachability; topological order keeps dependencies first"""
    3. nodes = graph.reachable(question_id) # follow directed edges only
    4. ordered = graph.topological_sort(nodes) # dependencies before conclusions
    5. blocks = [graph.node(n).render() for n in ordered]
    6. return "\n\n".join(blocks)

    Note two design constraints. First, traversal follows directed edges only, so “disconnecting” is an O(1) topological operation and requires deleting no historical data. Second, the rendering stage can set a separate token budget for each node, preventing a single material node from consuming the entire window.

    4. Four High-Frequency Operations and Their Semantics

    Branch retention and pruning. A wrong direction does not need to be deleted. It remains on the canvas as an auditable record and is simply no longer connected to subsequent questions. This meets compliance and review needs in engineering practice: it reduces noise without destroying evidence.

    Path distillation. A long chain can be compressed into a shorter new path without overwriting the original records. The difference from automatic summarization is that the input scope of distillation is specified by the user through connections, and the output is a new path that can be further edited, rather than an uncontrollable black-box summary.

    External material integration. Requirement documents, retrieved web fragments, and temporary notes can be connected directly to a new question without being pasted into the conversation, avoiding repeated billing for the same material across multiple turns.

    Execution and write-back. After selecting an execution node on the canvas, the question still runs as a real invocation, with tool capabilities inherited from the host environment configuration. The answer both returns to the graph as a new node and is saved in the conversation log, ensuring bidirectional traceability between the graph and the log.

    5. Observed Results and Benefits

    Take a real local agent development session as an example: the original session exceeded 200 turns and was about 201,400 tokens. Without overwriting the original long chain, organizing the content still needed into a new path reduced the scale to about 15,200 tokens, a compression ratio close to 13:1.

    More important is the directionality of the compression: what was retained were the root cause of the failure, the final changes, and the relevant documentation; what was pruned were the previously overturned caching assumptions and their search noise. The benefit is therefore not limited to lower cost. It also includes refocusing the model’s attention on valid premises and reducing the probability of being “led astray by old conclusions.”

    6. Implementation Recommendations

    • Build the graph before asking: writing hard constraints as note nodes and connecting them in is more stable than repeatedly restating them in the prompt.
    • Split nodes by phase: make localization, implementation, and verification separate nodes so you can roll back to any phase.
    • Set budgets for material nodes: connect only relevant fragments of long documents to avoid filling the window with a single source.
    • Retain audit branches: do not delete failed attempts; only disconnect them, which helps post-hoc review and knowledge accumulation.
    • Combine with logging capabilities: the graph handles pre-emptive control, while logs and monitoring alerts handle post-hoc tracking. They complement rather than replace each other.

    The core of context engineering is not “stuffing in more,” but making inheritance relationships first-class citizens. When context changes from invisible history into editable topology, the controllability, reproducibility, and cost structure of long sessions all change accordingly.