Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Agent Maintenance

From Leeroopedia
Knowledge Sources
Domains Memory, Subconscious
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for the agent subconscious maintenance loop — indexing new conversations and polling for unread messages — provided by AI Maestro's `lib/agent.ts` (the `Agent` class).

Description

The Agent class (in `lib/agent.ts`) is the core abstraction for a running agent's subconscious. It runs on the host where the agent lives and reads its files directly.

maintainMemory (private method) calls `runIndexDelta` directly — no HTTP round-trip, no TCP connection — to index new conversation content. It tracks cumulative message counts, surfaces relevant memories to the brain inbox after new content is indexed, and writes a status file.

checkMessages (private method) polls the self API for unread inbox messages. If there are unread messages, it triggers a message check in the agent's terminal (if idle). The inbox poll runs every 5 minutes by default (`messagePollingEnabled !== false`) as a safety net when push reaches the pane but never submits.

Usage

These are private methods of the `Agent` class, called by the subconscious loop. They are not called directly from API routes. `triggerConsolidation` (in `agents-memory-service.ts`) is the API-facing wrapper for consolidation.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/agent.ts (L419-455 maintainMemory, L510-560 checkMessages)
  • Supporting: lib/index-delta.ts (runIndexDelta), lib/hosts-config.ts (getSelfApiBase)

Signature

class Agent {
  // Private — called by the subconscious loop
  private async maintainMemory(): Promise<void>

  // Private — polls for unread inbox messages
  private async checkMessages(): Promise<void>
}

Import

// Agent is instantiated internally by the subconscious service
// triggerConsolidation is the API-facing entry point:
import { triggerConsolidation } from '@/services/agents-memory-service'

I/O Contract

Inputs

Name Type Required Description
this.agentId string — Agent UUID (from Agent instance)

Outputs

Name Type Description
maintainMemory() Promise<void> Indexed delta; surfaced relevant memories; wrote status file
checkMessages() Promise<void> Triggered message check in terminal if unread messages and agent idle

Usage Examples

The `Agent` class is used internally:

// The subconscious service creates Agent instances and runs their maintenance loop
// triggerConsolidation is the API-facing wrapper:
import { triggerConsolidation } from '@/services/agents-memory-service'

const result = await triggerConsolidation('agent-uuid', { maxConversations: 10 })

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment