Open-Source Coding Agent Architecture: Patterns, Trade-offs, and Selection

    This article analyzes the architecture of open-source coding agents, focusing on the runtime layer known as the Agent Harness. It breaks down four architectural schools, explains context management and summarization triggers, covers session persistence and fault tolerance, and reviews tool contracts, orchestration levels, and security depth. Readers will find a practical eight-dimension framework for evaluating and selecting an architecture for their own requirements, with specific attention to Chinese-language and mixed-language scenarios.

    1. Introduction: Why the “Harness” Is Becoming Its Own Technical Layer

    As large models move from answering questions to completing tasks, the user experience is no longer determined by the model alone. What matters just as much is the runtime wrapped around the model, commonly called the Agent Harness. This layer drives the main inference-and-action loop, manages a constantly growing context, persists session state, constrains tool calls, restores the scene after disconnects and crashes, and translates model output into an execution trace that can be audited and replayed.

    Several organizations have recently open-sourced their coding agent implementations. As a result, this layer has shifted from opaque product logic to readable, modifiable engineering assets. For developers, the value lies not in declaring a winner, but in seeing the trade-offs each implementation makes on key dimensions: which runtime hosts the hot path, how state is stored, when compression is triggered, and where security boundaries are pushed down. This article abstracts reusable architectural knowledge from a generalized perspective and offers a practical evaluation method.

    2. Four Architectural Schools and Their Boundaries

    A file-by-file examination of multiple open-source implementations shows that, although all of them use an “inference-action” loop as their skeleton, their architectural philosophies have clearly diverged into four schools.

    Native kernel school: Pushes hot paths such as loop scheduling, sandbox isolation, command execution, and token counting down into system-level language implementations, trading development effort for throughput and depth of isolation. Suited to latency-sensitive automation scenarios that require strong isolation.

    Event-sourcing platform school: Models the session as an immutable event log, where the UI, storage, and retrieval are all projections of that log. The advantage is that crash recovery and auditing come naturally; the drawback is that once the event schema grows, migration becomes expensive.

    Ecosystem integration school: Builds daemons, multi-platform clients, instant messaging entry points, and IDE plugins around its own model, emphasizing “available everywhere.” Engineering complexity concentrates on protocol adaptation and state synchronization.

    Standard engineering school: Uses a policy engine, observability, evaluation sets, and performance baselines as its skeleton. The process is complete, but it is often deeply coupled to specific model capabilities, so migration requires rewriting prompts and tool contracts.

    Selection advice: first decide whether your primary constraint is performance and isolation, auditability, or delivery speed, and then choose a school, not the other way around.

    3. The Main Loop and Context Governance: The Most Hidden Divergence

    All implementations use a ReAct-style loop: the model output is either a tool call to execute or a final answer, and the loop converges at a termination condition. The real difference lies in context governance.

    The industry commonly adopts a “summarize plus tail retention” compression pattern: when token usage crosses a threshold, the earlier conversation is handed to the model to produce a structured summary, while the most recent turns are kept verbatim to maintain continuity. In public implementations, trigger thresholds range from 50% to 85%. A lower threshold is more conservative and more expensive; a higher one relies more on the model’s own resistance to forgetting.

    More importantly, watch how tokens are counted. Apart from a few implementations that use a real tokenizer for byte-level estimation, most use character-count heuristics. This produces systematic bias in Chinese and mixed-language scenarios, where the same character count maps to noticeably different token volumes, causing compression to happen too early or too late. The safe engineering practice is to plug in real token counting and to impose structural constraints on the summary artifact:

    1. {
    2. "goal": "The original goal of the current task",
    3. "decisions": ["Confirmed technical decisions"],
    4. "artifacts": ["Modified files and key functions"],
    5. "open_questions": ["Unverified assumptions"],
    6. "next_steps": ["Next actions"]
    7. }

    Cross-session memory should distinguish “factual memory” (long-lived preferences and conventions) from “procedural memory” (one-off task traces). The former is best written to a separate file and retrieved by the model on demand; the latter can stay in the event log. Mixing them pollutes the context.

    4. Session Persistence and Fault Tolerance: Treat Crashes as the Norm

    The advantage of event-sourced implementations shows here: every user input, model output, and tool result is an append-only event, and recovery simply replays them to rebuild the scene, with no separate snapshot mechanism. Non-event-based implementations usually rely on periodic snapshots plus incremental logs, and must handle the consistency window between snapshots and logs.

    Fault tolerance must cover three classes of failure: streaming interruptions caused by network jitter (requiring resumable transfers and idempotent retries), tool execution timeouts or non-zero exits (stderr should be structured and fed back to the model rather than thrown directly), and process crashes (file changes already produced must remain traceable). Retries must carry an idempotency key; otherwise duplicate writes and duplicate submissions will occur.

    5. Tool Calls, Instruction Following, and Orchestration

    The key design of the tool layer is a “minimal exposure surface”: the tool description is the prompt, and the clarity of naming and parameter descriptions directly determines call accuracy; dangerous operations should be split into separate tools so they can be authorized individually. For the system prompt, a long list of rules dilutes attention. A more reliable approach is to encode hard constraints as runtime validation (such as path allowlists and command blocklists) rather than relying on the model’s own discipline.

    Orchestration capability can be divided into three levels: plan mode (produce steps for confirmation before executing), subagents (context-isolated delegates that execute and return conclusions), and workflow engines (declarative orchestration and parallel scheduling). The three levels are not mutually exclusive; mature implementations are usually “plan mode as a gate plus subagents for context isolation.”

    6. Security Depth and Performance Trade-offs

    Security capability is polarized: one end combines an OS-level sandbox, a network egress proxy, and a device management configuration stack; the other end explicitly states in its documentation that no sandbox is provided and relies entirely on user approval. Enterprise adoption must build its own depth: container or micro-VM isolation, egress allowlists, keys never written to disk, and full operation auditing.

    On performance, native kernel implementations have an edge in startup and execution overhead; event-sourced implementations need to manage write amplification and storage growth, and can introduce snapshot compaction and log rotation. For cloud deployment, you can combine container platforms to host sandboxes, object storage to archive event logs, and logging and monitoring services with alerting to observe the call chain, forming a closed loop.

    7. Conclusion

    Competition among open-source coding agents has shifted from model capability to runtime engineering capability. Evaluation should build a scorecard across eight dimensions: the main loop, context governance, persistence, tool contracts, fault tolerance, instruction following, orchestration, and security. It should also run targeted validation for Chinese-language scenarios and your own compliance requirements, rather than relying on default configurations.