Agent Observability: From Directory Structure to Evidence Chains

    This article explains how to make AI agents observable and controllable by inspecting local state directories, layered orchestration, context assembly, and structured evidence. It covers startup state self-checks, request snapshots, a three-ledger evidence model, dual-track verification, role boundaries, and a practical implementation checklist for debugging inconsistent or unreliable agent behavior.

    1. The Starting Problem: Why Agents Look Uncontrollable

    Once AI coding tools become part of daily development workflows, the most common complaint is not that “the model is not smart enough.” It is a different class of problem: the same task succeeds today and fails tomorrow; switching a role or skill pack suddenly changes the output style and capability boundaries; the agent claims it finished a modification, but the codebase shows no corresponding change; or it stalls for a long time at some step, with only a generic timeout in the logs.

    Together, these symptoms point to one fact: an agent system is a distributed process built from the model, context, memory, tools, and orchestration logic. The model is only one layer. What actually determines behavior is how a request is assembled before it reaches the model, and how the response is interpreted and executed afterward. So the first step in building observability is not to swap the model, but to break down “what happened behind a single conversation” into objects that can be inspected.

    2. First Principle: Complexity Concentrates in a Local State Directory

    A mature agent product usually keeps all runtime state in a conventional user-level directory. Configuration, memory, session records, skill definitions, and role definitions are stored in separate subdirectories by layer. This design brings two direct benefits.

    First, it greatly lowers the cost of understanding. Developers do not need to read the entire source code first; they can simply walk through the directory layer by layer to see which state the system persists and where. Compared with reading an architecture diagram, inspecting the real directory is closer to the facts and makes it easier to spot leftover files from previous versions after an upgrade.

    Second, it provides a stable entry point for troubleshooting. Many “wrong behavior” issues are not caused by model randomness, but by a file in a half-updated state: a new field was written to the config but the old field was not removed; a memory file was corrupted by an interrupted run; or the skill manifest does not match the actual files on disk. The troubleshooting order should be to validate state first, then suspect reasoning.

    The recommended engineering practice is to include this directory in startup self-checks: before a session begins, validate the integrity, schema version, and reference consistency of key files, and emit the self-check result as a structured log. Example logic:

    1. state_root = ~/.agent
    2. check:
    3. config/schema_version == expected
    4. memory/index is parseable and referenced files exist
    5. latest file in sessions/ is appendable with no corrupted trailing line
    6. skills/manifest matches the actual directory one-to-one
    7. on failure -> enter read-only degraded mode and show the repair path

    3. A Layered Orchestration Model: Treat the System as an Index

    A common layered description in the industry can be abstracted into five layers: user interaction, orchestration, capability, context, and model serving. Its value is not in memorizing the layer names, but in locating where a problem belongs.

    • The interaction layer handles input collection, permission confirmation, and result presentation; problems appear as an unresponsive UI or missing confirmation.
    • The orchestration layer decides how a task is split into steps, which capability is called, and when to stop; problems appear as infinite loops or skipped steps.
    • The capability layer contains tools such as file read/write, command execution, retrieval, and test running; problems appear as out-of-range parameters or uncontrollable side effects.
    • The context layer assembles the final request; problems appear as “it seems not to know the project conventions.”
    • The model serving layer only generates output; problems appear as unstable formatting or reasoning bias.

    When something goes wrong, first determine which layer the symptom belongs to, then decide whether to fix state, adjust the orchestration strategy, or tighten tool permissions. This layered attribution avoids the most common misjudgment: blaming everything on the model.

    4. Context Assembly: How Four Kinds of Parts Rewrite a Request

    The system prompt is not a fixed block of text. It is dynamically assembled from four kinds of parts: persona settings, memory fragments, tool descriptions, and behavior rules. They are merged before the request is sent, so the same underlying capability can behave noticeably differently under different configurations.

    This also explains a frequent confusion: why the model “seems like a different person” after switching a role pack or skill pack. The reason is not that the model changed, but that the persona and rule fragments were replaced, the set of tool descriptions changed, and different memory entries were retrieved.

    Three engineering practices are recommended. First, add snapshot capability for the final request, recording which fragments were injected, their source files, and version numbers, to avoid “debugging by feeling.” Second, set priority and conflict-resolution rules for fragments, making the override order among persona, rules, and memory explicit. Third, control the context budget by trimming and ordering tool descriptions and memory so that key constraints are not drowned out by long text.

    1. request = merge(
    2. persona, # role and tone
    3. rules, # hard constraints and safety boundaries
    4. memory_hits, # historical facts retrieved
    5. tool_schema # list of capabilities available this time
    6. )
    7. snapshot(request) -> traces/context_20260901.json

    5. The Evidence Chain: Three Ledgers Make Behavior Replayable

    The core of observability is not having many logs, but having a clear evidence structure. Mature systems usually divide evidence into three types: session records, execution traces, and audit records.

    • Session records store each round of input and output as append-only records grouped by project, answering “what it said and did.”
    • Execution traces record each step’s tool call, parameter summary, duration, and result status, answering “how it did it.”
    • Audit records store the authorization, confirmation, and result of high-risk actions, answering “when, by whom it was approved, and why it was executed.”

    Together, the three form a complete evidence chain that makes any task replayable, reviewable, and accountable. Implementation points include: append writes instead of overwrites; a monotonic sequence number and causal identifier on each record; masking of sensitive fields; and retention and archiving policies. As data volume grows, cold data can be moved to object storage, and log services and monitoring alerts can set thresholds for write latency and failure rate.

    A very practical troubleshooting method is dual-track comparison: place the model’s self-reported “I thought it was done” side by side with “what actually happened” in the file system and test results. Hallucinations and privilege violations usually become visible immediately in the differences between the two columns, for example claiming tests were run when no corresponding call exists in the trace, or claiming only to read a file when a write operation appears in the audit.

    6. Boundaries of Expert Plugins and Multi-Role Collaboration

    An expert plugin with a UI is essentially a constrained sub-agent: it uses type declarations to distinguish single-agent mode from team mode, fully injects the role persona into the context at runtime, and then selects available skills accordingly. Multi-expert collaboration is another form of the orchestration layer, assigning one goal to multiple roles to advance in parallel or sequentially.

    This pattern improves professionalism but amplifies three risks. The first is identity conflict: the expert persona contradicts the global identity setting, causing the output to waver. Priority and fallback must be defined before launch, for example global safety rules always rank highest, followed by task rules, and role tone last. The second is permission spread: multiple roles each hold tool permissions, and their combination may form a privilege-escalation path, so authorization should be minimized per role and high-risk tools should be centrally controlled. The third is unclear responsibility: the collaboration process lacks a single owner, making it hard to locate the source of a decision in the audit, so every assignment must record the initiator, the basis, and the ownership of the output.

    It is recommended to establish version management and a gradual rollout mechanism for role definitions: changes go through review, rollback-capable versions are retained, validation starts on low-risk projects, and the scope expands from there.

    7. A Practical Implementation Checklist

    1. State self-check: validate directory structure and file integrity at startup; enter degraded mode on anomalies.
    2. Request snapshots: record the source and version of context parts to support precise post-hoc review.
    3. Three ledgers in parallel: use a unified identifier system for sessions, traces, and audits to keep them correlatable.
    4. Dual-track verification: compare self-reports with actual side effects as a fixed part of regression testing.
    5. Permission consolidation: grant least privilege per role and require manual confirmation for high-risk actions.
    6. Conflict rules: define the priority and fallback path for persona, rules, and memory.
    7. Capacity governance: set retention, archiving, and masking policies for evidence data, and configure monitoring alerts.

    8. Conclusion

    The controllability of agents does not come from a stronger model, but from clearer state, more transparent context assembly, a more complete evidence chain, and stricter role boundaries. By converging complexity into inspectable directories and replayable evidence, developers can shift from “guessing what the model is thinking” to “seeing what the system did,” which marks the maturing of agent engineering.