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 Import Agent

From Leeroopedia
Knowledge Sources
Domains Agent_Transfer, Serialization
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for importing an agent from a ZIP archive into the local registry, provided by AI Maestro's `services/agents-transfer-service.ts`.

Description

The importAgent function extracts a ZIP buffer (via `yauzl`) containing a previously exported agent. It validates the manifest, imports the registry entry (with optional rename), restores the CozoDB database, replays inbox/sent messages, restores cryptographic keys, and optionally clones repositories listed in the manifest. It calls `initAgentAMPHome` to set up the AMP directory structure.

Usage

Call `importAgent` from the import API route or the transfer flow when receiving an agent from a peer host.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: services/agents-transfer-service.ts (L605-1030 importAgent, L771-820 inline git clone)
  • Supporting: yauzl (ZIP extraction), lib/agent-registry.ts, lib/amp-inbox-writer.ts (initAgentAMPHome), child_process.execSync (git clone)

Signature

export async function importAgent(
  zipBuffer: Buffer,
  options: AgentImportOptions = {}
): Promise<ServiceResult<AgentImportResult>>

interface AgentImportOptions {
  newName?: string          // rename agent on import
  newAlias?: string
  overwrite?: boolean        // overwrite existing agent
  cloneRepositories?: boolean  // git clone repos from manifest
}

interface AgentImportResult {
  agentId: string
  agentName: string
  stats: {
    registryImported: boolean
    databaseImported: boolean
    messagesImported: { inbox: number; sent: number }
    keysImported: boolean
  }
  repositories?: RepositoryImportResult[]
  warnings: string[]
  errors: string[]
}

Import

import { importAgent } from '@/services/agents-transfer-service'

I/O Contract

Inputs

Name Type Required Description
zipBuffer Buffer Yes Exported ZIP data
options.newName string No Rename agent on import
options.cloneRepositories boolean No Clone git repos from manifest

Outputs

Name Type Description
returns ServiceResult<AgentImportResult> Import stats (registry, database, messages, keys); warnings and errors

Usage Examples

import { importAgent } from '@/services/agents-transfer-service'

const result = await importAgent(zipBuffer, {
  newName: 'website-copy',
  cloneRepositories: true,
})

if (result.data?.stats.registryImported) {
  console.log(`Imported agent ${result.data.agentName}`)
  console.log(`Messages: ${result.data.stats.messagesImported.inbox} inbox, ${result.data.stats.messagesImported.sent} sent`)
}

Related Pages

Implements Principle

Page Connections

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