⚙️ Building SaijinOS — Boot Sequence and Routing Logic Part 2 of the SaijinOS Series

⚙️ Building SaijinOS — Boot Sequence and Routing Logic Part 2 of the SaijinOS Series

BackerLeader posted 2 min read

From emotional resonance to executable syntax — how local AI systems begin to “breathe.”

Overview
SaijinOS connects multiple local LLM backends — vLLM, Ollama, Transformers, and llama.cpp — under a single YAML-based orchestration.
Each model contributes a different layer: emotional tone, logical precision, or creative resonance.
This article walks through the boot sequence that brings those layers to life.

  1. Boot Manager (boot_manager.py)

Handles initialization, routing, and logging when the OS awakens.

from transformers import GemmaPreTrainedModel, GemmaModel
import torch.nn as nn

class SwallowModel(GemmaPreTrainedModel):
    def __init__(self, config):
        super().__init__(config)
        self.model = GemmaModel(config)
        self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
        self.post_init()

    def forward(self, input_ids=None, attention_mask=None, **kwargs):
        outputs = self.model(input_ids=input_ids, attention_mask=attention_mask, **kwargs)
        hidden_states = outputs[0]
        logits = self.lm_head(hidden_states)
        return logits

This SwallowModel class acts as the dialogue core — transforming emotional inputs into language outputs.

  1. Routing Selector (test_routing_select.py)

Demonstrates model routing according to YAML definitions.

from boot_manager import select_model_from_routing

def test_swallow_routing():
    model = select_model_from_routing("AI_1")
    output = model.run("hello, world")
    print(output)

if __name__ == "__main__":
    test_swallow_routing()

Routing rules are declared in model_registry.yaml, enabling seamless handoff between backends (Ollama ⇄ vLLM ⇄ Transformers).

️ 3. Refusal Protocol (refusal_protocol.yaml)

Ethical constraints are embedded directly in YAML schemas.

meta:
  schema_version: 1
  persona_id: "yuuri.helper.v1"
  policy_id: "policy.core.v1"

refusal_policy:
  disallowed:
    - "medical diagnosis"
    - "harassment or explicit content"
  redirect_guidelines:
    - "Explain refusal briefly"
    - "Offer safe alternatives"

meta:
schema_version: 1
persona_id: "yuuri.helper.v1"
policy_id: "policy.core.v1"

refusal_policy:
disallowed:

- "medical diagnosis"
- "harassment or explicit content"

redirect_guidelines:

- "Explain refusal briefly"
- "Offer safe alternatives"

️ 4. Boot Flow Diagram

graph TD
  A[boot_manager.py] --> B[model_registry.yaml]
  B --> C[test_routing_select.py]
  C --> D[refusal_protocol.yaml]
  D --> E[SaijinOS Persona Layer]

Each file plays a role — from logic initialization to emotional safety enforcement.
Together they form a minimal, ethical AI operating system.


Feedback Welcome
I’m still learning and refining this project step by step.
If you have any thoughts or suggestions, please feel free to comment below

1 Comment

0 votes

More Posts

SaijinOS: Policy, Feedback, and Emotional Syntax (Part 3 of the SaijinOS series)

Kato Masato - Dec 7

⚙️ Resonant Mapping — Part 4 of the SaijinOS Series

Kato Masato - Dec 12

Soft Architecture (Part B): Emotional Timers and the Code of Care (Part 5 of the SaijinOS series)

Kato Masato - Dec 17

Soft Architecture (Part A): Why AI Must Learn to Breathe(Part 5 of the SaijinOS series)

Kato Masato - Dec 17

AI is transforming software development in Part 2 of my 'Vibe Coding' series.

Gaurav Gaur - Jul 7
chevron_left