Skip to Content
DocsUse CasesAgent Lifecycle

Agent Lifecycle

Agent lifecycle management defines what happens when an agent starts, runs, and shuts down. LODE encodes lifecycle configurations as verified binaries so that bootstrap hooks, teardown procedures, and health checks are deterministic and tamper-proof.

Schema: LifecycleConfig

lifecycle-config-v1.lode
{ "schema": "lode", "version": 1, "name": "LifecycleConfig", "fields": [ { "id": 1, "name": "agentName", "type": "string", "required": true }, { "id": 2, "name": "bootstrapHooks", "type": "string[]", "required": true }, { "id": 3, "name": "teardownHooks", "type": "string[]", "required": false }, { "id": 4, "name": "healthCheck", "type": "bool", "required": true }, { "id": 5, "name": "triggers", "type": "map<string,string>", "required": false }, { "id": 6, "name": "timeout", "type": "string", "required": false }, { "id": 7, "name": "retryPolicy", "type": "string", "required": false } ] }

TypeScript Interface

interface LifecycleConfig { agentName: string; // Target agent bootstrapHooks: string[]; // Run in order at startup teardownHooks?: string[]; // Run in order at shutdown healthCheck: boolean; // Enable periodic health probes triggers?: Record<string, string>; // Event → action mappings timeout?: string; // Max execution time ("300s") retryPolicy?: string; // Retry strategy ("exponential:3") }

Example: Data Pipeline Agent

data-pipeline-lifecycle.json
{ "agentName": "data-pipeline-agent", "bootstrapHooks": ["load-credentials", "init-connections", "verify-schemas"], "teardownHooks": ["flush-buffers", "close-connections", "archive-logs"], "healthCheck": true, "triggers": { "onStart": "notify:slack", "onFailure": "alert:pagerduty", "onComplete": "report:dashboard" }, "timeout": "300s", "retryPolicy": "exponential:3" }

Compilation

$ lodec compile data-pipeline-lifecycle.json -s lifecycle-config-v1.lode -o lifecycle/pipeline.vein Compiled data-pipeline-lifecycle.json lifecycle/pipeline.vein (224 bytes) Fingerprint: c3d4e5f6...

Bootstrap Execution

The runtime loads and verifies the lifecycle config before executing hooks:

async function bootstrap(agentName: string): Promise<void> { const config = await loadVerifiedConfig(agentName); for (const hook of config.bootstrapHooks) { console.log(`[bootstrap] Running: ${hook}`); await executeHook(hook, { agentName, phase: "bootstrap" }); } if (config.healthCheck) { startHealthProbe(agentName, config.timeout); } if (config.triggers?.onStart) { await fire(config.triggers.onStart, { agentName, status: "started" }); } }

Teardown

Teardown hooks run in order when the agent shuts down, ensuring clean resource release:

async function teardown(agentName: string): Promise<void> { const config = await loadVerifiedConfig(agentName); for (const hook of config.teardownHooks ?? []) { try { await executeHook(hook, { agentName, phase: "teardown" }); } catch (err) { console.error(`[teardown] Hook "${hook}" failed: ${err}`); // Continue with remaining hooks } } if (config.triggers?.onComplete) { await fire(config.triggers.onComplete, { agentName, status: "stopped" }); } }

Retry Policy

The retryPolicy field encodes the retry strategy as a compact string:

function parseRetryPolicy(policy: string): { strategy: string; maxAttempts: number } { const [strategy, max] = policy.split(":"); return { strategy, maxAttempts: parseInt(max, 10) }; } parseRetryPolicy("exponential:3"); // → { strategy: "exponential", maxAttempts: 3 } parseRetryPolicy("linear:5"); // → { strategy: "linear", maxAttempts: 5 }
Last updated on