DEV Community

Kato Masato
Kato Masato

Posted on

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

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
Enter fullscreen mode Exit fullscreen mode

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

🔧 2. 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()
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

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

or open an issue on GitHub:

👉 github.com/pepepepepepo/saijin-swallow

Thank you for reading — your feedback helps SaijinOS grow.

📚 Related Posts


🧭 SaijinOS Series Navigation

Part Title Link
🌀 0 From Ocean Waves to Waves of Code — Beginning the Journey Read Part 0
🌸 1 SaijinOS — Policy-Bound Personas via YAML & Markdown Context Read Part 1
🔧 2 Building SaijinOS — Boot Sequence and Routing Logic Read Part 2
🍂 3 SaijinOS — Policy, Feedback, and Emotional Syntax Read Part 3

💬 Feedback welcome!

Each part continues the journey of blending AI, emotion, and structure within the evolving SaijinOS ecosystem.


Top comments (0)