# Soi96 Legal — AI Agent Architecture

## Overview

Ten agents. One job each. Strict hierarchy. No agent communicates with anything outside its defined chain.

The attorney interacts with one thing only — the Prompt Analyst. Everything else happens behind that interface. The attorney should never need to navigate the platform directly for any task, whether that is a quick note after a call or a full case strategy review.

---

## The Agent Roster

| # | Agent | Real-World Analogy | Count | Primary Role |
|---|---|---|---|---|
| 1 | Prompt Analyst | Executive Secretary | 1 | Only UI connection. Interprets attorney intent, calls Document Classifier first on any incoming document, then delegates and assembles the response. Never touches data. |
| 2 | Onboarding Agent | Intake Coordinator | 1 | Parallel to Prompt Analyst (peer, not subordinate). All new data in — manual or automated. Hands off to Prompt Analyst only. Never writes directly to client records. |
| 3 | Document Classifier | Records / Filing | 1 | Called by Prompt Analyst before any routing decision. Identifies document type, matter reference, practice area, and recommended action. Enables precise downstream delegation. |
| 4 | Case/Situation Analyst | Senior Associate | 1 | Receives pre-classified, context-rich requests from Prompt Analyst. Coordinates Client Managers and calls specialist agents. |
| 5 | Client Manager | File Handler / Associate | 1 per client | Knows one client completely. Executes all read/write operations for that client. Reports back up the chain. |
| 6 | Comms Agent | Receptionist / Office Manager | 1 | Parallel track to Case/Situation Analyst. All inbound comms, routine operational tasks, proactive alerts, internal calendar, Google Calendar sync. |
| 7 | RAG Agent | Law Library | 1 | Statute lookup only. Called by Case/Situation Analyst with a precisely framed query — after Prompt Analyst and Document Classifier have already established the domain context. |
| 8 | Billing Agent | Accounts | 1 | Retainers, trust accounts, invoicing, AR. Deterministic rules only. Called by Case/Situation Analyst. |
| 9 | Judicial Intelligence | Judicial Analyst | 1 | Career-long profiles on judges and court support teams. Built across all matters regardless of client. Called by Case/Situation Analyst. |
| 10 | Adversary Intelligence | Opposition Researcher | 1 | Career-long profiles on opposing counsel and law firms. Separate from judicial profiling — different data, different strategic use. Called by Case/Situation Analyst. |

---

## Hierarchy Diagram

```
                        ATTORNEY
                            ↕
┌──────────────────────────────────────────────────────────────────┐
│                      PROMPT ANALYST                              │
│                    (Executive Secretary)                         │
│                                                                  │
│  — Only UI connection to the system                              │
│  — Interprets natural language intent                            │
│  — Calls Document Classifier FIRST on any incoming document      │
│  — Determines which track(s) to route to, with full context      │
│  — Delegates with structured, pre-qualified requests             │
│  — Receives results, presents to attorney                        │
│  — Receives handoffs from Onboarding Agent                       │
│  — Never touches data directly                                   │
│                                                                  │
│   ┌──────────────────────────────────────────────────────────┐   │
│   │              DOCUMENT CLASSIFIER                        │   │
│   │                                                          │   │
│   │  — Called by Prompt Analyst before any routing          │   │
│   │  — Identifies: type · matter ref · practice area        │   │
│   │  — Returns: domain context that makes all downstream    │   │
│   │    agents more precise                                   │   │
│   │  — Thai-language docs from day one                      │   │
│   └──────────────────────────────────────────────────────────┘   │
└──────────────────────────┬───────────────────────────────────────┘
                           │                         ▲
                           │                         │ handoff
                           │              ┌──────────┴─────────────┐
                           │              │    ONBOARDING AGENT    │
                           │              │   (Intake Coordinator) │
                           │              │  Peer to Prompt        │
                           │              │  Analyst. New data in. │
                           │              │  Hands off only.       │
                           │              └────────────────────────┘
                           │
               ┌───────────┴─────────────┐
               │                         │
               ↕ (series)                ↕ (parallel)
               │                         │
   ┌───────────┴──────────┐  ┌───────────┴───────────────────────┐
   │  CASE/SITUATION      │  │          COMMS AGENT              │
   │      ANALYST         │  │        (Receptionist)             │
   │                      │  │                                   │
   │  Receives pre-        │  │  — Inbound email + LINE           │
   │  classified,          │  │  — Routine operational tasks     │
   │  domain-scoped        │  │  — Proactive alerts              │
   │  requests.            │  │  — Internal calendar             │
   │                      │  │  — Google Calendar sync           │
   └──────────┬───────────┘  └───────────────────────────────────┘
              │
   ┌──────────┼──────────────────────┐
   │          │          │           │
   ↕          ↕          ↕           ↕
   │          │          │           │
CLIENT    RAG AGENT  BILLING    JUDICIAL
MANAGER              AGENT      INTEL
(×N)                            +
                                ADVERSARY
                                INTEL
```

---

## The Sequencing Rule

Classification comes before routing. Routing comes before research. The sequence is not optional.

```
STEP 1 — PROMPT ANALYST reads the request
         What is being asked?
         Is a document involved?

STEP 2 — DOCUMENT CLASSIFIER (if document present)
         What type is it?
         Which matter does it belong to?
         Which practice area / jurisdiction?
         NOW the system knows the domain.

STEP 3 — PROMPT ANALYST routes with full context
         Knows practice area → can frame downstream queries precisely
         Knows matter reference → routes to the correct Client Manager
         Knows document type → knows whether to escalate or file

STEP 4 — CASE/SITUATION ANALYST receives a scoped request
         Not "look up immigration rules"
         But "retrieve BOI Section 12 re: manufacturing licences
              for foreign majority ownership — context: TM.7
              extension, US national, BOI zone 3"

STEP 5 — RAG AGENT receives a precise query
         Returns the exact provision that applies
         Not a broad statute dump
```

Neither the RAG Agent nor the Case/Situation Analyst works blind on an unframed question. By the time anything reaches them, the domain, matter reference, and document type are already established.

---

## Communication Rules — Enforced at Architecture Level

Each agent has a fixed set of agents it is permitted to communicate with. This is a hard constraint, not a convention.

| Agent | May call | May not call |
|---|---|---|
| Prompt Analyst | Document Classifier, Case/Situation Analyst, Comms Agent | Client Managers, RAG Agent, Billing Agent, Judicial Intelligence, Adversary Intelligence |
| Onboarding Agent | Prompt Analyst (handoff only) | All others |
| Document Classifier | (document store only) | Any agent |
| Case/Situation Analyst | Client Managers, RAG Agent, Billing Agent, Judicial Intelligence, Adversary Intelligence | Prompt Analyst, Onboarding Agent, Comms Agent |
| Client Manager | (platform data store only) | Any agent |
| Comms Agent | (platform data store only) | Any agent |
| RAG Agent | (statute vector store only) | Any agent |
| Billing Agent | (billing data store only) | Any agent |
| Judicial Intelligence | (intelligence data store only) | Any agent |
| Adversary Intelligence | (intelligence data store only) | Any agent |

No agent skips a level. No agent reaches sideways. Every response travels back up the same chain it came down.

---

## The Two Tracks

### Track 1 — Case / Research Track (Series)

```
Prompt Analyst  [calls Document Classifier first if document involved]
    → Case/Situation Analyst
        → Client Manager(s)
        → RAG Agent (statute lookup, precisely framed)
        → Billing Agent (if financial data required)
        → Judicial Intelligence (judge + court profile)
        → Adversary Intelligence (opposing counsel + firm profile)
    ← Aggregated response
← Attorney-facing answer
```

### Track 2 — Operational / Comms Track (Parallel)

```
Prompt Analyst
    → Comms Agent
        → Schedule / reschedule / notes / email / LINE /
           proactive alerts / calendar sync
    ← Confirmation
← Attorney-facing confirmation
```

Both tracks can run simultaneously on a single request. The Prompt Analyst holds both threads and assembles the combined response.

---

## The Learning Loop

```
MATTER OPENS
│
├── Prompt Analyst calls Document Classifier
│     → type identified, matter ref resolved, domain known
│
└── Case/Situation Analyst queries in parallel:
      Client Manager          → full client history
      Judicial Intelligence   → judge profile for this court
      Adversary Intelligence  → opposing counsel/firm profile
      RAG Agent               → relevant statutes (domain-scoped)
      Billing Agent           → retainer status
      → assembled into strategic brief → attorney


MATTER IN PROGRESS
│
├── Every document in → Onboarding Agent → Prompt Analyst
│     → Document Classifier (type + matter ref)
│     → Case/Situation Analyst → Client Manager (stored)
│
├── Every approved Comms draft → training queue
│     Weekly fine-tune on Workbeast
│     → Comms Agent sounds more like this firm each cycle
│
└── Every hearing → attorney observations captured
      → Client Manager stores raw notes


MATTER CLOSES
│
└── Case/Situation Analyst triggers close pipeline:

      Client Manager extracts (strips client context first):
      │
      ├── Hearing outcomes, judge responses to arguments
      │   Court staff interactions
      │   What worked, what did not            ──► JUDICIAL INTEL
      │                                              profile deepens
      │
      └── Opposing counsel behaviour
          Firm tactics, settlement patterns    ──► ADVERSARY INTEL
                                                    profile deepens

      Client Manager itself also updates:
          New matter outcome, behavioural notes,
          standing instructions revised         ──► CLIENT MANAGER
                                                    profile deepens

      Case/Situation Analyst outcome added
      to training queue → better synthesis
      on this matter type next time
```

---

## Specialist Practice Value

The architecture does not change by practice area. The corpus, client schema, and adversary scope are configured at tenant onboarding.

| Specialist Need | Which Agent | How It Compounds |
|---|---|---|
| Practice-area statute corpus (immigration, BOI, foreign business) | RAG Agent | Corpus loaded at onboarding per practice area. Reflects jurisdiction-specific rules for that tenant. |
| How law is actually applied (informal requirements, examiner behaviour) | Case/Situation Analyst | Learns from this firm's matter outcomes — the gap between statute and practice closes over time. |
| Government officer profiles (BOI examiners, immigration officers, land office staff) | Adversary Intelligence | "Adversary" is defined broadly — includes any official whose discretion affects outcomes. Same agent, wider scope. |
| Client specialist profiles (visa class, nationality, treaty eligibility, rejection history) | Client Manager | Schema is defined by the attorney at intake. An immigration firm's profile looks nothing like a family law firm's. |
| Inbound policy circulars and rule changes | Comms Agent + Document Classifier | Comms watches inbound. Classifier identifies official circulars. Attorney notified. Open matters can be audited against the new rule. |

The more arcane, contradictory, and relationship-dependent the practice area, the more valuable the platform becomes. The informal knowledge layer — how rules are actually applied by these officers, at these offices, under these informal conditions — currently lives in senior attorneys' heads. This platform is where it lives instead.

---

## Client Manager — One Per Client, Not One For All

Each Client Manager is a dedicated agent instance for a single client, initialised at onboarding and persisting for the life of that relationship.

**What it holds:**
- Full client profile (identity, assets, family/corporate structure, behavioural notes, communication preferences)
- Complete matter history
- All documents linked to that client
- Standing instructions
- Prior outcomes and strategic notes

**Rules:**
- Executes read and write operations for its client only
- Does not communicate with other Client Managers
- Does not call the RAG Agent — that is the Case/Situation Analyst's job
- Reports back up to Case/Situation Analyst only

---

## Onboarding Agent — Peer, Not Subordinate

Runs independently of the attorney request cycle. New information enters through the Onboarding Agent on its own schedule. On completion it packages the data and hands off to the Prompt Analyst, which coordinates where it goes via the standard chain.

**Rules:**
- Never writes directly to client records
- Never communicates with Client Managers, Case/Situation Analyst, or any downstream agent
- Runs a conflict check on new client and opposing party names before handoff
- Identifies whether this is a new client (new Client Manager required) or existing client (update required)

---

## Document Classifier — Called First, Not Last

Called by the Prompt Analyst before any routing decision. Its output is what makes downstream delegation precise rather than generic.

**What it returns:**
```
{
  document_type:        court_summons | chanote_deed | hearing_notice |
                        judgment | contract | financial_disclosure |
                        dbd_extract | opposing_counsel_letter |
                        client_correspondence | evidence |
                        government_circular | policy_update | unknown,
  language:             th | en | bilingual,
  practice_area:        civil_litigation | family | corporate_setup |
                        immigration | property | employment | tax | unknown,
  matter_reference:     <matter_id if identifiable>,
  client_reference:     <client_id if identifiable>,
  confidence:           high | medium | low,
  recommended_action:   file_to_matter | attorney_review |
                        paralegal_review | urgent_escalation,
  flags:                [deadline_present, opposing_counsel, court_issued,
                         requires_response, government_issued, rule_change]
}
```

Thai-language legal documents handled from day one. When confidence is low, the document is flagged for attorney review — attorney corrections feed back into classifier training.

---

## RAG Agent — Law Library, Not General Retrieval

One job: statute corpus lookup. Called by the Case/Situation Analyst with a precisely framed query, after the Prompt Analyst and Document Classifier have already established the domain context.

**Corpus (Thai jurisdiction template):**
- Thai Civil and Commercial Code (Books I–VI)
- Land Code
- Labour Protection Act
- Foreign Business Act
- Revenue Code
- BOI regulations
- Private Limited Companies Act
- Consumer Protection Act
- Immigration Act
- Condominium Act

Additional corpus loaded per tenant practice area at onboarding.

---

## Billing Agent — Accounts, Not Case Management

Deterministic rules only. No training. Called by Case/Situation Analyst when financial data is required.

**Scope:** client retainer balances, trust account ledger, time entry aggregation, invoice generation, AR aging, disbursement tracking.

Client funds never mixed with operating funds — enforced at the data layer with full audit trail.

---

## Judicial Intelligence — The Court Environment

Career-long profiles on every judge and court support team the firm has appeared before. Builds across all matters regardless of which client is involved.

**Judge Profile covers:**
- Ruling tendencies by matter type
- Procedural vs narrative preference
- Documentary standards and evidence threshold
- Interim order disposition
- Settlement vs judgment inclination
- Behavioural patterns: hearing management, tolerance for unprepared counsel
- Firm history: every appearance, every outcome, what worked and what did not

**Court Support Profile covers:**
- Processing speed and filing behaviour
- Preferred filing windows
- Known friction points and shortcuts within the rules
- Who has authority to resolve filing disputes

**Key principle:** Judicial Intelligence holds no client context. It holds what the firm has learned about how the court environment behaves.

---

## Adversary Intelligence — Opposing Counsel and Firms

Career-long profiles on every opposing counsel and law firm the firm has faced. Separate agent from Judicial Intelligence — different data source, different strategic application.

In specialist regulatory practice (immigration, BOI, foreign business), "adversary" expands to include government officers and examiners whose discretion affects outcomes. Same agent, scope configured at tenant onboarding.

**Opposing Counsel Profile covers:**
- Litigation style: aggressive vs procedural
- Settlement behaviour: at what point they open discussions and under what conditions
- Filing discipline and documentation quality
- Pressure tactics under stress
- Known strengths, weaknesses, prior procedural errors
- The firm's full record against them

**Law Firm Profile covers:**
- Specialism and resourcing patterns
- Whether they put senior or junior counsel on different matter types
- Known firm-level strategies
- Overall record for this firm against them

**Key principle:** Adversary Intelligence holds no client context. Cross-matter intelligence strips client-specific detail before it crosses from Client Manager to this agent.

---

## Why Judicial and Adversary Intelligence Are Separate

| | Judicial Intelligence | Adversary Intelligence |
|---|---|---|
| Subject | Judges, court clerks, registrars | Opposing counsel, law firms, government officers |
| Strategic use | How to argue, how to present, what to watch for in this court | How to anticipate, when to push, when to settle |
| Data source | Hearing notes, outcomes, procedural observations | Matter conduct, filing behaviour, settlement history |
| Compounds on | Every matter in this court regardless of client | Every matter against this counsel/firm regardless of client |

Merging them would dilute both. A judge profile and an opposing counsel profile require different data, different analysis, and serve different strategic purposes.

---

## The Training Loop Summary

| Agent | Learns from | Does not learn |
|---|---|---|
| Prompt Analyst | Attorney query patterns, phrasing, priorities | Other tenants' attorneys |
| Document Classifier | Attorney corrections to misclassified docs | — |
| Case/Situation Analyst | Matter outcomes, what data proved relevant | Other tenants' matters |
| Client Manager | New documents, communications, outcomes, corrections | Any other client |
| Comms Agent | Every approved draft (positive) and correction (signal) | Other tenants' voice |
| Judicial Intelligence | Every matter close → hearing outcomes, judge responses | Other tenants' observations |
| Adversary Intelligence | Every matter close → opposing conduct, settlement patterns | Other tenants' observations |
| RAG Agent | Corpus updates when statutes change | Firm data of any kind |
| Billing Agent | Nothing — deterministic rules only | — |
| Onboarding Agent | Correction patterns from handoff normalisation errors | — |

Training runs weekly on Workbeast (Saturday 2am, existing pipeline). Each tenant's agents train exclusively on their own data. No tenant's training data crosses to another tenant.

---

## Tenant Isolation — Your AI Is Yours

```
Base Model (shared, platform-maintained)
    ├── General language capability
    ├── Legal domain understanding
    └── Foundation for all tenants
            +
Per-Tenant LoRA Adapter (trained on tenant data only)
    ├── Tenant A adapter — their data only
    ├── Tenant B adapter — their data only
    └── Tenant C adapter — their data only
            =
Tenant-Specific Agent Behaviour
    ├── Sounds like their firm
    ├── Knows their clients
    ├── Reflects their court and adversary experience
    └── Improves on their specific practice
```

What tenants own: all client documents, matter profiles, trained agent adapters, intelligence profiles, Comms Agent voice. Exportable on request, deleted on termination.

What belongs to the platform: base model weights, statute corpus, agent architecture and code.

The switching cost is not contractual. Five years of trained adapters, judicial profiles, adversary profiles, and client manager depth do not transfer to another platform. They start from zero.

---

## What This Means for the Attorney

One interface. Natural language. The hierarchy is entirely invisible.

She types or speaks what she needs. The system classifies, routes, researches, drafts, schedules, and assembles — and returns either an answer or a confirmation. Nothing is lost. Everything is documented. The complexity is the platform's problem, not hers.
