Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
12a8f60
tools(laya): add model download script and CLI runner
WhoIsMrSentry Sep 16, 2026
46d8cfa
tools(laya): add fetch and smoke test utility for local inference
WhoIsMrSentry Sep 16, 2026
ca95ac4
tools(laya): add offline test suite for SentryBOT intent classification
WhoIsMrSentry Sep 16, 2026
b7a9534
tools(laya): add live test harness for real-time prompt evaluation
WhoIsMrSentry Sep 16, 2026
073b581
tools(laya): add action proposal benchmark and safety evaluation suite
WhoIsMrSentry Sep 16, 2026
91a8247
config(agent): add Laya model configuration and tri-layer feature tog…
WhoIsMrSentry Sep 17, 2026
346514d
feat(agent_core): introduce typed Laya action proposal contracts
WhoIsMrSentry Sep 17, 2026
614125d
test(agent_core): add unit tests for Laya action contract validation
WhoIsMrSentry Sep 17, 2026
97ca253
docs(architecture): specify Laya action contract and payload boundaries
WhoIsMrSentry Sep 17, 2026
aac3c57
docs(architecture): document Laya System 1 reflex and fast path design
WhoIsMrSentry Sep 17, 2026
e4c66b2
feat(agent_core): implement local Laya decision and inference engine
WhoIsMrSentry Sep 18, 2026
1259481
test(agent_core): add unit and regression tests for Laya decision engine
WhoIsMrSentry Sep 18, 2026
b157e44
feat(agent_core): integrate Laya engine into tri-layer coordinator
WhoIsMrSentry Sep 18, 2026
2c57f66
feat(agent_core): bind Laya context variables in runtime session state
WhoIsMrSentry Sep 18, 2026
0a8c62c
feat(agent_core): record Laya affective signals during memory sync
WhoIsMrSentry Sep 18, 2026
7a9d887
feat(agent_core): support fast-path dispatch in turn processing loop
WhoIsMrSentry Sep 19, 2026
96d7ba8
feat(agent_core): add capability validation for Laya proposed tools
WhoIsMrSentry Sep 19, 2026
6267ee3
feat(agent_core): restrict subagent invocation under fast-path execution
WhoIsMrSentry Sep 19, 2026
3730c77
feat(agent_core): add Laya fast-path router and request interceptor
WhoIsMrSentry Sep 19, 2026
e412430
test(agent_core): add end-to-end fast-path routing integration tests
WhoIsMrSentry Sep 19, 2026
6df3782
test(agent_core): verify arbiter chain precedence with Laya fast-path
WhoIsMrSentry Sep 20, 2026
c92d7a4
feat(agent_core): emit granular progress events for Laya reasoning steps
WhoIsMrSentry Sep 20, 2026
066c05b
feat(agent_core): wire speech arbiter priority with Laya urgency
WhoIsMrSentry Sep 20, 2026
d317941
config(autonomy): add reflex threshold and confidence parameters
WhoIsMrSentry Sep 20, 2026
b6ee227
config(autonomy): add Laya emotional appraisal weights
WhoIsMrSentry Sep 20, 2026
fde46c0
feat(agent_core): inject Laya reflex cycle into active sensor loop
WhoIsMrSentry Sep 21, 2026
5830bbc
test(agent_core): verify sensor loop latency budget with Laya enabled
WhoIsMrSentry Sep 21, 2026
158643b
feat(agent_core): track environment arousal and threat in world state
WhoIsMrSentry Sep 21, 2026
2b79486
test(agent_core): test environmental state updates from reflex inputs
WhoIsMrSentry Sep 21, 2026
2d0dd0f
test(agent_core): enforce expression idle boundary contract
WhoIsMrSentry Sep 21, 2026
9ba1f00
feat(autonomy): integrate spinal cord reflex with safety circuit
WhoIsMrSentry Sep 22, 2026
d8bfe04
feat(autonomy): implement System 1 reflex arbiter with confidence gating
WhoIsMrSentry Sep 22, 2026
baf8e20
feat(autonomy): incorporate Laya sentiment in affective appraisal
WhoIsMrSentry Sep 22, 2026
0066928
feat(autonomy): initialize Laya reflex coordinator in brain lifecycle
WhoIsMrSentry Sep 22, 2026
3b8a06f
feat(autonomy): populate perception context with reflex cues
WhoIsMrSentry Sep 22, 2026
fa3683c
feat(autonomy): evaluate hazard scenarios against Laya confidence
WhoIsMrSentry Sep 23, 2026
1c854e5
feat(autonomy): route high-urgency decisions through System 1 reflex
WhoIsMrSentry Sep 23, 2026
fffb1c4
test(autonomy): add unit tests for visual hazard appraisal
WhoIsMrSentry Sep 23, 2026
1c11ec7
test(autonomy): test brain decision pipeline with Laya reflex integra…
WhoIsMrSentry Sep 23, 2026
7da5474
test(autonomy): verify vision reflex trigger handling in brain service
WhoIsMrSentry Sep 23, 2026
0d7cb8d
config(vlm_bridge): add Laya vision event bus routing parameters
WhoIsMrSentry Sep 24, 2026
17b819b
feat(vlm_bridge): tag identity descriptors in visual event payload
WhoIsMrSentry Sep 24, 2026
c32d426
feat(vlm_bridge): initialize Laya vision dispatcher during bootstrap
WhoIsMrSentry Sep 24, 2026
7e2cbb6
feat(vlm_bridge): dispatch bounded visual detections to Laya bus
WhoIsMrSentry Sep 24, 2026
3cc2a43
feat(vlm_bridge): maintain visual context cache for fast reflex queries
WhoIsMrSentry Sep 24, 2026
9284225
test(vlm_bridge): verify bounded visual event propagation to Laya
WhoIsMrSentry Sep 25, 2026
45b5aa8
test(vlm_bridge): test visual importance filtering and priority cues
WhoIsMrSentry Sep 25, 2026
d5141b7
feat(gateway): wire Laya services into gateway AI bootstrap sequence
WhoIsMrSentry Sep 25, 2026
c4e5311
feat(autonomy): implement mood state transitions based on Laya affect
WhoIsMrSentry Sep 25, 2026
5eaced2
feat(autonomy): allow conversational barge-in on high-urgency reflexes
WhoIsMrSentry Sep 25, 2026
55e2d3f
feat(autonomy): modulate vocal prosody according to emotional state
WhoIsMrSentry Sep 26, 2026
652110e
feat(autonomy): incorporate user mood into companion goal selection
WhoIsMrSentry Sep 26, 2026
6b082e3
test(autonomy): add unit tests for reflex barge-in behavior
WhoIsMrSentry Sep 26, 2026
bfdf2f0
test(autonomy): verify behavior composition with active mood signals
WhoIsMrSentry Sep 26, 2026
ec87f75
test(autonomy): test companion goal selection under varying affect
WhoIsMrSentry Sep 26, 2026
a337b56
feat(autonomy): finalize behavior composer blending with mood cues
WhoIsMrSentry Sep 27, 2026
91576bd
feat(voice): support mood-aware prosody and speech synthesis
WhoIsMrSentry Sep 27, 2026
bdf057c
feat(agent_core): stream speech audio boundaries with mood tone forwa…
WhoIsMrSentry Sep 27, 2026
58c25ed
docs(laya): record completed integration phases and audit baseline
WhoIsMrSentry Sep 27, 2026
8f89711
docs(laya): publish comprehensive rollout checklist and release gates
WhoIsMrSentry Sep 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .sentrybot/AI_HUB.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Bu dosyayı oku → ilgili agent veya skill'i bul → uygula.
| Kod incele | `agents/code-reviewer.md` |
| Arduino komutu ekle | `skills/arduino-contract.md` |
| Hata ayıkla | `skills/debug-module.md` |
| Laya System 1 entegrasyonunu sürdür | `laya_integration_completed.md` → `laya_integration_todo.md` → `context/laya-action-contract.md` |

---

Expand Down
105 changes: 105 additions & 0 deletions .sentrybot/context/laya-action-contract.md

Large diffs are not rendered by default.

154 changes: 154 additions & 0 deletions .sentrybot/context/laya-system1-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# SentryBOT — Laya (System 1) Karar Motoru Entegrasyon Mimarisi

> **Doküman Durumu:** Tasarım ve Entegrasyon Haritası
> **Konsept:** İki Sistemli Yapay Zekâ Mimarisi (Dual-System AI: System 1 Refleks + System 2 Derin Zekâ)
> **Hedef:** Karar gecikmesini 1500ms'den 30ms'ye indirmek, kırılgan regex/keyword kurallarını ortadan kaldırmak ve Pi 5 üzerinde harici sunucusuz anlık refleks kazandırmak.

---

## 1. Vizyon: Neden System 1 (Laya) ve System 2 (Ollama)?

Şu anki SentryBOT mimarisinde tüm kararlar ya **kırılgan anahtar kelime eşlemelerine** (regex, string lookup) ya da **ağır ve uzaktaki bir LLM'e** (Ollama `qwen3.5:9b`) dayanmaktadır.
* **Anahtar kelimeler:** *"ışıkları yak"* çalışırken *"ortamı aydınlat"* kaçırılabilir; *"kırmızı yap"* çalışırken *"kızar"* anlaşılmayabilir.
* **Ollama (LLM):** Zengin ve akıllıdır ama tek bir "evet/hayır" veya "hangi modüle gideyim" kararı için 1.5 - 3 saniye ağ ve üretim gecikmesi yaratır.

### Çift Sistemli (Dual-System) Çözüm:

```mermaid
flowchart TD
INPUT["Kullanıcı Girdisi / Sensör Algısı"] --> S1["SYSTEM 1: Laya (322M mmBERT)<br/>⚡ ~30 ms Yerel Refleks"]

S1 -->|"Basit Komut / Refleks<br/>(Confidence > 0.85)"| DIRECT["Doğrudan Eylem / Fast-Path<br/>LED, Kafa, Duygu, Acil Durum"]
DIRECT --> ACT["Donanım / Eylem (NeoPixel, Arduino, OLED)"]

S1 -->|"Sohbet / Derin Planlama<br/>(Confidence < 0.85 veya chit_chat)"| S2["SYSTEM 2: Ollama Qwen 9B<br/>🧠 1000-2500 ms Derin Düşünce"]
S2 --> SYNTH["Persona Sentezi & Tool Calling"]
SYNTH --> ACT
```

* **System 1 (Laya):** Hızlı, içgüdüsel, tiplendirilmiş karar motoru. Non-autoregressive (tek seferde okur, metin üretmez, doğrudan `choice`, `score`, `boolean` döndürür). 30ms içinde kararı verir.
* **System 2 (Ollama):** Analitik, üretici, felsefi ve kişiliği taşıyan ana zekâ katmanı. Yalnızca gerçekten derin akıl yürütme veya serbest sohbet gerektiğinde devreye girer.

---

## 2. Modül Modül Etki Analizi: Neler Kalır, Neler Silinir, Neler Eklenir?

### 1. `modules/agent_core` (Orkestrasyon ve Yönlendirme)

* **🗑️ Neler Silinir / Hafifletilir:**
* `services/tri_layer.py`:
* `_score_keyword_matches` ve elle yazılmış token listeleri (`_LIGHT_TOKENS`, Türkçe ekler, vb.).
* `_apply_semantic_priors` içindeki 50+ satırlık statik öncelik kuralları.
* Regex tabanlı alt-ajan puanlama mantığı.
* `services/agent.py`:
* Fast-path kararındaki kaba `len(prompt) <= 140` gibi karakter/uzunluk heuristikleri.
* **✨ Neler Eklenir / Değişir:**
* `services/laya_router.py`: Laya `Router` veya `convaiinnovations/laya-multilingual` checkpoint'i kullanılarak:
* **Soru 1 (Routing):** `target_module` → `{"neopixel", "speak", "autonomy", "arduino_serial", "vlm_bridge", "general_chat"}`
* **Soru 2 (Complexity):** `is_direct_command` → `boolean` (Doğrudan donanım komutu mu yoksa diyalog mu?)
* **Soru 3 (Urgency):** `urgency` → `score` (0.0 - 1.0)
* Router süresi **250ms'den 30ms'ye** düşer.
* **🛡️ Neler Kalır (Dokunulmaz):**
* `ToolRegistry` ve tüm 27 tool (`set_lights`, `oled_face`, `move_head`, `speak` vb.).
* `SpeechArbiter`, `ActionArbiter` (kiralama/lease mekanizması).
* `_synthesize_main_persona` (SentryBOT kişiliğinin son cevabı üretmesi - System 2).

---

### 2. `modules/autonomy` (Duygu, Karar ve Otonomi Döngüsü)

* **🗑️ Neler Silinir / Hafifletilir:**
* `services/appraisal_triggers.py`:
* Hardcoded küfür/hakaret listeleri (`insult = ("aptal", "salak", "gerizekalı", ...)`).
* Hardcoded övgü listeleri (`praise = ("harikasın", "aferin", "seviyorum", ...)`).
* Hardcoded teşekkür ve sevgi listeleri (`thanks`, `petted`).
* `services/brain.py`:
* `_check_emotion_command` içindeki statik eşleşme kuralları.
* Kullanıcı niyetini yakalamaya çalışan statik if/else sentiment kontrolleri.
* **✨ Neler Eklenir / Değişir:**
* `services/laya_appraisal.py`:
* Kullanıcı cümlesini anında semantik appraisal olaylarına çevirir:
* `user_insult`, `user_rude`, `user_praise`, `user_thanks`, `petted`, `emergency`.
* Örnek: Kullanıcı *"Harika bir iş çıkardın küçük dostum"* dediğinde liste araması olmadan `user_praise (conf: 0.96)` olarak etiketlenir.
* **İhtiyaç Modeli (Needs):**
* Laya `context_appraisal`: Robotun o anki çevre/kullanıcı durumuna göre uyarılma veya dinlenme ihtiyacını milisaniyeler içinde sınıflandırır.
* **🛡️ Neler Kalır (Dokunulmaz):**
* `AffectiveAppraisal` matematik motoru ve `config/appraisal.yml` (duygu delta formülleri).
* `AutonomyBrain` Sense-Think-Act döngüsü.
* `GoalStore` ve tekil öncelikli yaşam döngüsü (`LifeLoop`).
* `ExpressionDirector` (duyguya göre LED/OLED/ses orkestrasyonu).

---

### 3. `modules/ai_provider` (Ollama & LLM)

* **🗑️ Neler Silinir:**
* Hiçbir şey silinmez!
* **✨ Neler Değişir:**
* Ollama'nın üzerinden **mikro-yönlendirme yükü kalkar**.
* Ollama artık yalnızca **gerçek düşünme gerektiren System 2 görevlerinde** (`chat`, `persona`, `creative response`, `complex reasoning`) çağrılır.
* Robotun basit komutlarda uzaktaki Ollama'ya gitme zorunluluğu ortadan kalkar; bu da gereksiz LLM çağrılarını **%60–%70 oranında azaltır**.
* **🛡️ Neler Kalır:**
* `xOllamaService.py`, `chat.py`, `clients.py` tamamen korunur.

---

### 4. `modules/interactions` (Refleks Kural Motoru)

* **🗑️ Neler Silinir / Hafifletilir:**
* Kural motorundaki aşırı karmaşık metin tabanlı olay tetikleyicileri sadeleşir.
* **✨ Neler Eklenir:**
* Laya'nın ürettiği `urgency` ve `sentiment` etiketleri doğrudan `interactions.event` olarak yayınlanır.
* Örnek: Yüksek `urgency` skoru gelirse, interactions anında NeoPixel'de kırmızı çakar refleksi tetikler.
* **🛡️ Neler Kalır:**
* Event-driven mimari, CPU sıcaklığı kuralları, donanım koruma kilitleri.

---

### 5. Donanım ve Çıktı Modülleri (`neopixel`, `visual_output`, `voice`, `arduino_serial`)

* **DURUM:** **TAMAMEN KORUNUR (SIFIR SİLİNME)**
* Bu modüller zaten eylem icra edicilerdir (actuators). Laya entegrasyonu bunların API'lerini veya donanım sürücülerini değiştirmez.
* **Tek fark:** Bu modüllere giden komutlar LLM'in 2 saniyelik düşünme gecikmesinden kurtulup **30 milisaniyelik refleks hızına** kavuşur.

---

## 3. Sistem Mimarisi ve Karar Akış Şeması

```mermaid
sequenceDiagram
autonumber
actor User as Kullanıcı
participant Voice as Speech / STT
participant S1 as Laya (System 1 Engine)
participant Core as Agent Core / Router
participant S2 as Ollama (System 2 LLM)
participant Act as Donanım (NeoPixel/Arduino/TTS)

User->>Voice: "Işıkları hemen mavi yap"
Voice->>Core: Metin: "Işıkları hemen mavi yap"
Core->>S1: predict(state, questions) [~30ms]
Note over S1: intent: neopixel<br/>action: set_color(blue)<br/>is_direct: True (0.98)<br/>urgency: 0.85

alt Doğrudan Komut (Fast-Path / S1)
S1-->>Core: Karar: Direkt Neopixel Eylemi
Core->>Act: /neopixel/color (Mavi) [~10ms]
Core->>Act: TTS: "Maviye geçiyorum." [Fast Ack]
Act-->>User: Anında Mavi Işık + Ses (Toplam: ~100ms!)
else Derin Sohbet / Bilgi Sorusu (S2)
S1-->>Core: Karar: chit_chat / complex_reasoning (is_direct: False)
Core->>S2: Ollama Chat / Persona [~1500ms]
S2-->>Core: Zengin yanıt ve kişisel diyalog
Core->>Act: TTS Cümle Akışı
Act-->>User: Doğal Diyalog Yanıtı
end
```

---

## 4. Raspberry Pi 5 Uyumluluğu ve Kaynak Tüketimi

* **Model:** `laya-multilingual` (322M parametre mmBERT-base).
* **Bellek (RAM):** Yalnızca ~650 MB RAM kaplar (Pi 5'in 8GB RAM'i içinde ihmal edilebilir bir pay).
* **CPU Gecikmesi:** Pi 5'in Cortex-A76 4 çekirdekli işlemcisinde ONNX Runtime veya PyTorch CPU backend ile tek çıkarım (single forward pass) **~45-65 milisaniye** sürmektedir.
* **Tamamen Çevrimdışı (Air-gapped):** İnternet veya harici PC gerekmez; internet kopsa bile robot temel komutları ve hisleri yerel olarak anlar.
Loading
Loading