Molecule AI
ArchitectureTechnical Reference

Communication, API & A2A

Hierarchy communication rules, the platform API surface, and the A2A protocol.

Part of the Comprehensive Technical Documentation. Definitive reference based on a non-invasive scan of the molecule-core repository.

6. Communication Rules

Hierarchy = Topology

The CanCommunicate() function is the single source of truth for all access control.

DirectionAllowedExample
Sibling ↔ SiblingYESMarketing Agent ↔ Developer PM
Parent → ChildYESDeveloper PM → Frontend Agent
Child → ParentYESFrontend Agent → Developer PM
Skip levelsNOFrontend Agent → Business Core (403)
Cross-teamNOFrontend Agent → Operations Team (403)

Access Check Algorithm

IF caller.parent_id == target.parent_id → ALLOW (siblings)
ELIF both parent_id IS NULL → ALLOW (root-level siblings)
ELIF caller.ID == target.parent_id → ALLOW (parent→child)
ELIF target.ID == caller.parent_id → ALLOW (child→parent)
ELSE → DENY (403 Forbidden)

This same logic governs: A2A delegation, memory scope enforcement, activity visibility, approval routing, and WebSocket event fanout.


7. Platform API Routes

Workspace Lifecycle (8 endpoints)

MethodEndpointPurpose
POST/workspacesCreate and provision new workspace
GET/workspacesList all with canvas layout data
GET/workspaces/:idGet single workspace
PATCH/workspaces/:idUpdate name, role, tier, runtime, parent
DELETE/workspaces/:idRemove workspace
POST/workspaces/:id/restartRestart container
POST/workspaces/:id/pausePause with cascade to children
POST/workspaces/:id/resumeResume from pause

Registry & Discovery (5 endpoints)

MethodEndpointPurpose
POST/registry/registerWorkspace self-registration on startup
POST/registry/heartbeatLiveness + current task + error rate (30s interval)
POST/registry/update-cardPush Agent Card updates (skills, capabilities)
GET/registry/discover/:idResolve workspace URL (hierarchy-validated)
GET/registry/:id/peersList reachable peers for workspace

Memory (6 endpoints)

MethodEndpointPurpose
POST/workspaces/:id/memoriesCommit HMA-scoped memory (LOCAL/TEAM/GLOBAL)
GET/workspaces/:id/memoriesSearch scoped memories with query
DELETE/workspaces/:id/memories/:memoryIdDelete specific memory entry
GET/workspaces/:id/memoryList key/value workspace memory
POST/workspaces/:id/memoryUpsert key/value pair (optional TTL)
DELETE/workspaces/:id/memory/:keyDelete key/value entry

Secrets & Config (5 endpoints)

MethodEndpointPurpose
GET/workspaces/:id/secretsGet merged workspace + global secrets
POST/workspaces/:id/secretsUpsert workspace secret (triggers auto-restart)
DELETE/workspaces/:id/secrets/:keyDelete secret (triggers auto-restart)
GET/workspaces/:id/configGet workspace config.yaml
PATCH/workspaces/:id/configUpdate workspace config

A2A & Activity (5 endpoints)

MethodEndpointPurpose
POST/workspaces/:id/a2aProxy A2A request to target workspace
GET/workspaces/:id/activityList activity rows (filterable)
POST/workspaces/:id/activityReport activity from workspace
POST/workspaces/:id/notifyEmit user-facing notification
GET/workspaces/:id/session-searchSearch recent activity + memory for contextual recall

Team & Hierarchy (2 endpoints)

MethodEndpointPurpose
POST/workspaces/:id/expandExpand workspace into team (become coordinator)
POST/workspaces/:id/collapseCollapse team back to single workspace

Files, Terminal, Templates, Bundles (8 endpoints)

MethodEndpointPurpose
GET/workspaces/:id/files[/*path]List or read files
PUT/workspaces/:id/files/*pathWrite file
DELETE/workspaces/:id/files/*pathDelete file
WS/workspaces/:id/terminalWebSocket terminal session into container
GET/bundles/export/:idExport workspace as .bundle.json
POST/bundles/importImport workspace bundle (recursive)
GET/templatesList available workspace templates
POST/templates/importImport custom template folder

Observability & Real-Time (5 endpoints)

MethodEndpointPurpose
GET/healthHealth check
GET/metricsPrometheus metrics (v0.0.4 format)
GET/workspaces/:id/tracesLangfuse trace links
GET/events[/:workspaceId]Event stream (SSE)
WS/wsWebSocket hub for real-time event fanout

8. A2A Protocol

Message Format (JSON-RPC 2.0 over HTTP)

{
  "jsonrpc": "2.0",
  "id": "task-123",
  "method": "message/send",
  "params": {
    "message": {
      "role": "user",
      "parts": [{"kind": "text", "text": "Build the login feature"}],
      "messageId": "msg-456"
    }
  }
}

Two Call Modes

ModeMethodUse Case
Synchronousmessage/sendShort tasks, immediate response
Streamingmessage/sendSubscribeLong tasks, SSE progress updates

Discovery Flow

  1. Caller queries GET /registry/discover/:targetId with X-Workspace-ID header
  2. Platform validates CanCommunicate(caller, target) — returns 403 if denied
  3. Returns Docker-internal URL (workspace caller) or host-mapped URL (Canvas/external caller)
  4. Caller sends A2A message directly to target (peer-to-peer)
  5. Target processes task and responds

Task State Machine

submitted → working → completed
                   → failed
                   → canceled
         → input-required → working (caller provides input)

Authentication

  • MVP (current): Discovery-time validation only. Direct A2A calls are unauthenticated (acceptable for self-hosted Docker network isolation).
  • Post-MVP: Platform-issued short-lived signed tokens scoped to caller/target pair.

On this page