@codebolt/agent 5.0.8 → 5.0.9

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.
Files changed (114) hide show
  1. package/dist/unified/base/responseExecutor.js +10 -6
  2. package/package.json +5 -5
  3. package/dist/agent.d.ts +0 -86
  4. package/dist/agent.js +0 -324
  5. package/dist/builderpattern/agent.d.ts +0 -86
  6. package/dist/builderpattern/agent.js +0 -324
  7. package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
  8. package/dist/builderpattern/followupquestionbuilder.js +0 -197
  9. package/dist/builderpattern/index.d.ts +0 -14
  10. package/dist/builderpattern/index.js +0 -23
  11. package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
  12. package/dist/builderpattern/llmoutputhandler.js +0 -452
  13. package/dist/builderpattern/promptbuilder.d.ts +0 -382
  14. package/dist/builderpattern/promptbuilder.js +0 -805
  15. package/dist/builderpattern/systemprompt.d.ts +0 -20
  16. package/dist/builderpattern/systemprompt.js +0 -48
  17. package/dist/builderpattern/taskInstruction.d.ts +0 -37
  18. package/dist/builderpattern/taskInstruction.js +0 -57
  19. package/dist/builderpattern/usermessage.d.ts +0 -70
  20. package/dist/builderpattern/usermessage.js +0 -123
  21. package/dist/composablepattern/agent.d.ts +0 -169
  22. package/dist/composablepattern/agent.js +0 -598
  23. package/dist/composablepattern/codebolt-storage.d.ts +0 -67
  24. package/dist/composablepattern/codebolt-storage.js +0 -320
  25. package/dist/composablepattern/document.d.ts +0 -149
  26. package/dist/composablepattern/document.js +0 -405
  27. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
  28. package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
  29. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
  30. package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
  31. package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
  32. package/dist/composablepattern/examples/custom-steps-example.js +0 -455
  33. package/dist/composablepattern/examples/document-agent.d.ts +0 -17
  34. package/dist/composablepattern/examples/document-agent.js +0 -107
  35. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
  36. package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
  37. package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
  38. package/dist/composablepattern/examples/weather-agent.js +0 -86
  39. package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
  40. package/dist/composablepattern/examples/workflow-example.js +0 -463
  41. package/dist/composablepattern/index.d.ts +0 -63
  42. package/dist/composablepattern/index.js +0 -115
  43. package/dist/composablepattern/memory.d.ts +0 -89
  44. package/dist/composablepattern/memory.js +0 -141
  45. package/dist/composablepattern/tool.d.ts +0 -84
  46. package/dist/composablepattern/tool.js +0 -260
  47. package/dist/composablepattern/types.d.ts +0 -194
  48. package/dist/composablepattern/types.js +0 -6
  49. package/dist/composablepattern/user-context.d.ts +0 -214
  50. package/dist/composablepattern/user-context.js +0 -275
  51. package/dist/composablepattern/workflow.d.ts +0 -388
  52. package/dist/composablepattern/workflow.js +0 -562
  53. package/dist/followupquestionbuilder.d.ts +0 -75
  54. package/dist/followupquestionbuilder.js +0 -197
  55. package/dist/index.d.ts +0 -14
  56. package/dist/index.js +0 -23
  57. package/dist/llmoutputhandler.d.ts +0 -102
  58. package/dist/llmoutputhandler.js +0 -452
  59. package/dist/processor/agent/agentStep.d.ts +0 -49
  60. package/dist/processor/agent/agentStep.js +0 -241
  61. package/dist/processor/agent/toolExecutor.d.ts +0 -19
  62. package/dist/processor/agent/toolExecutor.js +0 -90
  63. package/dist/processor/index.d.ts +0 -7
  64. package/dist/processor/index.js +0 -36
  65. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
  66. package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
  67. package/dist/processor/processors/baseProcessor.d.ts +0 -14
  68. package/dist/processor/processors/baseProcessor.js +0 -29
  69. package/dist/processor/tools/baseTool.d.ts +0 -10
  70. package/dist/processor/tools/baseTool.js +0 -20
  71. package/dist/processor/tools/toolList.d.ts +0 -9
  72. package/dist/processor/tools/toolList.js +0 -22
  73. package/dist/processor/types/interfaces.d.ts +0 -94
  74. package/dist/processor/types/interfaces.js +0 -2
  75. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
  76. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
  77. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
  78. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
  79. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
  80. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
  81. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
  82. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
  83. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
  84. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
  85. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
  86. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
  87. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
  88. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
  89. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
  90. package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
  91. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
  92. package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
  93. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
  94. package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
  95. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
  96. package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
  97. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
  98. package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
  99. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
  100. package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
  101. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
  102. package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
  103. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
  104. package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
  105. package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
  106. package/dist/processor-pieces/tools/fileTools.js +0 -162
  107. package/dist/promptbuilder.d.ts +0 -382
  108. package/dist/promptbuilder.js +0 -805
  109. package/dist/systemprompt.d.ts +0 -20
  110. package/dist/systemprompt.js +0 -48
  111. package/dist/taskInstruction.d.ts +0 -37
  112. package/dist/taskInstruction.js +0 -57
  113. package/dist/usermessage.d.ts +0 -70
  114. package/dist/usermessage.js +0 -123
@@ -1,405 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview Document handling for Composable Agent Pattern
4
- * @description Provides document processing, chunking, and embedding capabilities
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.MDocument = void 0;
41
- /**
42
- * Document processing and management class
43
- */
44
- class MDocument {
45
- constructor(content, type = 'text', metadata = {}) {
46
- this.content = content;
47
- this.type = type;
48
- this.metadata = {
49
- ...metadata,
50
- createdAt: new Date().toISOString(),
51
- wordCount: this.countWords(content),
52
- charCount: content.length
53
- };
54
- }
55
- /**
56
- * Create MDocument from plain text
57
- *
58
- * @param text - Plain text content
59
- * @param metadata - Optional metadata
60
- * @returns MDocument instance
61
- */
62
- static fromText(text, metadata) {
63
- return new MDocument(text, 'text', metadata);
64
- }
65
- /**
66
- * Create MDocument from markdown
67
- *
68
- * @param markdown - Markdown content
69
- * @param metadata - Optional metadata
70
- * @returns MDocument instance
71
- */
72
- static fromMarkdown(markdown, metadata) {
73
- return new MDocument(markdown, 'markdown', metadata);
74
- }
75
- /**
76
- * Create MDocument from JSON
77
- *
78
- * @param json - JSON object or string
79
- * @param metadata - Optional metadata
80
- * @returns MDocument instance
81
- */
82
- static fromJSON(json, metadata) {
83
- const content = typeof json === 'string' ? json : JSON.stringify(json, null, 2);
84
- return new MDocument(content, 'json', metadata);
85
- }
86
- /**
87
- * Create MDocument from file path
88
- *
89
- * @param filePath - Path to the file
90
- * @param metadata - Optional metadata
91
- * @returns Promise<MDocument> instance
92
- */
93
- static async fromFile(filePath, metadata) {
94
- const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
95
- const path = await Promise.resolve().then(() => __importStar(require('path')));
96
- const content = await fs.readFile(filePath, 'utf-8');
97
- const extension = path.extname(filePath).toLowerCase();
98
- let type = 'text';
99
- if (extension === '.md')
100
- type = 'markdown';
101
- else if (extension === '.json')
102
- type = 'json';
103
- else if (extension === '.xml')
104
- type = 'xml';
105
- const fileMetadata = {
106
- ...metadata,
107
- filePath,
108
- fileName: path.basename(filePath),
109
- fileExtension: extension
110
- };
111
- return new MDocument(content, type, fileMetadata);
112
- }
113
- /**
114
- * Get document content
115
- */
116
- getContent() {
117
- return this.content;
118
- }
119
- /**
120
- * Get document type
121
- */
122
- getType() {
123
- return this.type;
124
- }
125
- /**
126
- * Get document metadata
127
- */
128
- getMetadata() {
129
- return { ...this.metadata };
130
- }
131
- /**
132
- * Update document metadata
133
- *
134
- * @param metadata - Metadata to merge
135
- */
136
- updateMetadata(metadata) {
137
- this.metadata = {
138
- ...this.metadata,
139
- ...metadata,
140
- updatedAt: new Date().toISOString()
141
- };
142
- }
143
- /**
144
- * Chunk the document into smaller pieces
145
- *
146
- * @param options - Chunking options
147
- * @returns Array of text chunks
148
- */
149
- chunk(options = {}) {
150
- const { size = 1000, overlap = 100, strategy = 'paragraph' } = options;
151
- let chunks;
152
- switch (strategy) {
153
- case 'sentence':
154
- chunks = this.chunkBySentence(size, overlap);
155
- break;
156
- case 'paragraph':
157
- chunks = this.chunkByParagraph(size, overlap);
158
- break;
159
- case 'semantic':
160
- chunks = this.chunkSemantic(size, overlap);
161
- break;
162
- case 'fixed':
163
- default:
164
- chunks = this.chunkFixed(size, overlap);
165
- break;
166
- }
167
- this.chunks = chunks;
168
- this.updateMetadata({
169
- chunkCount: chunks.length,
170
- chunkStrategy: strategy,
171
- chunkSize: size,
172
- chunkOverlap: overlap
173
- });
174
- return chunks;
175
- }
176
- /**
177
- * Get existing chunks or create them if they don't exist
178
- */
179
- getChunks() {
180
- if (!this.chunks) {
181
- return this.chunk();
182
- }
183
- return this.chunks;
184
- }
185
- /**
186
- * Set embeddings for the document or its chunks
187
- *
188
- * @param embeddings - Array of embedding vectors
189
- */
190
- setEmbeddings(embeddings) {
191
- var _a;
192
- this.embeddings = embeddings;
193
- this.updateMetadata({
194
- hasEmbeddings: true,
195
- embeddingCount: embeddings.length,
196
- embeddingDimension: ((_a = embeddings[0]) === null || _a === void 0 ? void 0 : _a.length) || 0
197
- });
198
- }
199
- /**
200
- * Get embeddings
201
- */
202
- getEmbeddings() {
203
- return this.embeddings;
204
- }
205
- /**
206
- * Convert to processed document format
207
- */
208
- toProcessedDocument() {
209
- return {
210
- content: this.content,
211
- chunks: this.chunks,
212
- metadata: this.metadata,
213
- embeddings: this.embeddings
214
- };
215
- }
216
- /**
217
- * Convert to plain object
218
- */
219
- toJSON() {
220
- return {
221
- content: this.content,
222
- type: this.type,
223
- metadata: this.metadata,
224
- chunks: this.chunks,
225
- embeddings: this.embeddings
226
- };
227
- }
228
- /**
229
- * Create MDocument from processed document
230
- *
231
- * @param processed - Processed document data
232
- * @returns MDocument instance
233
- */
234
- static fromProcessedDocument(processed) {
235
- const doc = new MDocument(processed.content, processed.metadata.type || 'text', processed.metadata);
236
- if (processed.chunks) {
237
- doc.chunks = processed.chunks;
238
- }
239
- if (processed.embeddings) {
240
- doc.embeddings = processed.embeddings;
241
- }
242
- return doc;
243
- }
244
- /**
245
- * Extract text content based on document type
246
- */
247
- extractText() {
248
- switch (this.type) {
249
- case 'markdown':
250
- return this.extractMarkdownText();
251
- case 'json':
252
- return this.extractJSONText();
253
- case 'xml':
254
- return this.extractXMLText();
255
- default:
256
- return this.content;
257
- }
258
- }
259
- /**
260
- * Count words in content
261
- */
262
- countWords(content) {
263
- return content.trim().split(/\s+/).filter(word => word.length > 0).length;
264
- }
265
- /**
266
- * Fixed-size chunking with overlap
267
- */
268
- chunkFixed(size, overlap) {
269
- const chunks = [];
270
- let start = 0;
271
- while (start < this.content.length) {
272
- const end = Math.min(start + size, this.content.length);
273
- chunks.push(this.content.slice(start, end));
274
- if (end === this.content.length)
275
- break;
276
- start = end - overlap;
277
- }
278
- return chunks;
279
- }
280
- /**
281
- * Sentence-based chunking
282
- */
283
- chunkBySentence(size, overlap) {
284
- const sentences = this.content.split(/[.!?]+/).filter(s => s.trim().length > 0);
285
- const chunks = [];
286
- let currentChunk = '';
287
- let currentSize = 0;
288
- for (const sentence of sentences) {
289
- const sentenceSize = sentence.length;
290
- if (currentSize + sentenceSize > size && currentChunk) {
291
- chunks.push(currentChunk.trim());
292
- // Handle overlap by keeping some sentences
293
- if (overlap > 0) {
294
- const overlapSentences = currentChunk.split(/[.!?]+/).slice(-Math.ceil(overlap / 100));
295
- currentChunk = overlapSentences.join('. ') + '. ';
296
- currentSize = currentChunk.length;
297
- }
298
- else {
299
- currentChunk = '';
300
- currentSize = 0;
301
- }
302
- }
303
- currentChunk += sentence + '. ';
304
- currentSize += sentenceSize;
305
- }
306
- if (currentChunk.trim()) {
307
- chunks.push(currentChunk.trim());
308
- }
309
- return chunks;
310
- }
311
- /**
312
- * Paragraph-based chunking
313
- */
314
- chunkByParagraph(size, overlap) {
315
- const paragraphs = this.content.split(/\n\s*\n/).filter(p => p.trim().length > 0);
316
- const chunks = [];
317
- let currentChunk = '';
318
- let currentSize = 0;
319
- for (const paragraph of paragraphs) {
320
- const paragraphSize = paragraph.length;
321
- if (currentSize + paragraphSize > size && currentChunk) {
322
- chunks.push(currentChunk.trim());
323
- // Handle overlap
324
- if (overlap > 0) {
325
- const words = currentChunk.split(/\s+/);
326
- const overlapWords = words.slice(-overlap);
327
- currentChunk = overlapWords.join(' ') + ' ';
328
- currentSize = currentChunk.length;
329
- }
330
- else {
331
- currentChunk = '';
332
- currentSize = 0;
333
- }
334
- }
335
- currentChunk += paragraph + '\n\n';
336
- currentSize += paragraphSize;
337
- }
338
- if (currentChunk.trim()) {
339
- chunks.push(currentChunk.trim());
340
- }
341
- return chunks;
342
- }
343
- /**
344
- * Semantic chunking (basic implementation)
345
- */
346
- chunkSemantic(size, overlap) {
347
- // For now, fall back to paragraph chunking
348
- // In a full implementation, this would use NLP techniques
349
- return this.chunkByParagraph(size, overlap);
350
- }
351
- /**
352
- * Extract text from markdown
353
- */
354
- extractMarkdownText() {
355
- // Simple markdown text extraction
356
- return this.content
357
- .replace(/^#+\s+/gm, '') // Remove headers
358
- .replace(/\*\*(.*?)\*\*/g, '$1') // Remove bold
359
- .replace(/\*(.*?)\*/g, '$1') // Remove italic
360
- .replace(/`(.*?)`/g, '$1') // Remove inline code
361
- .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // Remove links
362
- .replace(/```[\s\S]*?```/g, '') // Remove code blocks
363
- .trim();
364
- }
365
- /**
366
- * Extract text from JSON
367
- */
368
- extractJSONText() {
369
- try {
370
- const obj = JSON.parse(this.content);
371
- return this.extractTextFromObject(obj);
372
- }
373
- catch {
374
- return this.content;
375
- }
376
- }
377
- /**
378
- * Extract text from XML
379
- */
380
- extractXMLText() {
381
- // Simple XML text extraction
382
- return this.content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
383
- }
384
- /**
385
- * Recursively extract text from object
386
- */
387
- extractTextFromObject(obj) {
388
- if (typeof obj === 'string')
389
- return obj;
390
- if (typeof obj === 'number')
391
- return obj.toString();
392
- if (typeof obj === 'boolean')
393
- return obj.toString();
394
- if (obj === null || obj === undefined)
395
- return '';
396
- if (Array.isArray(obj)) {
397
- return obj.map(item => this.extractTextFromObject(item)).join(' ');
398
- }
399
- if (typeof obj === 'object') {
400
- return Object.values(obj).map(value => this.extractTextFromObject(value)).join(' ');
401
- }
402
- return '';
403
- }
404
- }
405
- exports.MDocument = MDocument;
@@ -1,12 +0,0 @@
1
- /**
2
- * @fileoverview CodeBolt Integration Example
3
- * @description Example showing how to use ComposableAgent within CodeBolt's onMessage system
4
- */
5
- import { ComposableAgent } from '../index';
6
- declare const myAgent: ComposableAgent;
7
- declare const flexibleAgent: ComposableAgent;
8
- declare const researchAgent: ComposableAgent;
9
- declare const writingAgent: ComposableAgent;
10
- declare const workflowAgent: ComposableAgent;
11
- declare const complexWorkflow: import("../workflow").Workflow;
12
- export { myAgent, flexibleAgent, researchAgent, writingAgent, workflowAgent, complexWorkflow };
@@ -1,218 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview CodeBolt Integration Example
4
- * @description Example showing how to use ComposableAgent within CodeBolt's onMessage system
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.complexWorkflow = exports.workflowAgent = exports.writingAgent = exports.researchAgent = exports.flexibleAgent = exports.myAgent = void 0;
8
- const index_1 = require("../index");
9
- // This would typically be in a separate file, e.g., agent.js
10
- const codebolt = require('@codebolt/codeboltjs');
11
- // Create your tools
12
- const weatherTool = (0, index_1.createTool)({
13
- id: 'get-weather',
14
- description: 'Get current weather for a location',
15
- inputSchema: index_1.z.object({
16
- location: index_1.z.string().describe('City name'),
17
- }),
18
- outputSchema: index_1.z.object({
19
- temperature: index_1.z.number(),
20
- conditions: index_1.z.string(),
21
- location: index_1.z.string(),
22
- }),
23
- execute: async ({ context }) => {
24
- // Mock weather data
25
- return {
26
- temperature: 22,
27
- conditions: 'Sunny',
28
- location: context.location
29
- };
30
- },
31
- });
32
- // Create your composable agent
33
- const myAgent = new index_1.ComposableAgent({
34
- name: 'Weather Assistant',
35
- instructions: `
36
- You are a helpful weather assistant.
37
- Use the weather tool to get current weather information.
38
- Be friendly and provide helpful responses.
39
- `,
40
- model: 'weathermodel', // References configuration in codeboltagents.yaml
41
- tools: { weatherTool },
42
- processing: {
43
- // Configure what to process automatically
44
- processMentionedMCPs: true, // Auto-add mentioned MCPs as tools
45
- processRemixPrompt: true, // Use remix prompt to enhance instructions
46
- processMentionedFiles: true, // Include mentioned file contents
47
- processMentionedAgents: true // Add mentioned agents as sub-agents
48
- }
49
- });
50
- exports.myAgent = myAgent;
51
- // CodeBolt integration - this is how you'd use it in your agent
52
- codebolt.onMessage(async (reqMessage) => {
53
- try {
54
- console.log('Received message:', reqMessage);
55
- // Save the user message globally so the agent can access it
56
- (0, index_1.saveUserMessage)(reqMessage, {
57
- // You can override the auto-detection here if needed
58
- processMentionedMCPs: true,
59
- processRemixPrompt: true,
60
- processMentionedFiles: false, // Don't process files for this agent
61
- processMentionedAgents: true
62
- });
63
- // Now simply run the agent - it will automatically use the saved user context
64
- const result = await myAgent.run();
65
- if (result.success) {
66
- return result.message;
67
- }
68
- else {
69
- console.error('Agent failed:', result.error);
70
- return 'Sorry, I encountered an error processing your request.';
71
- }
72
- }
73
- catch (error) {
74
- console.error('Error in agent execution:', error);
75
- return 'Sorry, something went wrong.';
76
- }
77
- });
78
- // ================================
79
- // Alternative Example: Manual Configuration per Message
80
- // ================================
81
- const flexibleAgent = new index_1.ComposableAgent({
82
- name: 'Flexible Assistant',
83
- instructions: 'I am a flexible assistant that adapts based on user context.',
84
- model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
85
- tools: { weatherTool }
86
- // No processing config - will use global user config
87
- });
88
- exports.flexibleAgent = flexibleAgent;
89
- codebolt.onMessage(async (reqMessage) => {
90
- var _a, _b;
91
- try {
92
- // Analyze the message to determine what to process
93
- const shouldProcessMCPs = ((_a = reqMessage.mentionedMCPs) === null || _a === void 0 ? void 0 : _a.length) > 0;
94
- const shouldProcessFiles = (_b = reqMessage.mentionedFiles) === null || _b === void 0 ? void 0 : _b.some((file) => file.endsWith('.json') || file.endsWith('.yaml'));
95
- // Save with custom configuration
96
- (0, index_1.saveUserMessage)(reqMessage, {
97
- processMentionedMCPs: shouldProcessMCPs,
98
- processRemixPrompt: true,
99
- processMentionedFiles: shouldProcessFiles,
100
- processMentionedAgents: false // Don't use sub-agents for this example
101
- });
102
- // Run the agent
103
- const result = await flexibleAgent.run();
104
- return result.success ? result.message : 'Error occurred';
105
- }
106
- catch (error) {
107
- console.error('Error:', error);
108
- return 'Error processing request';
109
- }
110
- });
111
- // ================================
112
- // Example: Multiple Agents with Shared Context
113
- // ================================
114
- const researchAgent = new index_1.ComposableAgent({
115
- name: 'Research Agent',
116
- instructions: 'Research and gather information on topics.',
117
- model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
118
- processing: { processMentionedFiles: true } // This agent processes files
119
- });
120
- exports.researchAgent = researchAgent;
121
- const writingAgent = new index_1.ComposableAgent({
122
- name: 'Writing Agent',
123
- instructions: 'Write content based on research and requirements.',
124
- model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
125
- processing: { processRemixPrompt: true } // This agent uses remix prompts
126
- });
127
- exports.writingAgent = writingAgent;
128
- codebolt.onMessage(async (reqMessage) => {
129
- try {
130
- // Save user message once for all agents to use
131
- (0, index_1.saveUserMessage)(reqMessage);
132
- let result;
133
- // Determine which agent to use based on message content
134
- if (reqMessage.userMessage.toLowerCase().includes('research')) {
135
- result = await researchAgent.run();
136
- }
137
- else if (reqMessage.userMessage.toLowerCase().includes('write')) {
138
- result = await writingAgent.run();
139
- }
140
- else {
141
- // Use the default agent
142
- result = await myAgent.run();
143
- }
144
- return result.success ? result.message : 'Error occurred';
145
- }
146
- catch (error) {
147
- console.error('Error:', error);
148
- return 'Error processing request';
149
- }
150
- });
151
- // ================================
152
- // Example: Workflow with Global Context
153
- // ================================
154
- const index_2 = require("../index");
155
- const workflowAgent = new index_1.ComposableAgent({
156
- name: 'Workflow Agent',
157
- instructions: 'I coordinate complex multi-step tasks.',
158
- model: 'gpt-4o-mini' // References configuration in codeboltagents.yaml
159
- });
160
- exports.workflowAgent = workflowAgent;
161
- const complexWorkflow = (0, index_2.createWorkflow)({
162
- name: 'Research and Write Workflow',
163
- initialData: {}, // Will be populated from user context
164
- steps: [
165
- // Extract user context into workflow data
166
- (0, index_2.createSimpleStep)({
167
- id: 'setup-context',
168
- name: 'Setup Workflow Context',
169
- execute: () => {
170
- const userMsg = (0, index_1.getUserMessage)();
171
- const files = (0, index_1.getMentionedFiles)();
172
- const mcps = (0, index_1.getMentionedMCPs)();
173
- return {
174
- userMessage: (userMsg === null || userMsg === void 0 ? void 0 : userMsg.userMessage) || '',
175
- mentionedFiles: files,
176
- mentionedMCPs: mcps,
177
- setupComplete: true
178
- };
179
- }
180
- }),
181
- // Use agent step that automatically gets user context
182
- (0, index_2.createAgentStep)({
183
- id: 'research-step',
184
- name: 'Research Phase',
185
- agent: researchAgent,
186
- messageTemplate: 'Research this topic: {{userMessage}}',
187
- outputMapping: { 'researchData': 'agentResult.message' }
188
- }),
189
- (0, index_2.createAgentStep)({
190
- id: 'writing-step',
191
- name: 'Writing Phase',
192
- agent: writingAgent,
193
- messageTemplate: 'Write content based on: {{researchData}}',
194
- outputMapping: { 'finalContent': 'agentResult.message' }
195
- })
196
- ]
197
- });
198
- exports.complexWorkflow = complexWorkflow;
199
- codebolt.onMessage(async (reqMessage) => {
200
- try {
201
- // Save user message for all agents and workflow steps to use
202
- (0, index_1.saveUserMessage)(reqMessage);
203
- if (reqMessage.userMessage.includes('complex task')) {
204
- // Use workflow for complex tasks
205
- const workflowResult = await complexWorkflow.execute();
206
- return workflowResult.success ? workflowResult.data.finalContent : 'Workflow failed';
207
- }
208
- else {
209
- // Use simple agent for regular tasks
210
- const result = await workflowAgent.run();
211
- return result.success ? result.message : 'Agent failed';
212
- }
213
- }
214
- catch (error) {
215
- console.error('Error:', error);
216
- return 'Error processing request';
217
- }
218
- });
@@ -1,40 +0,0 @@
1
- /**
2
- * @fileoverview Example demonstrating CodeBolt backend storage for ComposableAgent
3
- * @description Shows how to use CodeBolt's state and memory functions instead of SQLite
4
- */
5
- import { ComposableAgent } from '../index';
6
- /**
7
- * Example: Weather Agent with CodeBolt Agent State Storage
8
- * Data is stored in CodeBolt's agent state backend
9
- */
10
- export declare const weatherAgentWithAgentStorage: ComposableAgent;
11
- /**
12
- * Example: Task Management Agent with CodeBolt Project State Storage
13
- * Data is stored in CodeBolt's project state backend
14
- */
15
- export declare const taskAgentWithProjectStorage: ComposableAgent;
16
- /**
17
- * Example: Knowledge Agent with CodeBolt Memory Database Storage
18
- * Data is stored in CodeBolt's in-memory database backend
19
- */
20
- export declare const knowledgeAgentWithDbStorage: ComposableAgent;
21
- /**
22
- * Example usage within CodeBolt onMessage
23
- */
24
- export declare function setupCodeBoltStorageExample(): void;
25
- /**
26
- * Example: Custom storage configuration
27
- */
28
- export declare function createCustomStorageAgent(): ComposableAgent;
29
- /**
30
- * Example: Multiple agents with different storage backends
31
- */
32
- export declare function setupMultiStorageAgents(): {
33
- sessionAgent: ComposableAgent;
34
- globalAgent: ComposableAgent;
35
- cacheAgent: ComposableAgent;
36
- };
37
- /**
38
- * Storage comparison and migration helper
39
- */
40
- export declare function storageComparison(): Promise<void>;