/** * Agent Runtime * * Manages agent lifecycle, execution, ownership, and recovery. * Agents run on the distributed fabric as durable participants. */ import type { StateFirstDB } from './db.js'; import type { AgentRef, AgentDefinition, AgentExecution } from './agent.js'; import { AgentExecutionStatus } from './agent.js'; import type { AgentObservation, ObservationTrigger } from './agent-observation.js'; import type { AgentDecision } from './agent-decision.js'; import type { AgentRegistry } from './agent-registry.js'; /** * Agent runtime context for execution */ export interface AgentRuntimeContext { /** The database instance */ db: StateFirstDB; /** The executing agent's definition */ agentDefinition: AgentDefinition; /** The current execution */ execution: AgentExecution; /** Observations made so far */ observations: AgentObservation[]; /** Decisions made so far */ decisions: AgentDecision[]; } /** * Agent runtime handler function * Called when agent needs to make decisions */ export type AgentHandler = (context: AgentRuntimeContext) => Promise; /** * Agent runtime configuration */ export interface AgentRuntimeConfig { /** Whether to persist agent state */ persistent: boolean; /** Maximum execution time in milliseconds */ executionTimeoutMs: number; /** Whether to support reactive triggers */ supportsReactiveTriggers: boolean; /** Default retry policy */ defaultRetryPolicy?: { maxAttempts: number; backoffMs: number; }; } /** * Agent execution result */ export interface AgentExecutionResult { /** The execution that completed */ execution: AgentExecution; /** Final status */ status: AgentExecutionStatus; /** Result reference if successful */ resultRef?: string; /** Error message if failed */ error?: string; } /** * Agent ownership manager for distributed execution */ export declare class AgentOwnershipManager { private ownership; private locks; /** * Claim ownership of an execution */ claim(executionId: string, peerId: string, ttlMs: number): boolean; /** * Release ownership */ release(executionId: string, peerId: string): void; /** * Get current owner */ getOwner(executionId: string): string | undefined; /** * Check if ownership is still valid */ isValid(executionId: string): boolean; /** * Renew ownership lock */ renew(executionId: string, peerId: string, ttlMs: number): boolean; } /** * Agent Runtime * * Manages agent lifecycle and execution across the distributed fabric. */ export declare class AgentRuntime { private config; private registry; private handlers; private executions; private ownership; private triggers; constructor(registry: AgentRegistry, config: AgentRuntimeConfig); /** * Register an agent handler */ registerHandler(agentName: string, handler: AgentHandler): void; /** * Create a new agent execution */ createExecution(db: StateFirstDB, agentRef: AgentRef, goal: string, inputs: string[]): Promise; /** * Start an agent execution */ start(execution: AgentExecution, peerId: string): Promise; /** * Resume an execution from durable state */ resume(execution: AgentExecution, peerId: string): Promise; /** * Transition execution to next state */ transition(execution: AgentExecution, nextStatus: AgentExecutionStatus): Promise; /** * Complete an execution */ complete(execution: AgentExecution, resultRef: string): Promise; /** * Fail an execution */ fail(execution: AgentExecution, error: string): Promise; /** * Get execution by ID */ getExecution(executionId: string): AgentExecution | undefined; /** * Get current owner of an execution */ getOwner(executionId: string): string | undefined; /** * Register observation triggers for reactive execution */ registerTriggers(agentName: string, triggers: ObservationTrigger[]): void; /** * Get triggers for an agent */ getTriggers(agentName: string): ObservationTrigger[]; } //# sourceMappingURL=agent-runtime.d.ts.map