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 Entity Graph

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

Overview

Concrete tool for querying the entity relationship graph and building memory cards about entities, provided by AI Maestro's `lib/memory/relations.ts` and `lib/memory/cards.ts`.

Description

The entityNeighbourhood function queries CozoDB for all entities related to a given entity — both outgoing and incoming relations — strongest first, excluding faded memories. It returns `NeighbourRelation[]` with the predicate, other entity name/type, and the memory that established the relation.

The aboutEntity function builds a complete memory card for one entity: finds the entity by name, queries its relations (via `entityNeighbourhood`), and fetches the memories that mention it. The result is a structured "everything known about this entity" view used by the memory cards UI.

Usage

  • Call `entityNeighbourhood` to explore the entity graph around a node.
  • Call `aboutEntity` to render a memory card for a named entity.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/memory/relations.ts (L115 entityNeighbourhood), lib/memory/cards.ts (L411 aboutEntity)

Signature

export async function entityNeighbourhood(
  agentDb: AgentDatabase,
  entityId: string,
  limit = 12
): Promise<NeighbourRelation[]>

export async function aboutEntity(
  agentDb: AgentDatabase,
  agentId: string,
  name: string,
  limit = 20
): Promise<...>

interface NeighbourRelation {
  direction: 'in' | 'out'
  predicate: string
  other: string
  other_name: string
  other_type: string
  memory_id: string
  sessions: number
}

Import

import { entityNeighbourhood } from '@/lib/memory/relations'
import { aboutEntity } from '@/lib/memory/cards'

I/O Contract

Inputs

Name Type Required Description
agentDb AgentDatabase Yes CozoDB handle
entityId string Yes (neighbourhood) Entity UUID in the graph
name string Yes (aboutEntity) Entity name to look up
limit number No Max results (default 12/20)

Outputs

Name Type Description
entityNeighbourhood() returns Promise<NeighbourRelation[]> Related entities with relationship types
aboutEntity() returns null> Entity + relations + mentioning memories; null if not found

Usage Examples

import { aboutEntity } from '@/lib/memory/cards'

// Get everything known about an entity
const card = await aboutEntity(agentDb, 'agent-uuid', 'DeployScript', 20)
if (card) {
  console.log(`Entity: ${card.entity.name}`)
  for (const rel of card.relations) {
    console.log(`  ${rel.predicate} → ${rel.other_name}`)
  }
}

Related Pages

Implements Principle

Requires Environment

Page Connections

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