snow-flow 2.9.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mcp.json +13 -141
- package/.mcp.json.template +11 -25
- package/README.md +18 -0
- package/claude-flow +81 -0
- package/claude-flow.bat +18 -0
- package/claude-flow.config.json +20 -0
- package/claude-flow.ps1 +24 -0
- package/dist/agents/index.d.ts +3 -10
- package/dist/agents/index.js +10 -50
- package/dist/agents/queen-agent.d.ts +0 -2
- package/dist/agents/queen-agent.js +25 -42
- package/dist/cli.js +1 -1
- package/dist/mcp/servicenow-automation-mcp.js +10 -10
- package/dist/mcp/servicenow-deployment-mcp.js +1050 -169
- package/dist/mcp/servicenow-development-assistant-mcp.js +13 -65
- package/dist/mcp/servicenow-integration-mcp.js +10 -10
- package/dist/mcp/servicenow-machine-learning-mcp.js +15 -15
- package/dist/mcp/servicenow-operations-mcp.js +23 -23
- package/dist/mcp/servicenow-platform-development-mcp.js +9 -9
- package/dist/mcp/servicenow-reporting-analytics-mcp.js +11 -11
- package/dist/mcp/servicenow-security-compliance-mcp.js +11 -11
- package/dist/mcp/servicenow-update-set-mcp.js +9 -9
- package/dist/mcp/shared/reliable-memory-manager.d.ts +78 -0
- package/dist/mcp/shared/reliable-memory-manager.js +268 -0
- package/dist/mcp/snow-flow-mcp.js +341 -87
- package/dist/queen/agent-factory.d.ts +4 -2
- package/dist/queen/agent-factory.js +72 -25
- package/dist/services/tensorflow-ml-service.d.ts +105 -0
- package/dist/services/tensorflow-ml-service.js +456 -0
- package/dist/services/widget-deployment-service.d.ts +107 -0
- package/dist/services/widget-deployment-service.js +332 -0
- package/dist/utils/file-storage-fallback.d.ts +62 -0
- package/dist/utils/file-storage-fallback.js +289 -0
- package/dist/utils/mcp-singleton-enforcer.d.ts +36 -0
- package/dist/utils/mcp-singleton-enforcer.js +201 -0
- package/dist/utils/mcp-timeout-fix.d.ts +53 -0
- package/dist/utils/mcp-timeout-fix.js +221 -0
- package/memory/agents/README.md +31 -0
- package/memory/claude-flow-data.json +1 -1
- package/memory/sessions/README.md +1 -1
- package/package.json +4 -2
- package/src/agents/README.md +192 -0
- package/src/health/README.md +161 -0
- package/src/memory/README.md +240 -0
- package/src/queen/README.md +403 -0
- package/src/schemas/deployment.schema.json +58 -0
- package/src/schemas/flow.schema.json +79 -0
- package/src/schemas/widget.schema.json +72 -0
- package/src/templates/base/application.template.json +45 -0
- package/src/templates/base/business_rule.template.json +33 -0
- package/src/templates/base/script_include.template.json +18 -0
- package/src/templates/base/table.template.json +64 -0
- package/src/templates/base/widget.template.json +25 -0
- package/src/templates/patterns/composite.incident-management.template.json +140 -0
- package/src/templates/patterns/widget.dashboard.template.json +238 -0
- package/src/templates/patterns/widget.datatable.template.json +292 -0
- package/dist/mcp/servicenow-graph-memory-mcp.js +0 -728
- package/servicenow/widgets/openai_incident_classifier/client_controller.js +0 -284
- package/servicenow/widgets/openai_incident_classifier/server_script.js +0 -314
- package/servicenow/widgets/openai_incident_classifier/style.css +0 -354
- package/servicenow/widgets/openai_incident_classifier/template.html +0 -167
- package/servicenow/widgets/openai_incident_classifier/widget.json +0 -86
- package/test-ml-improvements.sh +0 -76
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# ServiceNow Specialist Agents
|
|
2
|
+
|
|
3
|
+
This directory contains the implementation of ServiceNow specialist agents that work together through Claude Code to build, deploy, and maintain ServiceNow solutions.
|
|
4
|
+
|
|
5
|
+
## ⚠️ IMPORTANT: Flow Builder Agent Removed in v1.4.0 ⚠️
|
|
6
|
+
|
|
7
|
+
**Note**: The Flow Builder Agent and all flow-related functionality have been removed in v1.4.0 due to critical bugs. The agent file may still exist but is no longer functional. Please use ServiceNow's native Flow Designer interface directly for flow creation.
|
|
8
|
+
|
|
9
|
+
## 🤖 Available Agents
|
|
10
|
+
|
|
11
|
+
### 1. Widget Creator Agent (`widget-creator-agent.ts`)
|
|
12
|
+
Specializes in creating ServiceNow Service Portal widgets.
|
|
13
|
+
|
|
14
|
+
**Capabilities:**
|
|
15
|
+
- HTML template creation
|
|
16
|
+
- CSS styling and responsive design
|
|
17
|
+
- Client-side JavaScript development
|
|
18
|
+
- Server-side data processing
|
|
19
|
+
- Chart.js integration
|
|
20
|
+
- Demo data generation
|
|
21
|
+
|
|
22
|
+
**MCP Tools Used:**
|
|
23
|
+
- `snow_deploy` - Deploy widgets to ServiceNow
|
|
24
|
+
- `snow_preview_widget` - Preview widget rendering
|
|
25
|
+
- `snow_widget_test` - Test widget functionality
|
|
26
|
+
|
|
27
|
+
### 2. Flow Builder Agent (`flow-builder-agent.ts`)
|
|
28
|
+
Specializes in creating ServiceNow Flow Designer workflows.
|
|
29
|
+
|
|
30
|
+
**Capabilities:**
|
|
31
|
+
- Business process design
|
|
32
|
+
- Flow trigger configuration
|
|
33
|
+
- Approval workflow creation
|
|
34
|
+
- Integration flow building
|
|
35
|
+
- Error handling design
|
|
36
|
+
|
|
37
|
+
**MCP Tools Used:**
|
|
38
|
+
- `snow_create_flow` - Create flows from natural language
|
|
39
|
+
- `snow_test_flow_with_mock` - Test flows with mock data
|
|
40
|
+
- `snow_link_catalog_to_flow` - Link flows to catalog items
|
|
41
|
+
|
|
42
|
+
### 3. Script Writer Agent (`script-writer-agent.ts`)
|
|
43
|
+
Specializes in creating ServiceNow scripts.
|
|
44
|
+
|
|
45
|
+
**Capabilities:**
|
|
46
|
+
- Business rule creation
|
|
47
|
+
- Script include development
|
|
48
|
+
- Client script implementation
|
|
49
|
+
- Scheduled job scripts
|
|
50
|
+
- Performance optimization
|
|
51
|
+
|
|
52
|
+
**MCP Tools Used:**
|
|
53
|
+
- `snow_create_script_include` - Create script includes
|
|
54
|
+
- `snow_create_business_rule` - Create business rules
|
|
55
|
+
- `snow_create_client_script` - Create client scripts
|
|
56
|
+
|
|
57
|
+
### 4. Test Agent (`test-agent.ts`)
|
|
58
|
+
Specializes in testing ServiceNow artifacts.
|
|
59
|
+
|
|
60
|
+
**Capabilities:**
|
|
61
|
+
- Test scenario creation
|
|
62
|
+
- Mock data generation
|
|
63
|
+
- Integration testing
|
|
64
|
+
- Performance validation
|
|
65
|
+
- Quality assurance
|
|
66
|
+
|
|
67
|
+
**MCP Tools Used:**
|
|
68
|
+
- `snow_test_flow_with_mock` - Test flows
|
|
69
|
+
- `snow_widget_test` - Test widgets
|
|
70
|
+
- `snow_comprehensive_flow_test` - Comprehensive testing
|
|
71
|
+
- `snow_cleanup_test_artifacts` - Clean up test data
|
|
72
|
+
|
|
73
|
+
### 5. Security Agent (`security-agent.ts`)
|
|
74
|
+
Specializes in ServiceNow security and compliance.
|
|
75
|
+
|
|
76
|
+
**Capabilities:**
|
|
77
|
+
- Security policy enforcement
|
|
78
|
+
- Vulnerability scanning
|
|
79
|
+
- Access control validation
|
|
80
|
+
- Compliance checking (SOX, GDPR, HIPAA)
|
|
81
|
+
- Security best practices
|
|
82
|
+
|
|
83
|
+
**MCP Tools Used:**
|
|
84
|
+
- `snow_create_access_control` - Create ACLs
|
|
85
|
+
- `snow_security_scan` - Security scanning
|
|
86
|
+
- `snow_run_compliance_scan` - Compliance validation
|
|
87
|
+
|
|
88
|
+
## 🏗️ Architecture
|
|
89
|
+
|
|
90
|
+
### Base Agent Class (`base-agent.ts`)
|
|
91
|
+
All agents extend the `BaseAgent` class which provides:
|
|
92
|
+
- Shared memory integration via SQLite
|
|
93
|
+
- Progress reporting to Queen Agent
|
|
94
|
+
- Inter-agent communication
|
|
95
|
+
- Error handling and logging
|
|
96
|
+
- Lifecycle management
|
|
97
|
+
|
|
98
|
+
### Agent Communication Pattern
|
|
99
|
+
```typescript
|
|
100
|
+
// Agents communicate through shared memory
|
|
101
|
+
await agent.storeArtifact(artifact);
|
|
102
|
+
await agent.reportProgress('Task completed', 100);
|
|
103
|
+
await agent.sendMessage(otherAgentId, 'coordination', data);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Integration with Queen Agent
|
|
107
|
+
The Queen Agent uses `AgentFactory` to spawn these specialized agents:
|
|
108
|
+
```typescript
|
|
109
|
+
const agent = await agentFactory.createSpecializedAgent('widget-creator');
|
|
110
|
+
const result = await agent.execute(instruction, context);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 🚀 Usage Examples
|
|
114
|
+
|
|
115
|
+
### Creating a Widget
|
|
116
|
+
```typescript
|
|
117
|
+
const widgetAgent = new WidgetCreatorAgent({ debugMode: true });
|
|
118
|
+
const result = await widgetAgent.execute(
|
|
119
|
+
'Create an incident dashboard widget with real-time charts'
|
|
120
|
+
);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Building a Flow
|
|
124
|
+
```typescript
|
|
125
|
+
const flowAgent = new FlowBuilderAgent({ debugMode: true });
|
|
126
|
+
const result = await flowAgent.execute(
|
|
127
|
+
'Create an approval flow for catalog requests with manager approval'
|
|
128
|
+
);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Writing a Script
|
|
132
|
+
```typescript
|
|
133
|
+
const scriptAgent = new ScriptWriterAgent({ debugMode: true });
|
|
134
|
+
const result = await scriptAgent.execute(
|
|
135
|
+
'Create a business rule to calculate incident priority'
|
|
136
|
+
);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Testing Artifacts
|
|
140
|
+
```typescript
|
|
141
|
+
const testAgent = new TestAgent({ debugMode: true });
|
|
142
|
+
const result = await testAgent.execute(
|
|
143
|
+
'Test the incident dashboard widget with comprehensive scenarios'
|
|
144
|
+
);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Security Scanning
|
|
148
|
+
```typescript
|
|
149
|
+
const securityAgent = new SecurityAgent({ debugMode: true });
|
|
150
|
+
const result = await securityAgent.execute(
|
|
151
|
+
'Perform security scan on all recent artifacts'
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 🧪 Testing
|
|
156
|
+
|
|
157
|
+
Run the agent test suite:
|
|
158
|
+
```bash
|
|
159
|
+
npm test src/agents/test-agents.ts
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 📝 Best Practices
|
|
163
|
+
|
|
164
|
+
1. **Always use shared memory** for coordination between agents
|
|
165
|
+
2. **Report progress regularly** for long-running tasks
|
|
166
|
+
3. **Handle errors gracefully** and provide meaningful error messages
|
|
167
|
+
4. **Store artifacts** in shared memory for other agents to use
|
|
168
|
+
5. **Clean up resources** when agent tasks complete
|
|
169
|
+
|
|
170
|
+
## 🔄 Agent Lifecycle
|
|
171
|
+
|
|
172
|
+
1. **Initialization**: Agent is created with configuration
|
|
173
|
+
2. **Execution**: Agent performs its specialized task
|
|
174
|
+
3. **Coordination**: Agent communicates with other agents
|
|
175
|
+
4. **Completion**: Agent reports results and stores artifacts
|
|
176
|
+
5. **Cleanup**: Agent releases resources
|
|
177
|
+
|
|
178
|
+
## 🔗 MCP Tool Integration
|
|
179
|
+
|
|
180
|
+
Each agent knows which MCP tools to recommend for its tasks. The actual MCP tool execution happens through Claude Code, not directly by the agents. Agents provide:
|
|
181
|
+
- Tool recommendations
|
|
182
|
+
- Parameter preparation
|
|
183
|
+
- Result interpretation
|
|
184
|
+
- Error handling
|
|
185
|
+
|
|
186
|
+
## 🎯 Future Enhancements
|
|
187
|
+
|
|
188
|
+
- [ ] Add more specialized agents (Catalog Manager, Integration Specialist)
|
|
189
|
+
- [ ] Implement agent learning from past executions
|
|
190
|
+
- [ ] Add performance metrics collection
|
|
191
|
+
- [ ] Enhance inter-agent coordination protocols
|
|
192
|
+
- [ ] Add agent health monitoring
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Snow-Flow System Health Monitoring
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The System Health module provides comprehensive real-time monitoring of all Snow-Flow components, replacing placeholder metrics with actual system measurements.
|
|
6
|
+
|
|
7
|
+
## Real Metrics Implemented
|
|
8
|
+
|
|
9
|
+
### 1. **CPU Usage** (Real-time)
|
|
10
|
+
- Uses CPU time differentials for accurate usage calculation
|
|
11
|
+
- Supports multi-core systems
|
|
12
|
+
- Automatically averages across all CPU cores
|
|
13
|
+
- Updates every 100ms for initial reading
|
|
14
|
+
|
|
15
|
+
### 2. **Memory Usage** (Real-time)
|
|
16
|
+
- **System Memory**: Total and used memory from OS
|
|
17
|
+
- **Process Memory**:
|
|
18
|
+
- Heap usage (used/total)
|
|
19
|
+
- RSS (Resident Set Size)
|
|
20
|
+
- External memory
|
|
21
|
+
- Array buffers
|
|
22
|
+
- Percentage calculations for threshold monitoring
|
|
23
|
+
|
|
24
|
+
### 3. **Disk Usage** (Real-time)
|
|
25
|
+
- **Cross-platform support**:
|
|
26
|
+
- Unix/macOS: Uses `df` command
|
|
27
|
+
- Windows: Uses `wmic` command
|
|
28
|
+
- Monitors the filesystem containing the application
|
|
29
|
+
- Returns usage percentage and total size in GB
|
|
30
|
+
- Handles edge cases (long filesystem names, parsing errors)
|
|
31
|
+
|
|
32
|
+
### 4. **Network Connectivity**
|
|
33
|
+
- DNS lookup test to verify internet connectivity
|
|
34
|
+
- Used for ServiceNow API health checks
|
|
35
|
+
|
|
36
|
+
### 5. **Database Health**
|
|
37
|
+
- SQLite database size monitoring
|
|
38
|
+
- Table and index counts
|
|
39
|
+
- Integration with MemorySystem stats
|
|
40
|
+
|
|
41
|
+
### 6. **Component-Specific Monitoring**
|
|
42
|
+
- **Memory System**: Store/retrieve tests, cache hit rates
|
|
43
|
+
- **MCP Servers**: Status of all MCP server processes
|
|
44
|
+
- **ServiceNow**: API connectivity and response times
|
|
45
|
+
- **Queen System**: Active sessions and agent counts
|
|
46
|
+
- **Performance**: Operation success rates, response times
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### Basic Health Check
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { SystemHealth } from './health/system-health';
|
|
54
|
+
|
|
55
|
+
const systemHealth = new SystemHealth({
|
|
56
|
+
memory,
|
|
57
|
+
mcpManager,
|
|
58
|
+
config: {
|
|
59
|
+
checks: {
|
|
60
|
+
memory: true,
|
|
61
|
+
mcp: true,
|
|
62
|
+
servicenow: true,
|
|
63
|
+
queen: true
|
|
64
|
+
},
|
|
65
|
+
thresholds: {
|
|
66
|
+
responseTime: 1000, // 1 second
|
|
67
|
+
memoryUsage: 0.9, // 90%
|
|
68
|
+
cpuUsage: 0.8, // 80%
|
|
69
|
+
queueSize: 100,
|
|
70
|
+
errorRate: 0.1 // 10%
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await systemHealth.initialize();
|
|
76
|
+
|
|
77
|
+
// Single health check
|
|
78
|
+
const status = await systemHealth.performHealthCheck();
|
|
79
|
+
console.log('System healthy:', status.healthy);
|
|
80
|
+
console.log('CPU Usage:', status.metrics.systemResources.cpuUsage + '%');
|
|
81
|
+
console.log('Memory:', status.metrics.systemResources.memoryUsage + 'MB');
|
|
82
|
+
console.log('Disk:', status.metrics.systemResources.diskUsage + '%');
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Continuous Monitoring
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// Start monitoring every 30 seconds
|
|
89
|
+
await systemHealth.startMonitoring(30000);
|
|
90
|
+
|
|
91
|
+
// Listen for health events
|
|
92
|
+
systemHealth.on('health:check', (status) => {
|
|
93
|
+
console.log('Health update:', status);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
systemHealth.on('health:alert', (alert) => {
|
|
97
|
+
console.log('ALERT:', alert.message);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Stop monitoring
|
|
101
|
+
await systemHealth.stopMonitoring();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Testing
|
|
105
|
+
|
|
106
|
+
Run the test script to see real metrics:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
npm run build
|
|
110
|
+
npm run test:health
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Thresholds and Alerts
|
|
114
|
+
|
|
115
|
+
The system triggers alerts when:
|
|
116
|
+
- **CPU Usage** > 80% (degraded), > 90% (critical)
|
|
117
|
+
- **Memory Usage** > 80% (degraded), > 90% (critical)
|
|
118
|
+
- **Disk Usage** > 80% (degraded), > 90% (critical)
|
|
119
|
+
- **Heap Usage** > 90% (degraded)
|
|
120
|
+
- **Network Connectivity** lost (degraded)
|
|
121
|
+
- **Response Times** exceed configured thresholds
|
|
122
|
+
|
|
123
|
+
## Architecture
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
SystemHealth
|
|
127
|
+
├── CPU Monitor (real-time calculation)
|
|
128
|
+
├── Memory Monitor (system + process)
|
|
129
|
+
├── Disk Monitor (platform-specific)
|
|
130
|
+
├── Network Monitor (DNS-based)
|
|
131
|
+
├── Component Monitors
|
|
132
|
+
│ ├── Memory System
|
|
133
|
+
│ ├── MCP Servers
|
|
134
|
+
│ ├── ServiceNow API
|
|
135
|
+
│ ├── Queen System
|
|
136
|
+
│ └── Performance Metrics
|
|
137
|
+
└── Alert System
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Platform Support
|
|
141
|
+
|
|
142
|
+
- ✅ **macOS**: Full support for all metrics
|
|
143
|
+
- ✅ **Linux**: Full support for all metrics
|
|
144
|
+
- ✅ **Windows**: Full support (uses WMIC for disk stats)
|
|
145
|
+
- ⚠️ **Other platforms**: Basic support (some metrics may be unavailable)
|
|
146
|
+
|
|
147
|
+
## Performance Impact
|
|
148
|
+
|
|
149
|
+
The health monitoring system is designed to have minimal performance impact:
|
|
150
|
+
- CPU usage calculation adds < 1% overhead
|
|
151
|
+
- Disk usage checks are cached and throttled
|
|
152
|
+
- Database queries are optimized with indexes
|
|
153
|
+
- Network checks are asynchronous and non-blocking
|
|
154
|
+
|
|
155
|
+
## Future Enhancements
|
|
156
|
+
|
|
157
|
+
- Historical metric graphing
|
|
158
|
+
- Predictive failure detection
|
|
159
|
+
- Custom metric plugins
|
|
160
|
+
- Prometheus/Grafana integration
|
|
161
|
+
- Alert webhooks and notifications
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Snow-Flow Memory System
|
|
2
|
+
|
|
3
|
+
The Snow-Flow memory system provides SQLite-based persistent storage for agent coordination, artifact tracking, and performance monitoring. It's designed to meet the requirements specified in MCP_ARCHITECTURE.md with fast queries (<100ms), thread-safe operations, and automatic schema migration.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The memory system consists of three main components:
|
|
8
|
+
|
|
9
|
+
### 1. SwarmMemory (`swarm-memory.ts`)
|
|
10
|
+
- Core SQLite database management
|
|
11
|
+
- Schema creation and migration
|
|
12
|
+
- Performance optimization
|
|
13
|
+
- Thread-safe operations with WAL mode
|
|
14
|
+
|
|
15
|
+
### 2. MemoryOperations (`memory-operations.ts`)
|
|
16
|
+
- High-level operations for data storage/retrieval
|
|
17
|
+
- Agent coordination management
|
|
18
|
+
- Artifact tracking
|
|
19
|
+
- Performance monitoring
|
|
20
|
+
- Message passing between agents
|
|
21
|
+
|
|
22
|
+
### 3. MemoryClient (`memory-client.ts`)
|
|
23
|
+
- Simple API for agents
|
|
24
|
+
- Automatic session tracking
|
|
25
|
+
- Performance tracking helpers
|
|
26
|
+
- Simplified context storage
|
|
27
|
+
|
|
28
|
+
## Database Schema
|
|
29
|
+
|
|
30
|
+
The system implements all tables specified in MCP_ARCHITECTURE.md:
|
|
31
|
+
|
|
32
|
+
- **agent_coordination**: Track agent status and progress
|
|
33
|
+
- **servicenow_artifacts**: Store created artifacts
|
|
34
|
+
- **agent_messages**: Inter-agent communication
|
|
35
|
+
- **shared_context**: Session-wide shared data
|
|
36
|
+
- **deployment_history**: Track deployments
|
|
37
|
+
- **agent_dependencies**: Manage agent dependencies
|
|
38
|
+
- **performance_metrics**: Performance monitoring
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Basic Agent Usage
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { MemoryClient } from './memory/index.js';
|
|
46
|
+
|
|
47
|
+
// Create a memory client for an agent
|
|
48
|
+
const memory = MemoryClient.forAgent(
|
|
49
|
+
'widget_creator_001', // agent ID
|
|
50
|
+
'widget-creator', // agent type
|
|
51
|
+
'session_123' // session ID
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Register the agent
|
|
55
|
+
await memory.register(['create_dashboard_widget']);
|
|
56
|
+
|
|
57
|
+
// Update progress
|
|
58
|
+
await memory.updateProgress(50, 'creating_template');
|
|
59
|
+
|
|
60
|
+
// Store shared data
|
|
61
|
+
await memory.store({
|
|
62
|
+
key: 'widget_config',
|
|
63
|
+
value: {
|
|
64
|
+
name: 'incident_dashboard',
|
|
65
|
+
features: ['charts', 'filters']
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Retrieve shared data
|
|
70
|
+
const config = await memory.retrieve({ key: 'widget_config' });
|
|
71
|
+
|
|
72
|
+
// Track performance
|
|
73
|
+
const tracker = memory.trackOperation('widget_creation');
|
|
74
|
+
// ... do work ...
|
|
75
|
+
await tracker.complete(true);
|
|
76
|
+
|
|
77
|
+
// Mark as completed
|
|
78
|
+
await memory.complete();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Artifact Management
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Store artifact information
|
|
85
|
+
await memory.storeArtifact({
|
|
86
|
+
sys_id: 'widget_12345',
|
|
87
|
+
type: 'widget',
|
|
88
|
+
name: 'Incident Dashboard',
|
|
89
|
+
status: 'created',
|
|
90
|
+
metadata: { version: '1.0' }
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Update artifact status
|
|
94
|
+
await memory.updateArtifactStatus('widget_12345', 'deployed');
|
|
95
|
+
|
|
96
|
+
// Find artifacts
|
|
97
|
+
const widgets = await memory.findSessionArtifacts('widget');
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Agent Communication
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Send handoff to another agent
|
|
104
|
+
await memory.handoff({
|
|
105
|
+
to_agent: 'ui_specialist_001',
|
|
106
|
+
artifact_reference: 'widget_12345',
|
|
107
|
+
data: {
|
|
108
|
+
template_ready: true,
|
|
109
|
+
next_steps: ['add_styling', 'test_responsiveness']
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Check for incoming handoffs
|
|
114
|
+
const handoffs = await memory.checkHandoffs();
|
|
115
|
+
for (const handoff of handoffs) {
|
|
116
|
+
console.log(`Received from ${handoff.from}:`, handoff.data);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Report dependency ready
|
|
120
|
+
await memory.reportDependencyReady('test_agent_001', 'widget_12345');
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Performance Monitoring
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// Track operation performance
|
|
127
|
+
const tracker = memory.trackOperation('api_call');
|
|
128
|
+
try {
|
|
129
|
+
// ... perform operation ...
|
|
130
|
+
await tracker.complete(true, undefined, {
|
|
131
|
+
response_time: 150,
|
|
132
|
+
records_processed: 100
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
await tracker.complete(false, error.message);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Get performance statistics
|
|
139
|
+
const stats = await memory.getPerformanceStats('api_call');
|
|
140
|
+
console.log(`Average duration: ${stats.avgDuration}ms`);
|
|
141
|
+
console.log(`Success rate: ${stats.successRate * 100}%`);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Session Management
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
// Get complete session state
|
|
148
|
+
const state = await memory.getSessionState();
|
|
149
|
+
console.log('Active agents:', state.agents);
|
|
150
|
+
console.log('Created artifacts:', state.artifacts);
|
|
151
|
+
console.log('Performance summary:', state.performanceSummary);
|
|
152
|
+
|
|
153
|
+
// Clean up session when done
|
|
154
|
+
await memory.cleanup();
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Advanced Usage
|
|
158
|
+
|
|
159
|
+
### Direct Database Access
|
|
160
|
+
|
|
161
|
+
For custom queries, you can access the underlying database:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const db = memory.getDatabase();
|
|
165
|
+
const results = db.all(`
|
|
166
|
+
SELECT * FROM servicenow_artifacts
|
|
167
|
+
WHERE deployment_status = 'failed'
|
|
168
|
+
ORDER BY updated_at DESC
|
|
169
|
+
`);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Custom Operations
|
|
173
|
+
|
|
174
|
+
Access the operations layer for advanced functionality:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const ops = memory.getOperations();
|
|
178
|
+
|
|
179
|
+
// Search messages with custom criteria
|
|
180
|
+
const messages = await ops.searchMessages({
|
|
181
|
+
message_type: 'error',
|
|
182
|
+
processed: false,
|
|
183
|
+
limit: 10
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Get deployment history
|
|
187
|
+
const history = await ops.getDeploymentHistory('artifact_123');
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Performance Optimization
|
|
191
|
+
|
|
192
|
+
The memory system is optimized for performance:
|
|
193
|
+
|
|
194
|
+
1. **WAL Mode**: Enables concurrent reads
|
|
195
|
+
2. **Indexes**: Fast queries on common fields
|
|
196
|
+
3. **Prepared Statements**: Reusable query plans
|
|
197
|
+
4. **Connection Pooling**: Single shared instance
|
|
198
|
+
5. **Batch Operations**: Transaction support
|
|
199
|
+
|
|
200
|
+
## Best Practices
|
|
201
|
+
|
|
202
|
+
1. **Always register agents** before performing operations
|
|
203
|
+
2. **Use transactions** for multiple related operations
|
|
204
|
+
3. **Clean up sessions** when work is complete
|
|
205
|
+
4. **Track performance** for critical operations
|
|
206
|
+
5. **Store minimal data** in shared context
|
|
207
|
+
6. **Use appropriate expiration** for temporary data
|
|
208
|
+
7. **Handle errors gracefully** with try-catch blocks
|
|
209
|
+
|
|
210
|
+
## Testing
|
|
211
|
+
|
|
212
|
+
Run the test suite to verify functionality:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npm run test:memory
|
|
216
|
+
# or
|
|
217
|
+
node dist/memory/memory-test.js
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Monitoring
|
|
221
|
+
|
|
222
|
+
Check memory statistics:
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
const stats = memory.getStats();
|
|
226
|
+
console.log('Database statistics:', stats);
|
|
227
|
+
|
|
228
|
+
// Run cleanup for old data
|
|
229
|
+
await memory.runCleanup();
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Shutdown
|
|
233
|
+
|
|
234
|
+
Always shutdown the memory system when done:
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
MemoryClient.shutdown();
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
This ensures all connections are properly closed and data is flushed to disk.
|