Skip to main content

Type 2 Wiring & Operations Manual

Status: Active Version: 1.0 Last Updated: 2026-04-18


Overview

This document describes the complete wiring between RABS and the Type 2 agents (Reggie and Henry), covering the SMS pipeline, admin chat integration, memory system, hybrid broker model, workspace synchronisation, and operational procedures. It was written following the initial live deployment and testing on 2026-04-18.

For architectural rationale, see Hybrid Broker Architecture. For session schema, see Type2 Agent Session Architecture.


1. System Topology

┌──────────────────────────────────────────────────────────────┐
│ RABS Backend (192.168.77.6:3009) │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────────────┐ │
│ │ sms.js │ │ agent-chat.js│ │ memory.js │ │
│ │ (webhook) │ │ (socket.io) │ │ /api/v1/memory/* │ │
│ └──────┬──────┘ └──────┬───────┘ └─────────────────────┘ │
│ │ │ │
│ ┌──────▼──────────────▼─────────┐ │
│ │ sms-type2-handler.js │ │
│ │ - classifies caller │ │
│ │ - resolves identity │ │
│ │ - builds prompt (DB memory) │ │
│ │ - fires webhook to VM │ │
│ │ - multi-stage SMS notifs │ │
│ └──────────────┬────────────────┘ │
│ │ │
│ ┌──────────────▼────────────────┐ │
│ │ type2-session.js │ │
│ │ - identity resolution │ │
│ │ - session management │ │
│ │ - prompt construction │ │
│ │ - auto memory logging │ │
│ └───────────────────────────────┘ │
│ │
│ ┌───────────────────────────────┐ │
│ │ agent-governance.js │ │
│ │ - response-time logging │ │
│ │ - policy enforcement (future) │ │
│ └───────────────────────────────┘ │
└──────────────────────┬───────────────────────────────────────┘
│ HTTPS webhook

┌──────────────────────────────────────────────────────────────┐
│ Agent VMs │
│ ┌────────────────────┐ ┌────────────────────┐ │
│ │ Reggie VM (.17) │ │ Henry VM (.16) │ │
│ │ OC runner :19191 │ │ OC runner :18181 │ │
│ │ FD runner :19091 │ │ FD runner :18081 │ │
│ │ │ │ │ │
│ │ Reads: coreMEM │ │ Reads: coreMEM │ │
│ │ Reads: .env │ │ Reads: .env │ │
│ │ Access: DB (r/o) │ │ Access: DB (r/o) │ │
│ │ Access: RABS API │ │ Access: RABS API │ │
│ │ Access: repo clone │ │ Access: repo clone │ │
│ └────────────────────┘ └────────────────────┘ │
│ │
│ Shared: /mnt/storage_agents/ (GoodSync to RABS host) │
└──────────────────────────────────────────────────────────────┘

2. SMS Pipeline

Message Flow

  1. Inbound SMS arrives at Twilio, forwarded to POST /api/v1/sms/webhook
  2. sms.js validates Twilio signature, logs to comms.sms_messages, checks for keywords (STOP, START, NOCONTRACT, YES ###)
  3. If no keyword match, fires handleIncomingSmsType2() in the background (does not await -- Twilio requires a response within 15 seconds or it retries)
  4. sms-type2-handler.js takes over:
    • Classifies the caller via inbound-classifier.js (staff/participant/external/unknown)
    • Resolves identity to canonical person_id (YP3000 UUID)
    • Gets or creates a Type 2 session
    • Registers the request as in-flight (prevents duplicate processing)
    • Builds prompt with DB memory context
    • Fires webhook to agent VM runner
    • Manages multi-stage SMS notifications while agent works
  5. Agent responds, handler sends SMS reply via Twilio and logs everywhere

Multi-Stage SMS Notifications

Users don't see reasoning steps like admin chat users do. Instead, the handler sends timed notifications:

DelayWhat the user receivesPurpose
2 seconds💭 (thought bubble emoji)Immediate acknowledgement -- message received
45 seconds"Hey {name}, just working on that for you. I'll text back shortly. - Reggie"First status update
2 min 15s"Still on it {name}, this one's taking a bit of digging"Periodic follow-up
Every 90s afterRotating follow-up messages with personalityKeeps user informed
15 min (max)Graceful failure with admin phone numberSafety net -- something is genuinely broken

All timers are cleared when the agent responds. If the agent responds in 10 seconds, the user only sees the 💭 and then the answer.

Follow-Up Message Handling

If a user sends another SMS while one is processing:

  1. In-flight tracking detects the active request
  2. User receives: "I'm still working on your earlier message -- I'll check this too and get back to you when I'm done!"
  3. The follow-up is logged to the session
  4. When the first request completes, queued follow-ups are processed as a new request with context from the previous exchange

Error Handling

  • If the webhook times out (15 min), the user receives a graceful British failure message with the admin phone number as fallback
  • Responses are logged to the database BEFORE attempting SMS delivery, so admin chat always shows the response even if Twilio fails
  • SMS delivery retries once with a 2-second delay on failure

3. Admin Chat Integration

How It Works

Admin chat uses Socket.IO for real-time communication. When a user sends a message via the admin dashboard:

  1. agent-chat.js receives the message via socket
  2. Resolves identity, gets/creates session
  3. Builds prompt with DB memory context
  4. Fires webhook to agent VM runner
  5. Streams progress updates back via Socket.IO as the agent works
  6. Delivers final response when agent completes

Timeouts

SettingReggieHenry FD
Foreground timeout2 min15 min
Max runtime15 min30 min

The foreground timeout controls when the UI switches from "waiting with spinner" to "working in background, we'll notify you." The agent keeps working either way. Max runtime is a safety net, not a performance target.

Cross-Channel Visibility

Because identity is unified via person_id, SMS conversations appear in the admin chat interface. An admin can see what Reggie discussed with a staff member over SMS. This is by design -- the same person has one unified session regardless of channel.


4. Memory System

Architecture

Memory is entirely database-backed in the brainframe schema. No disk-based memory.

TablePurposeWritten by
memory_eventsRaw observations and interactionslogMessage() in type2-session.js (automatic)
memory_indexesFast-lookup preferences, facts, key observations/api/v1/memory/observe (agent-initiated)
memory_summariesCumulative and weekly summariesNightly pipeline (not yet built)

Memory API

Agents access memory via the RABS API at http://192.168.77.6:3009/api/v1/memory/:

EndpointMethodPurpose
/memory/recallGETRetrieve summaries and context for a person
/memory/searchGETSearch indexed memories by keyword
/memory/observePOSTSave a new observation (preference, fact, finding)
/memory/feedbackPOSTRecord feedback on a memory (reinforce or correct)

Prompt Injection

The buildPrompt() function in type2-session.js automatically injects memory context into every agent prompt. The "zoom lens" hierarchy:

  1. Cumulative summary -- "who is this person to me" (long-term)
  2. Weekly summary -- "what's been happening lately"
  3. Memory indexes -- known preferences, facts (up to 15 entries, sorted by confidence)
  4. Session summary -- conversation-level context
  5. The actual message

Current Status

  • memory_events -- working (auto-logged on every message)
  • memory_indexes -- working (agents can observe and search)
  • memory_summaries -- empty (nightly pipeline not yet built)
  • memory/recall -- returns empty until summaries exist (this is expected, not broken)

5. Hybrid Broker Model

Agents have three ways to access RABS data. See Hybrid Broker Architecture for the full rationale.

Broker API

For external services (Xero, Deputy, Twilio) and write operations. Every call is logged to brainframe.agent_access_log.

POST /api/v1/broker/call
{
"agent_id": "reggie",
"tool_id": "leave.balance",
"arguments": { "staff_id": "..." },
"reason": "Staff member asking about their leave"
}

Tools are registered in brainframe.tools with an agent_access column controlling which agents can use which tools. Execution modes: auto (immediate), review (queued for human approval), disabled.

Direct Database Access

Read-only PostgreSQL access for complex queries, reporting, and data investigation.

  • Host: 192.168.77.10, Port: 5432, Database: rabsdb
  • User: type2agent (read-only)
  • Key schemas: accounts, admin, brainframe, comms, core_source, core_ops, finance, hr

RABS Codebase

Cloned repo at /mnt/storage_agents/production/rabs/APP_Clone/rabs/ for understanding implementations, checking schemas, and resolving ambiguous API responses.


6. Workspace Synchronisation

Structure

The agent workspace lives on the VMs at /mnt/storage_agents/. A clone is available in the RABS repo at type2Agents/workspace_clone/ for direct editing.

type2Agents/workspace_clone/
├── AGENTS.md # Lean orientation file
├── coreMEM-reggie.md # Reggie's complete operational guide
├── coreMEM-henry.md # Henry's complete operational guide
├── coreMEM_api_companion.md # API reference (Reggie-authored)
├── reginald/ # Reggie's personal workspace
│ └── ID/ # OpenClaw identity docs
└── henry/ # Henry's personal workspace
└── ID/ # OpenClaw identity docs

Sync Mechanism

GoodSync monitors the workspace and syncs changes between the RABS host and the agent VMs on a timed interval (currently 3 minutes). Edits made in workspace_clone/ propagate to the VMs automatically.

Important Note for Developers

The type2Agents/ folder is a synced/symlinked directory. Glob and Grep tools cannot index it. Use direct Read and Edit with explicit file paths. This is documented in the task helper header (admin/tasks/helpers/00_task_helper_header.md).

coreMEM Files

These are the primary instruction files for each agent. Loaded by the OpenClaw runner on the VM as part of the agent's system prompt. The RABS backend does NOT read or inject coreMEM content -- CORE_MEMORY_DIR in type2-session.js is a dead variable.

coreMEM files contain:

  • Agent identity and personality
  • Channel-specific delivery rules
  • Memory API usage with curl examples
  • Broker tool reference with arguments
  • Database connection details
  • Privacy rules per channel
  • Common workflows
  • Boundaries and safety rules

7. Identity Unification

All channels resolve to the same canonical person_id using the brainframe.resolve_type2_identity() database function. The YP3000 UUID is the canonical identifier.

ChannelIdentifierResolution
Admin ChatUser UUID (from JWT)Mapped to YP3000 UUID via core_source.yp3000_identities
SMSPhone number (E.164)Matched via core_source.yp3000_contact_details
DiscordDiscord user IDMatched via identity mapping
TelegramTelegram user IDMatched via identity mapping

This means:

  • The same person has one unified session across all channels
  • Memory accumulated on SMS is available on admin chat
  • An admin can see SMS conversations in the admin chat interface

8. Agent Governance

Current State: Logging Only

The agent-governance.js middleware intercepts all API responses when req.user.type === 'agent' and logs:

  • Endpoint called
  • Response time
  • Agent identity
  • HTTP status

Logs go to brainframe.agent_access_log.

Future: Enforcement Mode

When switched to enforcement, the middleware will check brainframe.endpoint_policies and block or flag requests that violate policy. This is not yet active.


9. Inbound Classification

The inbound-classifier.js service classifies every incoming message into one of four funnels:

Actor ClassRisk LevelPrivacy Context
staff(low)lowCan share their own data
participant(low)lowCan share their own schedule/plan
external(medium)mediumGeneral info only
unknown(high)highIdentify first, general info only

Classification results are passed to the agent via the webhook metadata, allowing the agent to make appropriate privacy decisions.


10. Database Schema

All agent-related tables are in the brainframe schema:

TablePurpose
toolsTool registry with agent_access column
agent_access_logAudit trail of all agent API calls (no FKs -- audit survives deletes)
endpoint_policiesPer-endpoint access rules (for future enforcement)
memory_eventsRaw memory entries from conversations
memory_summariesGenerated summaries (cumulative, weekly)
memory_indexesFast-lookup preferences and facts

Session and message tables are in the comms schema:

TablePurpose
type2_sessionsOne session per person+agent+channel combination
type2_messagesAll messages (inbound and outbound) with metadata

11. Operational Procedures

Restarting an Agent

Agents run as systemd services on their VMs. The RABS backend connects to them via webhook -- if the VM runner is down, the webhook will timeout and the user gets a graceful failure message.

Updating Agent Instructions

  1. Edit files in type2Agents/workspace_clone/ (coreMEM, AGENTS.md, companion)
  2. Wait for GoodSync sync (up to 3 minutes)
  3. Agent picks up changes on next conversation (coreMEM is loaded per-session by the runner)

Adding a New Broker Tool

  1. Insert a row into brainframe.tools with the tool definition
  2. Set the agent_access array to include the agent names that should use it
  3. Implement the handler in backend/routes_v1p/broker.js
  4. Document in coreMEM and the API companion

Checking What Went Wrong

  1. Server logs -- search for [sms-t2] entries for SMS pipeline, [agent-chat] for admin chat
  2. brainframe.agent_access_log -- every API call an agent makes through the governance middleware
  3. comms.type2_messages -- every message in and out, with correlation IDs and metadata
  4. comms.sms_messages -- SMS-specific delivery log
  5. hr.reggie_runs -- analytics-compatible log (question type T2 distinguishes from V3)
  6. brainframe.memory_events -- all memory observations

Live Test Results (2026-04-18)

CapabilityStatusNotes
Broker: staff.searchWorkingFound staff records via broker
Broker: leave.balanceWorkingReturned Xero leave data in hours
Direct DB accessWorkingQueried staff table directly
Repo accessWorkingRead code to determine leave units
Memory: observeWorkingWrote to memory_events + memory_indexes
Memory: searchWorkingFound indexed entries by keyword
Memory: recallEmpty (expected)Nightly summarisation pipeline not yet built
SMS pipelineWorkingDelivered responses, multi-stage notifications
Admin chatWorkingFull progress visibility, tool usage, memory
Cross-channel visibilityWorkingSMS sessions visible in admin chat

12. Known Issues & Future Work

Known Issues

  • memory/recall returns empty -- this is expected until the nightly summarisation pipeline is built
  • Glob/Grep cannot index type2Agents/ -- use direct Read/Edit with explicit paths (documented in task helper)
  • backend/agents/ is stale -- deprecated folder with old URLs. A DEPRECATED.md warning is in place.

Planned

  • Nightly memory summarisation -- scheduled job to generate cumulative/weekly summaries from memory_events
  • corePEOPLE document -- who's who of the admin team with IDs and trust levels
  • Safety and robustness testing -- destructive command detection, social engineering resistance
  • Fast Reggie Intercept -- flash model fast-path for conversational SMS (greetings, thanks) to avoid full T2 pipeline for simple messages. Only if testing shows response time is a real UX issue.
  • Privacy context injection -- _privacy field in API responses for channel-aware data handling
  • Agent governance enforcement -- switch from logging-only to active policy enforcement