Agent Observability: From Directory Layout to Evidence Chains
This article presents a general engineering approach to observability for AI coding agents and agent platforms. It explains why inspecting the local working directory often reveals more than reading architecture diagrams, how a five-layer reference model helps isolate faults, what components make up the system prompt, and how three types of evidence make agent behavior replayable and accountable. Readers will find practical guidance on versioning templates, defining role conflict priority, and managing agent identity files.
Agent Observability: From Directory Layout to Evidence Chains
A single interaction involves far more than what the interface shows between the moment a user presses Enter and the moment the model emits its first token. When teams debug “the agent is behaving incorrectly,” their first instinct is often to blame the model. In practice, the more common root causes are deviations in state files, context assembly, or permission boundaries. This article does not cover the operation of any specific product. Instead, it abstracts a common engineering pattern across AI coding tools and agent platforms: how to use directory conventions to hold state, how to use a layered model to locate problems, and how to use evidence chains to make every action replayable and accountable.
1. Why Checking the Directory First Beats Reading the Architecture Diagram
In a mature agent runtime, most of the complexity quietly settles into a local working directory. Configuration, memory, sessions, skills, and expert roles are stored in layers by convention. This design offers three benefits:
- Externalized state: The runtime does not hide critical state in memory or a remote black box, so any anomaly can be observed directly through the file system.
- Portability: Switch machines or environments, and behavior can be reproduced as long as the directory structure is intact.
- Diagnosability: When the agent stalls, times out, or produces off-target output, the cause is often not the model “acting up” but a file that is partially written, version-mismatched, or missing a field.
The recommended engineering action is to print and read your directory tree before integrating any agent framework, and confirm the responsibility boundary of each layer. This is more direct than reading ten architecture diagrams.
~/.agent/├── config/ # Global and project-level configuration├── memory/ # Long-term memory and user profiles├── sessions/ # Session records grouped by project├── traces/ # Execution traces├── audit/ # Audit logs└── skills/ # Skill and role definitions
2. A Five-Layer Reference Model: Using Architecture as an Index
A common layering approach in the industry can be summarized as five layers, from top to bottom: the user interaction layer, the orchestration layer, the capability layer, the context layer, and the model service layer. The point is not to memorize the layer names but to understand the “fault semantics” of each layer:
- Problems in the interaction layer show up as rendering issues or interrupted streaming output;
- Problems in the orchestration layer show up as out-of-order tool calls or subtasks that fail to converge;
- Problems in the capability layer show up as plugins or skills that are not registered correctly, or parameter validation failures;
- Problems in the context layer show up as “memory loss,” “sudden tone changes,” or “rules not taking effect”;
- Only problems in the model service layer truly show up as degraded generation quality.
The practical value of this indexing method is to first determine which layer a symptom belongs to, then decide which type of evidence to examine, avoiding the urge to tune parameters or swap models right away.
3. The Four Components of the System Prompt
Before a request reaches the model, the context has already been quietly rewritten. It is typically assembled from four components:
- Persona settings: Determine tone, boundaries, and refusal policies;
- Memory injection: A summary of long-term memory and the user profile;
- Tool descriptions: The list of available capabilities and invocation constraints;
- Rule constraints: Security, formatting, approval, and fallback rules.
This explains a common phenomenon: with the same base model, switching the role package or skill package noticeably changes the tone and capability boundaries. From an engineering perspective, templates should be treated as versionable code assets. When the same template exists in both the application package and the user directory, priority must be defined explicitly; otherwise, “ghost” problems where changes do not take effect will appear.
# Example: Priority of context assemblypriority:system_rules: 100expert_persona: 80user_memory: 60tool_schema: 40
4. Three Types of Evidence: Making Behavior Replayable and Accountable
The core of observability is not the volume of logs but the structure of evidence. At minimum, maintain three ledgers:
- Session records: Answer “what it did,” logging input, output, and tool calls turn by turn;
- File history: Answer “what it changed,” recording before-and-after diffs and the operator;
- Traces and audit logs: Answer “when and why,” recording decision rationale, approvals, and failure reasons.
This yields a cost-effective troubleshooting method: dual-track comparison. Place the model’s self-reported “I thought I did X” side by side with the file system’s record of “Y actually happened.” Hallucination, privilege escalation, and missed execution typically become obvious at a glance.
| Symptom | Self-report | Actual | Common root cause |
|---|---|---|---|
| Hallucination | Configuration modified | No change recorded | Tool was never actually called |
| Privilege escalation | Read-only inspection | A write operation occurred | Permission rules were not injected |
| Missed execution | Tests completed | No trace | Orchestration layer returned early |
5. Boundaries of Expert Plugins and Multi-Role Collaboration
A sub-agent with an interface is essentially a “declarable role”: a type field declares whether it is a single role or a team, the runtime injects the full role persona into the context, and the corresponding skills are invoked accordingly. Multi-role collaboration is an orchestration-layer capability responsible for task decomposition, dispatch, and aggregation.
One incident boundary must be settled before launch: when the role persona conflicts with the user identity settings, who takes priority, how to degrade, and how to fall back to a safe default. It is recommended to enforce a hard priority of “rules > role > memory” and explicitly record in the audit log when a conflict occurs and which policy was adopted.
6. Identity System: The Four-File Convention
A widely used practice is to carry identity in four files: persona, identity, user profile, and long-term memory. They respectively answer “how to speak,” “who I am,” “who the user is,” and “what we have experienced together.” Engineering recommendations:
- Put all of them under version control, with changes going through review;
- Memory writes require deduplication and time-stamping to avoid stale information polluting the context;
- Sensitive fields must be redacted before entering long-term memory.
7. Implementation Checklist
- Read the directory first, then the documentation; 2. Use the five-layer model to classify faults; 3. Version templates and rules and define priority explicitly; 4. Keep all three ledgers complete and stick to dual-track comparison; 5. Define hard priority and fallback paths for role conflicts; 6. Put the four identity files under review and redaction processes.
When state is enumerable, context is explainable, and actions are replayable, the “uncontrollability” of agents degrades into an ordinary engineering problem. To store session and audit data, you can combine general cloud capabilities such as object storage, logging services, and monitoring and alerting to achieve low-cost retention and anomaly alerts.
