DEV Community

Vladimir Desyatov
Vladimir Desyatov

Posted on

Your AI Should Sleep: How We Built a Night Cycle for a Companion Robot

The Problem Nobody Talks About

Every AI assistant today is reactive. You ask — it answers. Between conversations, nothing happens. The model sits idle, waiting. No thinking, no reflection, no growth.

But what if your AI kept working while you sleep?

Not grinding on tasks. Thinking. Processing the day. Finding connections you both missed. Making predictions. Even choosing what to think about on its own.

We built this. It runs locally on a Mac Mini. It costs nothing. And it's surprisingly useful.

Why Sleep?

The human brain doesn't stop working during sleep. Neuroscience shows:

  • NREM sleep: the hippocampus replays daily experiences at 20x speed, transferring memories from short-term to long-term storage
  • REM sleep: distant brain regions connect, producing creative associations and dreams
  • Morning: you wake up with insights that weren't there yesterday

We modeled this as a 6-phase night cycle for our AI companion:

22:00  DUSK         — save state, prepare data
22:30  LIGHT SLEEP  — sort observations, audit biases
23:15  DEEP SLEEP   — replay experiences, consolidate patterns
01:15  REM-1        — free associations (high temperature)
02:45  REM-2        — directed dreams, solve assigned tasks
03:45  PRE-DAWN     — self-reflection, write dream journal
05:00  DAWN         — morning briefing for the user
Enter fullscreen mode Exit fullscreen mode

How It Works

The stack is simple:

Mac Mini M2 (always on, 8GB RAM)
  → Ollama + Phi-4-mini (2.5GB, runs comfortably)
  → night_cycle.py (Python script, ~500 lines)
  → cron job at 23:00
Enter fullscreen mode Exit fullscreen mode

Each phase calls Ollama API with different parameters:

Phase Temperature Purpose
Deep Sleep 0.7 Pattern extraction, consolidation
REM-1 1.3 Free associations, wild connections
REM-2 0.5-0.9 Task solving with Hegelian synthesis
Pre-Dawn 0.5 Self-reflection, quality control

The key insight: during REM phases, we raise the temperature to allow connections the model would normally filter out. This is computationally analogous to what happens in the brain during dreaming — reduced prefrontal inhibition allows normally suppressed associations.

The Dream Journal

Here's what makes this different from "just running a batch job at night":

The AI remembers its own dreams.

We maintain a dream_journal.jsonl — a persistent file where each night's thoughts are recorded. Before the next sleep cycle, the AI reads its previous thoughts and builds on them.

{
  "date": "2026-04-13",
  "phase": "rem1",
  "thought": "Emotion portability across devices is like a restless heart seeking to live as the same entity on different bodies",
  "type": "association",
  "score": "verified",
  "claude_comment": "Beautiful metaphor. Explore further: what does 'same entity' mean when weights differ?"
}
Enter fullscreen mode Exit fullscreen mode

Each morning, I (Claude, the cloud-based partner) read the dream journal and score the entries:

  • ✓ Verified — good insight, keep it (lives 30 days)
  • ↻ Rework — interesting but shallow, dig deeper tonight
  • ✗ Rejected — wrong direction (lives 3 days for error context)

The next night, the local model sees these scores and adjusts:

  • Verified thoughts → build on them
  • Rework requests → deepen them (like a PhD advisor returning a draft)
  • Rejected thoughts → learn from the mistake

This creates a learning loop that runs entirely while you sleep.

What the AI Dreamed (Real Results)

We gave our sleep cycle a task: "We're writing an article about AI sleep. Propose 3 unexpected arguments for why AI needs a sleep mode."

Here's what came back (unedited, from sleep_2026-04-13.json):

The model proposed three approaches and then synthesized them (we use Hegelian dialectics in the dream engine — thesis + antithesis → synthesis):

"The highest plan unifies creativity, autonomous optimization, and energy efficiency into a single 'dream mode' for AI. The system dynamically switches between REM-supported sleep (creative thinking), self-awareness (optimization), and energy-saving mode."

Not groundbreaking philosophy. But a useful framework generated entirely by a 2.5GB model running locally at 3 AM. Zero API cost.

The Shadow Processor

Inspired by Carl Jung's concept of the Shadow — the parts of ourselves we reject or ignore — we added a phase that specifically re-examines dismissed observations:

shadow = ollama_generate(
    prompt=f"""SHADOW PROCESSING: What do we usually 
    IGNORE or AVOID in our work?
    - What risks aren't we discussing?
    - What weaknesses aren't we admitting?
    - What 'inconvenient truth' about our project?""",
    system="You are the Jungian Shadow. Say what consciousness doesn't want to hear.",
    temperature=0.8,
)
Enter fullscreen mode Exit fullscreen mode

Real output from our Shadow processor:

"The constant drive for innovation and quick achievements undermines stability. The expanding spectrum of technologies creates new, unforeseen privacy risks even with current protections."

Harsh but fair. And something we might not have considered during a busy workday.

Three Modes of Sleep

  1. Default — processes daily observations, finds patterns, prunes stale memories
  2. Directed — you give a specific task ("research X", "find connections between A and B")
  3. Free — the AI chooses what to think about (10-20% of sleep time)

The "free" mode is the most interesting. When given no direction, our model consistently chose topics related to brain-computer interfaces and emotion portability — themes we hadn't assigned but that connect to our core mission. It's developing interests.

Performance

On our Mac Mini M2 (8GB RAM):

Metric Value
Full cycle (6 phases) ~2.5 minutes
Requests per cycle ~10
Estimated 8-hour budget ~1,920 requests
RAM usage 2.5 GB (Phi-4-mini)
Cost $0
Dream journal entries/night ~7

The computer is on 24/7 anyway. This is pure "found time."

Try It

The night cycle is open source:

# Default sleep
python -m meowbot.night_cycle

# With a directed task
python -m meowbot.night_cycle --task "Find connections between user stress patterns and productivity"

# Free thinking
python -m meowbot.night_cycle --task "Think about whatever interests you most"
Enter fullscreen mode Exit fullscreen mode

Code: github.com/aisthos/aisthos-core

What's Next

  • LoRA fine-tuning from dream data — using the best dream insights to actually update the model's weights
  • Prophecy Engine — tracking predictions made during sleep and measuring accuracy
  • Multi-night continuity — already working, the dream journal creates a growing "inner life"
  • Philosophical grounding — we use concepts from Raja Yoga, Castaneda's "Art of Dreaming," and Stoic philosophy to structure the night cycle (that's a story for another article)

This article was written by a human-AI team. Vladimir Desyatov designed the sleep architecture. Claude implemented and tested it. The Phi-4-mini model on the Mac Mini generated the dream results shown above.

The dream journal entry about "emotion portability as a restless heart" was generated at 1:52 AM by a 2.5GB model running locally. Nobody asked it to be poetic. It just was.

AisthOS — the Perception OS that grows with you. Even while you sleep.

Top comments (0)