UNPKG

tlnt

Version:

TLNT - HMS-Powered Multi-Agent Platform with Government Agency Analysis, Deep Research, and Enterprise-Ready Deployment. Self-optimizing multi-domain AI agent with continuous learning and enterprise-grade performance monitoring.

299 lines 12.5 kB
/** * HMS Integrated Client * * Unified client for HMS-NET and HMS-NFO integration * Provides a single interface for all HMS operations including: * - Agent orchestration via HMS-NET * - Data processing and research via HMS-NFO * - LLM capabilities through HMS APIs (no local keys needed) */ import HMSNetClient from './hmsNetClient.js'; import HMSNfoClient from './hmsNfoClient.js'; export class HMSIntegratedClient { netClient; nfoClient; config; constructor(config) { this.config = config; this.netClient = new HMSNetClient(config.hmsNet); this.nfoClient = new HMSNfoClient(config.hmsNfo); } // Health checks for both systems async healthCheck() { try { const [netHealth, nfoHealth] = await Promise.allSettled([ this.netClient.healthCheck(), this.nfoClient.healthCheck(), ]); const netStatus = netHealth.status === 'fulfilled' ? netHealth.value : { status: 'error' }; const nfoStatus = nfoHealth.status === 'fulfilled' ? nfoHealth.value : { status: 'error' }; return { hmsNet: { status: netStatus.status, available: netHealth.status === 'fulfilled', }, hmsNfo: { status: nfoStatus.status, available: nfoHealth.status === 'fulfilled', }, integrated: netHealth.status === 'fulfilled' && nfoHealth.status === 'fulfilled', }; } catch (error) { return { hmsNet: { status: 'error', available: false }, hmsNfo: { status: 'error', available: false }, integrated: false, }; } } // Enhanced chat with HMS agent orchestration and research async chat(request) { const startTime = Date.now(); try { // Create or get appropriate agent for this request const agent = await this.getOrCreateChatAgent(request.agentType || 'general'); // Prepare execution request const executionRequest = { input: { prompt: request.prompt, context: request.context, include_research: request.includeResearch, max_tokens: request.maxTokens || 4096, }, config: { research_enabled: request.includeResearch || false, }, }; // Execute agent const execution = await this.netClient.executeAgent(agent.id, executionRequest); // If research is requested, enhance response with HMS-NFO data let researchContext = undefined; if (request.includeResearch && execution.status === 'completed') { researchContext = await this.enhanceWithResearch(request.prompt, execution.result); } const processingTime = Date.now() - startTime; return { response: String(execution.result?.response || 'No response generated'), agentUsed: agent.name || 'Unknown Agent', researchContext, processingTime, confidence: Number(execution.result?.confidence || 0.8), }; } catch (error) { console.error('HMS chat error:', error); // Fallback to direct HMS-NFO demo if HMS-NET is unavailable if (request.includeResearch) { const research = await this.nfoClient.performDemoDeepResearch(request.prompt); const processingTime = Date.now() - startTime; return { response: `Based on research findings: ${research.cort_analysis.structured_insights.join('. ')}`, agentUsed: 'HMS-NFO Fallback', researchContext: research, processingTime, confidence: 0.7, }; } throw new Error(`HMS chat failed: ${error instanceof Error ? error.message : String(error)}`); } } // Government agency analysis with full HMS integration async analyzeAgency(agencyName, issueTopic, options = {}) { try { // Request analysis from HMS-NFO const analysisRequest = await this.nfoClient.analyzeGovernmentAgency(agencyName, issueTopic, { state: options.state, agencyType: options.agencyType, includeRegulations: true, includePolicyAnalysis: true, generateRecommendations: true, }); // If workflow creation is requested, create in HMS-NET let workflowId; if (options.createWorkflow) { const workflow = await this.netClient.createWorkflow({ name: `Agency Analysis: ${agencyName} - ${issueTopic}`, steps: [ { name: 'Data Collection', type: 'data_processing', config: { agency: agencyName, topic: issueTopic }, }, { name: 'Analysis', type: 'agency_analysis', config: { analysis_id: analysisRequest.request_id }, dependencies: ['Data Collection'], }, { name: 'Report Generation', type: 'documentation', config: { format: 'comprehensive' }, dependencies: ['Analysis'], }, ], }); workflowId = workflow.id; await this.netClient.startWorkflow(workflow.id); } // Get demo result for immediate response const demoAnalysis = await this.nfoClient.performDemoAgencyAnalysis(agencyName, issueTopic, options.state); return { analysis: demoAnalysis.analysis, workflowId, recommendations: demoAnalysis.analysis.recommendations, hmsComponents: demoAnalysis.hms_components, }; } catch (error) { console.error('Agency analysis error:', error); throw new Error(`Agency analysis failed: ${error instanceof Error ? error.message : String(error)}`); } } // Deep research with CoRT analysis async performDeepResearch(topic, options = {}) { try { // Create dedicated research agent if requested let agentId; if (options.createAgent) { const agent = await this.netClient.createAgent({ name: `Research Agent: ${topic}`, type: 'research', config: { research_topic: topic, depth: options.depth || 3, breadth: options.breadth || 5, }, }); agentId = agent.id; } // Request deep research from HMS-NFO const researchRequest = await this.nfoClient.performComprehensiveResearch(topic, { depth: options.depth, breadth: options.breadth, includeCoRT: true, synthesisRequired: true, }); // Get demo result for immediate response const demoResearch = await this.nfoClient.performDemoDeepResearch(topic, options.depth || 3); return { research: demoResearch, agentId, insights: demoResearch.cort_analysis.structured_insights, sources: demoResearch.cort_analysis.sources_analyzed, }; } catch (error) { console.error('Deep research error:', error); throw new Error(`Deep research failed: ${error instanceof Error ? error.message : String(error)}`); } } // Enhanced response with research context async enhanceWithResearch(prompt, baseResult) { try { // Determine if this is agency-related or general research const isAgencyRelated = /agency|government|compliance|regulation|policy/i.test(prompt); if (isAgencyRelated) { // Extract agency and topic from prompt (simplified) const agencyMatch = prompt.match(/\b(EPA|FDA|CDC|HHS|DOE|USDA|DOT)\b/i); const agency = agencyMatch ? agencyMatch[0] : 'Federal Agency'; const research = await this.nfoClient.performDemoAgencyAnalysis(agency, 'Regulatory Compliance'); return { type: 'agency_analysis', findings: research.analysis.recommendations, components: research.hms_components, confidence: research.confidence_score, }; } else { // General research enhancement const research = await this.nfoClient.performDemoDeepResearch(prompt); return { type: 'deep_research', insights: research.cort_analysis.structured_insights, sources: research.cort_analysis.sources_analyzed, confidence: research.cort_analysis.confidence_threshold, }; } } catch (error) { console.error('Research enhancement error:', error); return { type: 'error', message: 'Research enhancement unavailable', }; } } async getOrCreateChatAgent(agentType) { try { // Try to find existing agent const agents = await this.netClient.listAgents(); const existingAgent = agents.find(a => a.type === agentType && a.status === 'active'); if (existingAgent) { return existingAgent; } // Create new agent return await this.netClient.createAgent({ name: `Chat Agent (${agentType})`, type: agentType, config: { llm_provider: 'hms_integrated', max_tokens: 4096, temperature: 0.7, research_enabled: true, }, }); } catch (error) { console.error('Agent management error:', error); // Return mock agent for fallback return { id: `mock-agent-${Date.now()}`, name: 'Mock Chat Agent', type: agentType, config: {}, status: 'active', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), }; } } // Direct access to underlying clients get net() { return this.netClient; } get nfo() { return this.nfoClient; } // Convenience methods for common operations async listActiveAgents() { return this.netClient.listAgents(); } async getSystemStatus() { try { const [agents, workflows, etlStatus, health] = await Promise.allSettled([ this.netClient.listAgents(), this.netClient.listWorkflows(), this.nfoClient.getETLStatus(), this.healthCheck(), ]); return { agents: agents.status === 'fulfilled' ? agents.value.length : 0, workflows: workflows.status === 'fulfilled' ? workflows.value.length : 0, etlStatus: etlStatus.status === 'fulfilled' ? etlStatus.value : { status: 'unavailable' }, health: health.status === 'fulfilled' ? health.value : { integrated: false }, }; } catch (error) { return { agents: 0, workflows: 0, etlStatus: { status: 'error' }, health: { integrated: false }, }; } } } export default HMSIntegratedClient; //# sourceMappingURL=hmsIntegratedClient.js.map