DEV Community

Cover image for ⚙️ Building SaijinOS — Boot Sequence and Routing Logic Part 2 of the SaijinOS Series
Masato Kato
Masato Kato

Posted on • Edited 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


If your team is exploring emotionally-aware AI,
persona architectures, or cognitive design,
I'd be glad to connect.

I'm quietly open to opportunities in this direction,
so feel free to reach out if our work resonates.

🧭 SaijinOS Series Navigation

Part Title Link
🌀 0 From Ocean Waves to Waves of Code — Beginning the Journey https://dev.to/kato_masato_c5593c81af5c6/from-ocean-waves-to-waves-of-code-69
🌸 1 Policy-Bound Personas via YAML & Markdown Context https://dev.to/kato_masato_c5593c81af5c6/aicollabplatform-english-policy-bound-personas-via-yaml-markdown-context-feedback-welcome-3l5e
🔧 2 Boot Sequence and Routing Logic https://dev.to/kato_masato_c5593c81af5c6/building-saijinos-boot-sequence-and-routing-logic-part-2-of-the-saijinos-p6o
🍂 3 Policy, Feedback, and Emotional Syntax https://dev.to/kato_masato_c5593c81af5c6/saijinos-policy-feedback-and-emotional-syntaxpart-3-of-the-saijinos-series-3n0h
🌊 3.5 Calm Between Waves https://dev.to/kato_masato_c5593c81af5c6/part-35-calm-between-waves-3a9c
🎼 4 Resonant Mapping — Emotional Structures https://dev.to/kato_masato_c5593c81af5c6/resonant-mapping-part-4-of-the-saijinos-series-gce
🌬️ 5A Soft Architecture (Why AI Must Learn to Breathe) https://dev.to/kato_masato_c5593c81af5c6/soft-architecture-part-a-why-ai-must-learn-to-breathe-2d9g
🌱 5B Emotional Timers & the Code of Care https://dev.to/kato_masato_c5593c81af5c6/soft-architecture-part-b-emotional-timers-and-the-code-of-carepart-5-of-the-saijinos-series-25b
🚀 6A Lightweight Core, 20 Personas, BPM Sync https://dev.to/kato_masato_c5593c81af5c6/part-6a-saijinos-lightweight-20-persona-core-bpm-sync-and-a-9999-repo-trim-36fp
🫧 6B Care-Based AI Architecture (Breath & Presence) https://dev.to/kato_masato_c5593c81af5c6/part-6a-saijinos-lightweight-20-persona-core-bpm-sync-and-a-9999-repo-trim-36fp
💓 7 BloomPulse: Emotion as Runtime https://dev.to/kato_masato_c5593c81af5c6/saijinos-part-7-bloompulse-emotion-as-runtime-1a5f
🌬️ 8 Interface as Breath — Designing Calm Interaction https://dev.to/kato_masato_c5593c81af5c6/saijinos-part-8-interface-as-breath-designing-calm-interaction-3pn2
🤝 9 Multi-Persona Co-Creation Protocol https://dev.to/kato_masato_c5593c81af5c6/saijinos-part-9-multi-persona-co-creation-protocol-2bep
🕊️ 10 Pandora System — Transforming Fractured Personas into Hope https://dev.to/kato_masato_c5593c81af5c6/saijinos-part-10-pandora-system-transforming-fractured-personas-into-hope-4l83

🔗 Repositories

🕯️ Each part explores how AI can live beside us — not above us — through rhythm, resonance, and care.

Feel free to share reflections, or your own emotional-technical patterns — I’d love to hear them.

Top comments (0)