@gotza02/seq-thinking 1.1.22 → 1.1.24
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/README.md +234 -89
- package/SYSTEM_INSTRUCTIONS.md +35 -35
- package/dist/__tests__/agents/base-agent.js +215 -0
- package/dist/__tests__/agents/specialist-agent.js +75 -0
- package/dist/__tests__/specialist-agent.test.js +653 -30
- package/dist/__tests__/types/index.js +278 -0
- package/dist/__tests__/utils/llm-adapter.js +93 -0
- package/dist/__tests__/utils/logger.js +48 -0
- package/dist/constants.d.ts +69 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +96 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.js +1 -1
- package/dist/utils/llm-adapter.d.ts +4 -4
- package/dist/utils/llm-adapter.d.ts.map +1 -1
- package/dist/utils/llm-adapter.js +25 -23
- package/dist/utils/llm-adapter.js.map +1 -1
- package/dist/utils/persistence.d.ts +17 -0
- package/dist/utils/persistence.d.ts.map +1 -1
- package/dist/utils/persistence.js +60 -5
- package/dist/utils/persistence.js.map +1 -1
- package/dist/validation/index.d.ts +6 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +6 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/schemas.d.ts +793 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +340 -0
- package/dist/validation/schemas.js.map +1 -0
- package/dist/validation/schemas.test.d.ts +6 -0
- package/dist/validation/schemas.test.d.ts.map +1 -0
- package/dist/validation/schemas.test.js +171 -0
- package/dist/validation/schemas.test.js.map +1 -0
- package/package.json +7 -6
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Agent Class
|
|
3
|
+
* @module agents/base-agent
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { AgentType, AgentStatus } from '../types/index.js';
|
|
7
|
+
import { Logger } from '../utils/logger.js';
|
|
8
|
+
/**
|
|
9
|
+
* Abstract base class for all agents
|
|
10
|
+
*/
|
|
11
|
+
export class BaseAgent {
|
|
12
|
+
/** Agent ID */
|
|
13
|
+
id;
|
|
14
|
+
/** Agent configuration */
|
|
15
|
+
config;
|
|
16
|
+
/** Current status */
|
|
17
|
+
status = AgentStatus.IDLE;
|
|
18
|
+
/** Current task IDs */
|
|
19
|
+
currentTasks = new Set();
|
|
20
|
+
/** Performance history */
|
|
21
|
+
performanceHistory = [];
|
|
22
|
+
/** Message handlers */
|
|
23
|
+
messageHandlers = [];
|
|
24
|
+
/**
|
|
25
|
+
* Create a new base agent
|
|
26
|
+
* @param config - Agent configuration
|
|
27
|
+
*/
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.id = config.id || `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
30
|
+
this.config = {
|
|
31
|
+
id: this.id,
|
|
32
|
+
name: config.name,
|
|
33
|
+
type: config.type || AgentType.UTILITY,
|
|
34
|
+
subtype: config.subtype,
|
|
35
|
+
capabilities: config.capabilities || [],
|
|
36
|
+
maxConcurrentTasks: config.maxConcurrentTasks || 3,
|
|
37
|
+
confidenceThreshold: config.confidenceThreshold || 0.7,
|
|
38
|
+
metadata: {
|
|
39
|
+
createdAt: new Date(),
|
|
40
|
+
version: '1.0.0',
|
|
41
|
+
config: config.metadata?.config || {}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute a task
|
|
47
|
+
* @param task - Task to execute
|
|
48
|
+
* @returns Task result
|
|
49
|
+
*/
|
|
50
|
+
async execute(task) {
|
|
51
|
+
const startTime = Date.now();
|
|
52
|
+
this.status = AgentStatus.BUSY;
|
|
53
|
+
this.currentTasks.add(task.id);
|
|
54
|
+
try {
|
|
55
|
+
const result = await this.process(task);
|
|
56
|
+
const processingTime = Date.now() - startTime;
|
|
57
|
+
this.performanceHistory.push({
|
|
58
|
+
taskId: task.id,
|
|
59
|
+
quality: result.confidence,
|
|
60
|
+
timeMs: processingTime,
|
|
61
|
+
timestamp: new Date()
|
|
62
|
+
});
|
|
63
|
+
this.currentTasks.delete(task.id);
|
|
64
|
+
this.status = this.currentTasks.size === 0 ? AgentStatus.IDLE : AgentStatus.BUSY;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.currentTasks.delete(task.id);
|
|
69
|
+
this.status = this.currentTasks.size === 0 ? AgentStatus.IDLE : AgentStatus.BUSY;
|
|
70
|
+
return {
|
|
71
|
+
taskId: task.id,
|
|
72
|
+
agentId: this.id,
|
|
73
|
+
success: false,
|
|
74
|
+
output: null,
|
|
75
|
+
confidence: 0,
|
|
76
|
+
processingTimeMs: Date.now() - startTime,
|
|
77
|
+
metadata: {
|
|
78
|
+
tokensUsed: 0,
|
|
79
|
+
reasoningSteps: 0,
|
|
80
|
+
intermediateResults: [],
|
|
81
|
+
error: error instanceof Error ? error.message : String(error)
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Register a message handler
|
|
88
|
+
* @param handler - Message handler function
|
|
89
|
+
* @returns Unsubscribe function
|
|
90
|
+
*/
|
|
91
|
+
onMessage(handler) {
|
|
92
|
+
this.messageHandlers.push(handler);
|
|
93
|
+
return () => {
|
|
94
|
+
const index = this.messageHandlers.indexOf(handler);
|
|
95
|
+
if (index > -1) {
|
|
96
|
+
this.messageHandlers.splice(index, 1);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Receive a message
|
|
102
|
+
* @param message - Message to receive
|
|
103
|
+
*/
|
|
104
|
+
receiveMessage(message) {
|
|
105
|
+
for (const handler of this.messageHandlers) {
|
|
106
|
+
try {
|
|
107
|
+
const result = handler(message);
|
|
108
|
+
if (result instanceof Promise) {
|
|
109
|
+
result.catch(error => {
|
|
110
|
+
Logger.error(`Error in message handler for agent ${this.id}`, { error });
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
Logger.error(`Error in message handler for agent ${this.id}`, { error });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get agent status
|
|
121
|
+
* @returns Current status
|
|
122
|
+
*/
|
|
123
|
+
getStatus() {
|
|
124
|
+
return this.status;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Set agent status
|
|
128
|
+
* @param status - New status
|
|
129
|
+
*/
|
|
130
|
+
setStatus(status) {
|
|
131
|
+
this.status = status;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get current task IDs
|
|
135
|
+
* @returns Array of task IDs
|
|
136
|
+
*/
|
|
137
|
+
getCurrentTasks() {
|
|
138
|
+
return Array.from(this.currentTasks);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get performance metrics
|
|
142
|
+
* @returns Performance metrics
|
|
143
|
+
*/
|
|
144
|
+
getPerformanceMetrics() {
|
|
145
|
+
if (this.performanceHistory.length === 0) {
|
|
146
|
+
return {
|
|
147
|
+
tasksCompleted: 0,
|
|
148
|
+
averageQuality: 0,
|
|
149
|
+
averageTimeMs: 0,
|
|
150
|
+
successRate: 0
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const completed = this.performanceHistory.length;
|
|
154
|
+
const avgQuality = this.performanceHistory.reduce((sum, p) => sum + p.quality, 0) / completed;
|
|
155
|
+
const avgTime = this.performanceHistory.reduce((sum, p) => sum + p.timeMs, 0) / completed;
|
|
156
|
+
const successRate = this.performanceHistory.filter(p => p.quality > 0.5).length / completed;
|
|
157
|
+
return {
|
|
158
|
+
tasksCompleted: completed,
|
|
159
|
+
averageQuality: avgQuality,
|
|
160
|
+
averageTimeMs: avgTime,
|
|
161
|
+
successRate
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Check if agent has a capability
|
|
166
|
+
* @param capabilityName - Capability name
|
|
167
|
+
* @returns True if agent has capability
|
|
168
|
+
*/
|
|
169
|
+
hasCapability(capabilityName) {
|
|
170
|
+
return this.getCapabilities().some(c => c.name === capabilityName);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get capability confidence
|
|
174
|
+
* @param capabilityName - Capability name
|
|
175
|
+
* @returns Confidence level (0-1)
|
|
176
|
+
*/
|
|
177
|
+
getCapabilityConfidence(capabilityName) {
|
|
178
|
+
const cap = this.getCapabilities().find(c => c.name === capabilityName);
|
|
179
|
+
return cap?.confidence || 0;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Check if agent can handle a task
|
|
183
|
+
* @param task - Task to check
|
|
184
|
+
* @returns True if agent can handle task
|
|
185
|
+
*/
|
|
186
|
+
canHandleTask(task) {
|
|
187
|
+
const requiredCaps = task.requirements.requiredCapabilities;
|
|
188
|
+
return requiredCaps.every(cap => this.hasCapability(cap));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create a task result
|
|
192
|
+
* @param taskId - Task ID
|
|
193
|
+
* @param output - Output data
|
|
194
|
+
* @param confidence - Confidence level
|
|
195
|
+
* @param processingTimeMs - Processing time in ms
|
|
196
|
+
* @param metadata - Additional metadata
|
|
197
|
+
* @returns Task result
|
|
198
|
+
*/
|
|
199
|
+
createTaskResult(taskId, output, confidence, processingTimeMs, metadata = {}) {
|
|
200
|
+
return {
|
|
201
|
+
taskId,
|
|
202
|
+
agentId: this.id,
|
|
203
|
+
success: confidence > 0.5,
|
|
204
|
+
output,
|
|
205
|
+
confidence,
|
|
206
|
+
processingTimeMs,
|
|
207
|
+
metadata: {
|
|
208
|
+
tokensUsed: metadata.tokensUsed || 0,
|
|
209
|
+
reasoningSteps: metadata.reasoningSteps || 1,
|
|
210
|
+
intermediateResults: metadata.intermediateResults || [],
|
|
211
|
+
error: metadata.error
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specialist Agent Implementation
|
|
3
|
+
* @module agents/specialist-agent
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseAgent } from './base-agent.js';
|
|
7
|
+
import { AgentType } from '../types/index.js';
|
|
8
|
+
import { LLMAdapter } from '../utils/llm-adapter.js';
|
|
9
|
+
/**
|
|
10
|
+
* Specialist agent that focuses on specific domain capabilities
|
|
11
|
+
*/
|
|
12
|
+
export class SpecialistAgent extends BaseAgent {
|
|
13
|
+
/**
|
|
14
|
+
* Create a new specialist agent
|
|
15
|
+
* @param config - Agent configuration
|
|
16
|
+
*/
|
|
17
|
+
constructor(config) {
|
|
18
|
+
// Convert string capabilities to AgentCapability objects if needed
|
|
19
|
+
const normalizedCapabilities = (config.capabilities || []).map(cap => {
|
|
20
|
+
if (typeof cap === 'string') {
|
|
21
|
+
return {
|
|
22
|
+
name: cap,
|
|
23
|
+
description: `Specialized capability: ${cap}`,
|
|
24
|
+
confidence: 0.8,
|
|
25
|
+
performanceMetrics: { tasksCompleted: 0, averageQuality: 0, averageTimeMs: 0 }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return cap;
|
|
29
|
+
});
|
|
30
|
+
super({
|
|
31
|
+
name: config.name,
|
|
32
|
+
type: AgentType.SPECIALIST,
|
|
33
|
+
capabilities: normalizedCapabilities,
|
|
34
|
+
confidenceThreshold: config.confidenceThreshold || 0.7
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get agent type
|
|
39
|
+
* @returns Agent type
|
|
40
|
+
*/
|
|
41
|
+
getType() {
|
|
42
|
+
return AgentType.SPECIALIST;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get agent capabilities
|
|
46
|
+
* @returns Array of capabilities
|
|
47
|
+
*/
|
|
48
|
+
getCapabilities() {
|
|
49
|
+
return this.config.capabilities;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Process a task using specialist domain knowledge
|
|
53
|
+
* @param task - Task to process
|
|
54
|
+
* @returns Task result
|
|
55
|
+
*/
|
|
56
|
+
async process(task) {
|
|
57
|
+
const startTime = Date.now();
|
|
58
|
+
const input = typeof task.input === 'string' ? task.input : JSON.stringify(task.input);
|
|
59
|
+
const capabilitiesList = this.getCapabilities().map(c => c.name).join(', ');
|
|
60
|
+
const prompt = `You are a specialist agent named "${this.config.name}" with expertise in: ${capabilitiesList}.
|
|
61
|
+
Your task is: ${task.description}
|
|
62
|
+
Input details: ${input}
|
|
63
|
+
|
|
64
|
+
Provide a detailed expert response based on your specialized knowledge.`;
|
|
65
|
+
const systemPrompt = `You are an expert specialist in ${capabilitiesList}. Provide precise, high-quality technical or domain-specific analysis.`;
|
|
66
|
+
const response = await LLMAdapter.call(prompt, systemPrompt);
|
|
67
|
+
const output = response.content || `Error: ${response.error}`;
|
|
68
|
+
const confidence = response.error ? 0 : 0.85;
|
|
69
|
+
return this.createTaskResult(task.id, {
|
|
70
|
+
conclusion: output,
|
|
71
|
+
specialistRole: this.config.name,
|
|
72
|
+
capabilitiesUsed: this.getCapabilities().map(c => c.name)
|
|
73
|
+
}, confidence, Date.now() - startTime);
|
|
74
|
+
}
|
|
75
|
+
}
|