Agent Sandbox Registry

python-sdk

Decision: L3→L2 layer-violation fix and error-code reassignment

无中文版

.agents/notes/implemented/architecture/2026-09-09-layer-violation-fix.md

Decision: L3→L2 layer-violation fix and error-code reassignment

Status: implemented

Problem

The project's layered architecture (L0 Models/Utils → L1 Transport → L2 Protocol → L3 API) had several violations, causing circular-dependency risk and architectural erosion:

  1. session/__init__.py upward dependency: the session module (same tier as L1) imported api.session_manager.SessionManager (L3), forming a lower→higher reverse dependency.
  2. Error types in the wrong location: TemplateBuildError and TemplateBuildTimeoutError were defined in protocol/template.py (L2), but error types are the responsibility of the L0 Models layer.
  3. Error-code collision: the original codes E7001/E7002 collided with the existing TemplateNotFoundError (E7001) / TemplateParseError (E7002).
  4. Missing CLI command groups: the cli/commands/ directory lacked the four command modules session.py, secret.py, skill.py, and auth.py.

Decision

1. Remove the session upward dependency

Remove the SessionManager import from session/__init__.py; __all__ exposes only the L0/L1-level SessionStore (base) and LocalSessionStore (local). Users who need SessionManager import it directly from api.session_manager.

2. Move error classes to models/errors.py

Move TemplateBuildError and TemplateBuildTimeoutError from protocol/template.py to models/errors.py (L0), so that all exception types are centralized in the errors module.

3. Error-code reassignment

The E7010+ range is reserved for Template Build errors and does not collide with the existing E7000–E7003 (TemplateError/TemplateNotFoundError/TemplateParseError/ TemplateValidationError).

4. Fill in the CLI command groups

Add four CLI command modules: - cli/commands/auth.py — authentication management (login/logout/status) - cli/commands/session.py — session management (list/save/restore/delete) - cli/commands/secret.py — secret management (set/get/list/delete) - cli/commands/skill.py — skill management (list/install/remove/run)

API Design

# session/__init__.py — after the fix
from agent_sandbox.session.base import SessionStore
from agent_sandbox.session.local import LocalSessionStore

__all__ = ["SessionStore", "LocalSessionStore"]
# no longer imports SessionManager (L3)

# models/errors.py — new error-code range
# --- Template Build Errors (E7010+) ---
class TemplateBuildError(SandboxError):
    """Template build failed."""
    code = "E7010"

class TemplateBuildTimeoutError(SandboxError):
    """Template build timed out."""
    code = "E7011"

Alternatives considered

Dependencies

Test Strategy

Acceptance criteria

Files changed