Implementation:23blocks OS Ai maestro Import Agent
| 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`)
}