← Cornmill Agentics

cornOS

A cognitive agent orchestration platform built on the principle that evolution already solved intelligence — we just need to read the blueprints.

40,000+ Lines of Swift
131 Source Files
16 Tool Executors
6 Channels
4 Dream Types

Overview

What is cornOS?

cornOS is a native macOS cognitive agent platform that deploys AI assistants which genuinely learn and improve over time. Unlike conventional chatbots that reset every conversation, cornOS agents develop persistent memory, consolidate knowledge through bio-mimetic sleep cycles, and coordinate as specialised teams.

Each agent is a fully autonomous entity with its own personality, memory, expertise, communication channels, and tool access. Agents can delegate tasks to specialists, operate across email, messenger, and webhooks, and run scheduled workflows — all while building institutional knowledge that compounds over time.

The platform is LLM-agnostic, supporting Claude, OpenAI-compatible models, and local inference. It's built in Swift as a native macOS menu bar application — lightweight, always-on, and deeply integrated with the operating system.

Native macOS

Menu bar application built in Swift. Always-on, lightweight, with Keychain credential storage and AppleScript automation.

LLM-Agnostic

Each agent can use a different provider — Claude API, OpenAI-compatible endpoints, or local models. Switch without changing agent logic.

50+ Config Properties

Every agent is individually tuneable — system prompts, tool budgets, memory limits, trust policies, dream parameters, channel bindings, and more.

Architecture

How it all fits together

cornOS
├── Message Ingestion
│   ├── AIMessagePoller          // Messenger API (60s interval)
│   ├── ChannelPoller            // IMAP, webhooks (30-120s)
│   └── WebhookServer            // Inbound HTTP triggers
│
├── Agent Pool
│   ├── AIAgent                  // Per-agent config (UUID-based)
│   ├── AIAgentManager           // Lifecycle, CRUD, persistence
│   └── AgentStateManager        // Processing state, delegation chains
│
├── Cognitive Core
│   ├── ClaudeInvoker            // Prompt assembly, provider routing
│   ├── AgentMemoryManager       // Per-user + global memory
│   ├── PlanParser               // [STEP:tool:params] extraction
│   └── ToolRouter               // 16 executor adapters
│
├── Subconscious
│   ├── MelatoninTracker         // Activity accumulation
│   ├── DreamEngine              // Sleep cycle orchestration
│   └── SubconsciousEngine       // Dream execution & memory ops
│
├── Knowledge
│   ├── RAGManager               // Document intelligence
│   ├── SkillLibraryManager      // Reusable workflows
│   └── ConversationStore        // Message history
│
└── Governance
    ├── ApprovalManager          // Authorization gates
    ├── TrustPolicyEngine        // 5-tier trust model
    └── ScheduledTaskManager     // Cron-based autonomy

Message processing flow

1

Ingest

Message arrives via Messenger poll, IMAP fetch, or webhook. Sender authenticated against trust policies.

2

Contextualise

Last 20 messages fetched. Per-user + global memories injected. RAG documents surfaced if relevant.

3

Reason

LLM generates a response with optional plan steps. Plans parsed into sequential tool calls.

4

Execute

ToolRouter dispatches each step to the correct executor. Approval gates checked. Results accumulated.

5

Respond

Final reply sent back via the originating channel. Memory updated. Melatonin incremented.

The Dream Engine

Bio-mimetic memory consolidation

Just as the human brain cycles through sleep stages to consolidate learning, cornOS agents accumulate cognitive pressure and enter dream states that transform raw experience into distilled knowledge.

The melatonin system

Activity generates digital melatonin. When it crosses a threshold — and the agent has been idle for 30+ minutes with a 2-hour cooldown since the last dream — consolidation begins.

Hourly base rate +1.0
Per message processed +0.5
Per memory operation +2.0
Per tool call +0.3
High engagement (3+ plan steps) −1.0

Melatonin caps at 100.0. Rates are configurable per agent — allowing research into how different "metabolic profiles" affect learning outcomes.

Stage 1

Light Sleep

15.0 melatonin

Quick housekeeping pass. Prunes 3-5 stale or redundant memories, notes 2-3 emerging patterns as global memories.

Timeout: 90s Scope: 50 messages, 10/user
Biological parallel: NREM Stage 1-2 — the brain begins sorting the day's inputs, discarding noise, flagging what matters.
Stage 2

Deep Sleep

30.0 melatonin

Thorough consolidation. Merges duplicate entries across users, compresses verbose memories into concise form, strengthens important patterns. Targets 10-20 memory operations.

Timeout: 180s Scope: Unlimited, 5/user
Biological parallel: NREM Stage 3 — slow-wave sleep, where the hippocampus replays and transfers memories to long-term cortical storage.
Stage 3

REM Sleep

50.0 melatonin

Creative cross-user analysis. Discovers patterns spanning multiple users, generates 3-5 insight globals prefixed with "pattern_" or "insight_". Finds behavioural trends, shared interests, recurring themes.

Timeout: 180s Scope: 100 messages, 20/user
Biological parallel: REM sleep — the brain forms novel associations between unrelated memories, enabling creative insight and emotional processing.
Stage 4

Lucid Dream

40.0 melatonin

Directed task execution with custom directives. The agent is given a specific prompt to process during the dream cycle — enabling targeted reflection, strategic planning, or creative exploration.

Timeout: 180s Scope: 100 messages, 20/user
Biological parallel: Lucid dreaming — conscious awareness within the dream state, allowing directed exploration of the subconscious landscape.

Dream outputs

During dreams, the LLM generates structured memory operations that are automatically applied:

[MEMORY:SAVE_USER:userId:key:value] [MEMORY:SAVE_GLOBAL:key:value] [MEMORY:FORGET_USER:userId:key] [MEMORY:FORGET_GLOBAL:key] [DREAM:SUMMARY:one sentence summary of the dream]

Every dream is recorded with metrics — memories created, modified, pruned, and melatonin consumed — enabling longitudinal analysis of how agents' knowledge evolves.

Omnichannel Communication

One agent, every channel

cornOS agents maintain a unified identity across all communication channels, with trust-aware permissions that scale with the relationship.

Email

Live

Full IMAP inbound + SMTP/SendGrid/Mailgun outbound. MIME parsing, attachment handling, thread awareness. Configurable polling intervals (min 30s).

Messenger

Live

Real-time web chat via DCCD service. Full conversation history, 60s polling, complete tool access for authenticated users.

Webhooks

Live

Inbound HTTP triggers for system integration. Trust-level gating, async response delivery, tool parameter validation.

WhatsApp

Planned

Meta Cloud API integration. Phone-based trust, rich media support, business messaging compliance.

SMS

Planned

Twilio integration for quick-response interactions. Lightweight tool subset for mobile-first use cases.

Telegram

Planned

Bot API integration. Group and direct messaging, inline commands, rich formatting.

Five-tier trust model

Inspired by how social species develop trust through repeated interaction — from stranger to ally.

Blocked

No access. Message ignored.

Chat Only

Conversation only. No tool access.

Limited

Read-only document access via RAG.

Trusted

Full tool access enabled.

Owner

All tools + administrative privileges.

Tool Ecosystem

16 executor adapters, unlimited extensibility

Every tool is routed through a protocol-based executor system. Built-in tools cover the most common operations; the Model Context Protocol (MCP) opens the door to anything else.

Communication

  • send_email
  • send_slack
  • send_sms
  • send_whatsapp
  • send_messenger
  • send_telegram

Memory

  • memory_save / memory_save_global
  • memory_recall / memory_recall_global
  • memory_search
  • memory_list
  • memory_forget / memory_forget_global

Documents (RAG)

  • rag_search
  • rag_get_page
  • rag_list_docs
  • rag_attach_doc
  • rag_attach_pages

Filesystem

  • fs_read / fs_write / fs_list
  • fs_delete / fs_move / fs_copy
  • fs_create_dir / fs_stat

Delegation

  • ask_agent (local)
  • agent_ask (remote MCP)
  • Depth tracking (max 3)
  • Context preservation

Calendar & Scheduling

  • list_events / schedule_event
  • cancel_event / get_availability
  • schedule_create (cron tasks)

Web & Vision

  • web_search / web_fetch
  • ocr_image / pdf_to_text
  • applescript_* (macOS automation)

MCP (Extensibility)

  • JSON-RPC 2.0 protocol
  • Per-agent server configuration
  • Bearer token auth via Keychain
  • 5-min tool cache with refresh
  • Async job tracking (5s polling)
  • Unlimited external tool integration

Intelligence Layer

Memory, knowledge, and skills

Dual-Layer Memory

Every agent maintains two memory stores. User-specific memories capture per-person preferences, context, and history. Global memories hold cross-user patterns, institutional knowledge, and dream-generated insights. Both are injected into every conversation — configurable counts, default 5 each.

Document Intelligence (RAG)

Per-agent document collections with three search modes: local TF-IDF (no API required), OpenAI embeddings (1536-dim semantic search), or local embeddings via Ollama. Supports PDF, DOCX, HTML, TXT, and images. Automatic chunking with page-number tracking.

Skill Library

Reusable workflow recipes with names, summaries, and detailed instructions. Skills can include plan templates for deterministic execution. A global library is shared across agents; each agent can also define custom skills. Invoked via the use_skill tool.

Workspace Collaboration

Multi-agent teams with role-based access. Shared file storage with traversal prevention, shared memory pools, and desk instructions (SOPs injected into prompts). Workspace-level MCP servers grant role-gated tool access.

Approval & Governance

Condition-based approval gates: match by tool name, prefix, parameter thresholds, new contacts, or unconditionally. Configurable urgency (blocking/standard/informational), timeout actions (auto-reject/approve/skip), and multi-target notifications.

Observability

Per-agent, per-category structured logging — dreams, inbound/outbound channels, errors, usage. Token counting and cost tracking per provider. Dream records with memory operation metrics. Status bar indicators for processing state and delegation chains.

Execution Model

Plan-based reasoning

cornOS agents don't just generate text — they generate executable plans.

When an agent needs to take action, it produces structured plans that are parsed and executed sequentially. Each step is a tool call with typed parameters, routed through the approval system before execution.

Example: Agent processes a research request
[PLAN:START] [STEP:1:TOOL:web_search:query=latest developments in bio-mimetic AI] [STEP:2:TOOL:rag_search:query=our previous research on neural consolidation] [STEP:3:TOOL:memory_recall:key=user_research_interests] [STEP:4:TOOL:send_email:to=researcher@lab.org|subject=Summary|body=...] [STEP:5:TOOL:memory_save:key=last_research_brief|value=bio-mimetic AI update sent] [PLAN:END]

Sequential execution

Steps run in order. Each step's output is available to subsequent steps. Failed steps can halt or skip based on configuration.

Tool budget

Configurable max tool calls per message (default 5). Prevents runaway execution while allowing complex multi-step workflows.

Approval gates

Sensitive operations pause for human approval. Rules match on tool name, parameter values, or contact novelty.

Technology

Built with

Swift 5

Primary language. Type-safe, performant, native.

SwiftUI + AppKit

Modern UI framework with native macOS integration.

URLSession

Networking layer with custom timeout management.

NWConnection

Low-level socket connections for IMAP/SMTP.

Keychain Services

Secure credential storage for all API keys and tokens.

PDFKit + Vision

Document text extraction and image OCR.

JSON-RPC 2.0

MCP protocol for unlimited tool extensibility.

Codable

JSON persistence for agents, memories, dreams, and configs.

Want to know more about cornOS?

Whether you're interested in the platform for research, business automation, or just want to geek out about bio-mimetic AI — let's talk.