localgreenchain/lib/agents/types.ts
Claude 4235e17f60
Add comprehensive 10-agent autonomous system for LocalGreenChain
Agents created:
1. PlantLineageAgent - Monitors plant ancestry and lineage integrity
2. TransportTrackerAgent - Tracks transport events and carbon footprint
3. DemandForecastAgent - Predicts consumer demand and market trends
4. VerticalFarmAgent - Manages vertical farm operations and optimization
5. EnvironmentAnalysisAgent - Analyzes growing conditions and recommendations
6. MarketMatchingAgent - Connects grower supply with consumer demand
7. SustainabilityAgent - Monitors environmental impact and sustainability
8. NetworkDiscoveryAgent - Maps geographic distribution and network analysis
9. QualityAssuranceAgent - Verifies blockchain integrity and data quality
10. GrowerAdvisoryAgent - Provides personalized growing recommendations

Also includes:
- BaseAgent abstract class for common functionality
- AgentOrchestrator for centralized agent management
- Comprehensive type definitions
- Full documentation in docs/AGENTS.md
2025-11-22 21:24:40 +00:00

166 lines
3.6 KiB
TypeScript

/**
* Agent Types for LocalGreenChain
* Defines common interfaces and types for all autonomous agents
*/
export type AgentStatus = 'idle' | 'running' | 'paused' | 'error' | 'completed';
export type AgentPriority = 'low' | 'medium' | 'high' | 'critical';
export interface AgentConfig {
id: string;
name: string;
description: string;
enabled: boolean;
intervalMs: number;
priority: AgentPriority;
maxRetries: number;
timeoutMs: number;
}
export interface AgentTask {
id: string;
agentId: string;
type: string;
payload: Record<string, any>;
priority: AgentPriority;
createdAt: string;
scheduledFor?: string;
status: 'pending' | 'running' | 'completed' | 'failed';
result?: any;
error?: string;
retryCount: number;
}
export interface AgentMetrics {
agentId: string;
tasksCompleted: number;
tasksFailed: number;
averageExecutionMs: number;
lastRunAt: string | null;
lastSuccessAt: string | null;
lastErrorAt: string | null;
uptime: number;
errors: AgentError[];
}
export interface AgentError {
timestamp: string;
message: string;
taskId?: string;
stack?: string;
}
export interface AgentEvent {
id: string;
agentId: string;
eventType: 'task_started' | 'task_completed' | 'task_failed' | 'agent_started' | 'agent_stopped' | 'alert';
timestamp: string;
data: Record<string, any>;
}
export interface AgentAlert {
id: string;
agentId: string;
severity: 'info' | 'warning' | 'error' | 'critical';
title: string;
message: string;
timestamp: string;
acknowledged: boolean;
actionRequired?: string;
relatedEntityId?: string;
relatedEntityType?: string;
}
export interface BaseAgent {
config: AgentConfig;
status: AgentStatus;
metrics: AgentMetrics;
start(): Promise<void>;
stop(): Promise<void>;
pause(): void;
resume(): void;
runOnce(): Promise<AgentTask | null>;
getMetrics(): AgentMetrics;
getAlerts(): AgentAlert[];
}
// Recommendation types
export interface PlantingRecommendation {
id: string;
growerId: string;
produceType: string;
recommendedQuantity: number;
quantityUnit: string;
expectedYieldKg: number;
projectedRevenue: number;
riskLevel: 'low' | 'medium' | 'high';
explanation: string;
demandSignalIds: string[];
timestamp: string;
}
export interface EnvironmentRecommendation {
plantId: string;
category: string;
currentValue: any;
recommendedValue: any;
priority: 'low' | 'medium' | 'high';
reason: string;
expectedImpact: string;
}
export interface MarketMatch {
id: string;
supplyId: string;
demandSignalId: string;
produceType: string;
matchedQuantityKg: number;
pricePerKg: number;
deliveryDistanceKm: number;
carbonFootprintKg: number;
matchScore: number;
timestamp: string;
}
export interface SustainabilityReport {
periodStart: string;
periodEnd: string;
totalCarbonSavedKg: number;
totalFoodMilesSaved: number;
localProductionPercentage: number;
wasteReductionPercentage: number;
waterSavedLiters: number;
recommendations: string[];
}
export interface NetworkAnalysis {
totalNodes: number;
totalConnections: number;
clusters: {
centroid: { lat: number; lon: number };
nodeCount: number;
avgDistance: number;
dominantSpecies: string[];
}[];
hotspots: {
location: { lat: number; lon: number };
intensity: number;
type: 'grower' | 'consumer' | 'mixed';
}[];
recommendations: string[];
}
export interface QualityReport {
chainId: string;
isValid: boolean;
blocksVerified: number;
integrityScore: number;
issues: {
blockIndex: number;
issueType: string;
description: string;
severity: 'low' | 'medium' | 'high';
}[];
lastVerifiedAt: string;
}