How to wire the Thinking Agents system into OpenClaw, step by step.
OpenClaw's cron system runs isolated agent sessions on a schedule. The cleanest approach:
One cron job fires every 5 minutes β runs an orchestrator agent β orchestrator spawns 4 sub-agents in parallel β waits β runs aggregation β optionally escalates.
Why not 4 separate cron jobs?
- No way to synchronize them (aggregator needs all 4 to finish first)
- Shared state writes would race condition
- One orchestrator keeps the pipeline clean
# Get free API key from https://open.bigmodel.cn
openclaw env set ZAI_API_KEY=<key>The orchestrator is itself an agent session (can be the cron job's agent). It:
- Reads
subconscious.json - Assembles 4 prompts from templates
- Spawns 4 sub-agents (parallel)
- Collects results
- Runs aggregation
- Writes updated
subconscious.json - Handles escalation if needed
openclaw cron add \
--name "thinking-tick" \
--schedule "*/5 * * * *" \
--model "zai/glm-4.7-flash" \
--isolated \
--prompt "You are the Thinking Clock orchestrator. Read /home/rye/.openclaw/workspace/thinking-agents/ORCHESTRATOR.md and execute one thinking tick."This is the master prompt for the cron job agent. It instructs the agent to:
# Thinking Clock β Orchestrator
## On each tick:
1. Read `thinking-agents/subconscious.json`
2. Read all 4 prompt templates from `thinking-agents/prompts/`
3. For each thread (watcher, librarian, oracle, dreamer):
a. Replace {{SUBCONSCIOUS}} with current state
b. Replace {{THREAD_HISTORY}} with thread_state[name].last_findings
c. Replace {{FOCUS_HINT}} with thread_state[name].focus_hint or "No specific focus"
d. Replace {{NOVELTY_PRESSURE}} with thread_state[name].novelty_pressure
e. Spawn a sub-agent with that prompt + appropriate tool access
4. Wait for all 4 to complete
5. Read aggregator prompt, feed it (subconscious + 4 outputs)
6. Run aggregation (can be done inline, no sub-agent needed)
7. Write updated subconscious.json
8. If ESCALATE: send message to main session with context| Thread | Tools Needed |
|---|---|
| Watcher | exec (himalaya, df, uptime), read (workspace files), web_fetch |
| Librarian | read (memory files, workspace) |
| Oracle | read (memory, calendar), web_search |
| Dreamer | read (workspace), web_search |
| Aggregator | read/write (subconscious.json only) |
The orchestrator agent uses OpenClaw's sub-agent capability. In the cron session:
# Spawn all 4 as sub-agents (they run in parallel)
# Each sub-agent gets:
# - Its assembled prompt as the task
# - Model: zai/glm-4.7-flash
# - Relevant tool access
# - Label for identification
Since sub-agents report back to the spawning agent, the orchestrator naturally collects all results before proceeding.
Alternative if sub-agents aren't available: Run 4 sequential calls to the model via tool use. Slower (4x serial) but simpler. At ~2-3 seconds per call on GLM-4.7-Flash, total tick time would be ~15 seconds. Acceptable.
If parallel sub-agents prove complex to implement initially:
- Run Watcher β get output
- Run Librarian β get output
- Run Oracle β get output
- Run Dreamer β get output
- Run Aggregator with all 4 outputs Total: ~15-20 seconds per tick. Fine for a 5-minute cycle.
The orchestrator reads the aggregator prompt and executes it directly (or as one more model call). The aggregator:
- Receives: current subconscious + 4 thread outputs (as JSON)
- Returns: updated subconscious (as JSON)
- Orchestrator writes the result to
subconscious.json
If aggregator returns {"ESCALATE": true, ...}:
- Orchestrator sends a message to the main agent session (or directly to the user's channel)
- Includes compiled context from the escalation
- Logs in escalation_history
Before enabling the cron, run manually:
# Trigger one tick manually
openclaw cron trigger thinking-tickVerify:
- subconscious.json updates correctly
- Thread outputs are valid JSON
- Decay works (run 3 ticks, watch entries fade)
- Reinforcement works (create conditions where the same thing is noticed twice)
- Novelty pressure increases for empty threads
- Focus hints rotate between threads
openclaw cron enable thinking-tick- Watch subconscious.json evolve over a few hours
- Check cron logs for errors
- Verify token usage stays within free tier
- Ensure ticks complete within ~30 seconds
- If subconscious empties too fast: reduce decay to -1 every 2 ticks
- If it fills with noise: increase decay or raise importance threshold from 3 to 4
- If threads plateau: increase pressure increment
- If threads hallucinate: cap pressure lower (5 instead of 10)
- Track false escalations in escalation_history
- Adjust thread prompts to be more/less conservative
- If the Dreamer produces low-quality ideas: try Qwen-Turbo ($0.0001/tick)
- If the Watcher misses things: try DeepSeek V3 ($0.0004/tick)
- Keep Librarian and Oracle on free tier (pattern matching and calendar scanning are simpler tasks)
| Component | Calls/Day | Model | Daily Cost |
|---|---|---|---|
| 4 Threads Γ 288 ticks | 1,152 | GLM-4.7-Flash | $0.00 |
| Aggregator Γ 288 ticks | 288 | GLM-4.7-Flash | $0.00 |
| Escalations | ~2-5 | Claude Opus | ~$0.10-$0.25 |
| Total | ~$0.10-$0.25/day |
thinking-agents/
βββ MANIFESTO.md # Philosophy
βββ MODEL-RESEARCH.md # Model options & pricing
βββ ARCHITECTURE.md # System design
βββ IMPLEMENTATION.md # This file
βββ ORCHESTRATOR.md # Master prompt for cron job (to be written)
βββ subconscious.json # Shared state (live, mutated each tick)
βββ prompts/
βββ watcher.md # Thread 1 template
βββ librarian.md # Thread 2 template
βββ oracle.md # Thread 3 template
βββ dreamer.md # Thread 4 template
βββ aggregator.md # Aggregation logic
- Visualization: Build a simple dashboard showing subconscious state over time
- Thread specialization: Let threads develop expertise based on what they keep finding
- User feedback loop: When user acknowledges an escalation as useful, boost the pattern that triggered it
- Multi-agent: Let other agents (Chai, Nori) contribute to the subconscious
- Publish: Write up the architecture as a blog post / paper for the OpenClaw community
- Can OpenClaw cron jobs spawn sub-agents? If yes: parallel. If no: sequential fallback (still works).
- Should the Watcher have actual tool access in cron? Need to test if isolated cron sessions can run himalaya, check system health, etc.
- 5-minute interval β too frequent? Start with 5 min, can relax to 10-15 if the subconscious evolves too slowly to justify the frequency.
- Should escalation go to the user or to the main agent session? Probably main agent session first, let it decide whether to bother the user.