UNPKG

anon-identity

Version:

Decentralized identity framework with DIDs, Verifiable Credentials, and privacy-preserving selective disclosure

153 lines 4.67 kB
/** * Agent-LLM Communication Manager * * Manages all LLM interactions for agents with security, context management, and routing */ import { EventEmitter } from 'events'; import { LLMResponse, FunctionDefinition, FunctionCall, RequestPriority } from '../types'; import { MCPClient } from '../client'; import { AuthManager } from '../security/auth-manager'; import { AuditLogger } from '../security/audit-logger'; import { RateLimiterManager } from '../security/rate-limiter'; import { DelegationManager } from '../../agent/delegation-manager'; import { DelegationPolicyEngine } from '../../agent/delegation-policy-engine'; /** * Agent context for LLM interactions */ export interface AgentLLMContext { agentDID: string; agentName: string; agentDescription?: string; parentDID?: string; scopes: string[]; delegationDepth: number; maxDelegationDepth: number; activeServices: string[]; metadata?: Record<string, any>; } /** * LLM interaction options */ export interface LLMInteractionOptions { priority?: RequestPriority; timeout?: number; maxRetries?: number; includeContext?: boolean; providerId?: string; temperature?: number; maxTokens?: number; systemPrompt?: string; } /** * Delegation decision result */ export interface DelegationDecision { decision: 'approve' | 'deny' | 'request_more_info'; reason: string; suggestedScopes?: string[]; suggestedConstraints?: any; confidence: number; warnings?: string[]; } /** * Policy interpretation result */ export interface PolicyInterpretation { summary: string; requirements: string[]; restrictions: string[]; recommendations: string[]; riskLevel: 'low' | 'medium' | 'high'; } /** * Agent LLM Manager */ export declare class AgentLLMManager extends EventEmitter { private mcpClient; private authManager; private auditLogger; private rateLimiter; private delegationManager?; private policyEngine?; private llmInterface; private sessionMap; private contextCache; private functionHandlers; constructor(mcpClient: MCPClient, authManager: AuthManager, auditLogger: AuditLogger, rateLimiter: RateLimiterManager, delegationManager?: DelegationManager | undefined, policyEngine?: DelegationPolicyEngine | undefined); /** * Process natural language request from agent */ processNaturalLanguageRequest(agentDID: string, request: string, options?: LLMInteractionOptions): Promise<LLMResponse>; /** * Process delegation decision request */ processDelegationDecision(parentAgentDID: string, delegationRequest: { targetAgentDID: string; requestedScopes: string[]; purpose: string; duration?: number; constraints?: any; }, options?: LLMInteractionOptions): Promise<DelegationDecision>; /** * Interpret policy using LLM */ interpretPolicy(agentDID: string, policy: any, context: string, options?: LLMInteractionOptions): Promise<PolicyInterpretation>; /** * Get scope recommendations based on request */ getScopeRecommendations(agentDID: string, purpose: string, currentScopes: string[], availableScopes: string[], options?: LLMInteractionOptions): Promise<{ recommendedScopes: string[]; reasoning: string; alternatives?: string[][]; }>; /** * Register function handler for LLM function calls */ registerFunctionHandler(name: string, handler: (args: any) => Promise<any>, definition: FunctionDefinition): void; /** * Execute function call from LLM */ executeFunctionCall(functionCall: FunctionCall): Promise<any>; /** * Get or create agent context */ private getAgentContext; /** * Build context-aware prompt */ private buildContextAwarePrompt; /** * Build delegation analysis prompt */ private buildDelegationPrompt; /** * Parse unstructured policy interpretation */ private parseUnstructuredPolicyInterpretation; /** * Get or create session for agent */ private getOrCreateSession; /** * Initialize default function handlers */ private initializeDefaultFunctions; /** * Setup event handlers */ private setupEventHandlers; /** * Clear agent session */ clearAgentSession(agentDID: string): void; /** * Get usage statistics for agent */ getAgentUsageStats(agentDID: string): Promise<any>; /** * Shutdown manager */ shutdown(): void; } export default AgentLLMManager; //# sourceMappingURL=agent-llm-manager.d.ts.map