Skip to content

feat: Agent Thinking Clock — periodic reflection with multi-model orchestration #17287

Description

@amor71

Motivation

Agents in OpenClaw are purely reactive — they only process when receiving external stimuli: a user message, a heartbeat poll, or a cron trigger. Between these events, the agent is inert. It has no idle cognition, no background awareness, no time to think.

Humans don't work this way. We have a constant background process — noticing things, connecting dots, preparing for what's next. The best assistants anticipate needs before being asked. This proposal gives agents that capability.

The existing heartbeat mechanism is the closest analog, but it's coarse-grained (typically 15-60 min intervals), runs on the primary (expensive) model, and is designed for periodic check-ins rather than continuous ambient awareness. Cron jobs are isolated and task-specific — they can't build on conversational context.

The Thinking Clock fills the gap between reactive responses and proactive intelligence.


Design Overview

The Clock

A configurable periodic timer that fires "ticks" at regular intervals (default: 5 minutes). Each tick:

  1. Assembles a lightweight context window (recent messages, memory files, pending tasks)
  2. Sends a reflection prompt to a cheap/fast model
  3. The model either responds TICK_OK (nothing to do) or ESCALATE: <reason> to hand off to the primary model
  4. If escalated, the primary model receives the cheap model's observation + full context and can take action

This creates a two-tier attention system: peripheral awareness (cheap model) that occasionally triggers focused attention (primary model).

Tick Prompt

You have a quiet moment. Review your recent context and consider:
- Is there anything you should be preparing for?
- Any ideas worth exploring?
- Anything you noticed but haven't acted on?
- Any background work you could do right now?

If something needs the primary model's attention, respond with ESCALATE: <reason>
If nothing needs attention, respond with TICK_OK

The prompt is intentionally open-ended. The agent's personality (SOUL.md) and context shape what it notices and prioritizes.


Multi-Model Orchestration

This is the key innovation. Running 288 ticks/day on Claude Opus would cost ~$50+/day. That's untenable for most users. But the idle tick doesn't need frontier intelligence — it needs fast, cheap pattern recognition.

The Two-Tier Architecture

Tier Role Model Examples Cost/tick
Peripheral (every tick) Quick scan, pattern matching GPT-4o-mini, Gemini Flash, DeepSeek, Qwen ~$0.005-0.01
Focused (escalation only) Deep reasoning, action taking Claude Opus, GPT-4o, Claude Sonnet ~$0.10-0.50

With a 5% escalation rate (14 escalations/day), daily cost drops from $50+ to approximately $2-4/day.

Open-Source Model Support

The peripheral tier is an ideal use case for open-source models:

  • DeepSeek (DeepSeek-V3/R1) — excellent reasoning at very low cost
  • Qwen (Alibaba) — strong multilingual capabilities
  • Mistral (Mistral Large/Small) — fast, efficient
  • Llama (Meta) — can run locally for zero API cost
  • GLM-4 (Zhipu AI) — competitive on many benchmarks
  • Kimi (Moonshot AI) — strong long-context capabilities

For users with GPUs, a local model (e.g., Llama 3 8B via Ollama) could provide zero-cost ticks. The thinking clock becomes the gateway feature for local model integration in OpenClaw.

Pluggable Model Router

The thinkingClock.model config accepts any model string the gateway supports. A future enhancement could add smart routing:

thinkingClock.model: "auto"  // picks cheapest available provider
thinkingClock.model: "ollama/llama3:8b"  // local model
thinkingClock.model: "deepseek/deepseek-chat"  // specific provider

Configuration

{
  "thinkingClock": {
    "enabled": true,
    "intervalMinutes": 5,
    "model": "gpt-4o-mini",
    "escalationModel": "anthropic/claude-opus-4-6",
    "quietHours": {
      "start": "23:00",
      "end": "07:00"
    },
    "maxDailyTicks": 200,
    "maxDailyEscalations": 20,
    "context": ["memory", "recent_messages", "pending_tasks"],
    "tickPrompt": null
  }
}
Field Description Default
enabled Toggle the thinking clock false
intervalMinutes Minutes between ticks 5
model Model for peripheral ticks gpt-4o-mini
escalationModel Model for escalated thoughts Agent's primary model
quietHours Suppress ticks during these hours 23:00–07:00
maxDailyTicks Hard cap on ticks per day 200
maxDailyEscalations Hard cap on escalations per day 20
context What to include in tick context ["memory", "recent_messages"]
tickPrompt Custom reflection prompt Built-in default

Cost Analysis

Scenario Ticks/day Model Est. Daily Cost
Cheap model, no escalation 200 GPT-4o-mini ~$1.00
Cheap model + 5% escalation 200 + 10 GPT-4o-mini + Opus ~$3.50
Local model + escalation 200 + 10 Llama 3 8B + Opus ~$2.50
Primary model only (no orchestration) 200 Claude Opus ~$50+
Heartbeat status quo 24-48 Claude Opus ~$6-12

The multi-model approach makes continuous ambient awareness economically viable for the first time.


How This Differs from Heartbeats and Cron

Feature Heartbeat Cron Thinking Clock
Frequency 15-60 min Configurable 1-10 min
Model Primary Configurable Cheap + escalation
Context Full session Isolated Curated subset
Purpose Periodic check-in Scheduled tasks Ambient awareness
Cost efficiency Low (uses primary) Medium High (two-tier)
Proactive capability Limited Task-specific Open-ended
Session continuity Yes No Yes

The thinking clock is complementary to heartbeats and cron, not a replacement. Heartbeats remain useful for batch periodic checks. Cron remains ideal for precise scheduling. The thinking clock adds the missing layer: continuous low-cost ambient cognition.


Implementation Plan

Phase 1: Core Clock

  • Add thinkingClock configuration schema
  • Implement tick timer in the gateway scheduler
  • Basic tick prompt with TICK_OK / ESCALATE protocol
  • Quiet hours and daily tick cap
  • Tick counter and basic telemetry

Phase 2: Multi-Model Routing

  • Model override for tick sessions (use different model than agent default)
  • Escalation handler: pass cheap model's observation to primary model
  • Escalation rate limiting and daily cap
  • Cost tracking per tick/escalation

Phase 3: Context & Intelligence

  • Configurable context assembly (memory, messages, tasks, calendar, etc.)
  • Tick history — agent can see what it thought about in recent ticks
  • Adaptive tick interval (increase frequency when context is rich, decrease when idle)
  • Custom tick prompts per agent persona

Phase 4: Local Model Support

  • Ollama integration for zero-cost local ticks
  • model: "auto" smart routing (cheapest available)
  • Benchmark framework: ensure local models meet minimum quality for tick usefulness

The Bigger Picture

This is essentially an attention system for AI agents. The peripheral tier handles background processing — scanning, noticing, pattern matching — while the focused tier handles conscious, deliberate thought. This mirrors how biological attention works: most processing is subconscious, with only salient signals breaking through to awareness.

As models get cheaper and faster, the thinking clock becomes more powerful. Today's 5-minute interval could become 30-second intervals with local models, approaching something like continuous awareness.

This feature positions OpenClaw as the first agent framework with genuine ambient cognition — not just reactive intelligence, but proactive, self-directed thought.


Proposed by @amichay-nine30 · Discussion welcome

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions