@codebolt/agent 1.2.1 → 2.2.2

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 (183) hide show
  1. package/README.md +157 -66
  2. package/dist/builderpattern/agent.d.ts +86 -0
  3. package/dist/builderpattern/agent.js +324 -0
  4. package/dist/builderpattern/followupquestionbuilder.d.ts +75 -0
  5. package/dist/builderpattern/followupquestionbuilder.js +197 -0
  6. package/dist/builderpattern/index.d.ts +14 -0
  7. package/dist/builderpattern/index.js +23 -0
  8. package/dist/builderpattern/llmoutputhandler.d.ts +102 -0
  9. package/dist/builderpattern/llmoutputhandler.js +452 -0
  10. package/dist/builderpattern/promptbuilder.d.ts +382 -0
  11. package/dist/builderpattern/promptbuilder.js +805 -0
  12. package/dist/builderpattern/systemprompt.d.ts +20 -0
  13. package/dist/builderpattern/systemprompt.js +48 -0
  14. package/dist/builderpattern/taskInstruction.d.ts +37 -0
  15. package/dist/builderpattern/taskInstruction.js +57 -0
  16. package/dist/builderpattern/usermessage.d.ts +70 -0
  17. package/dist/builderpattern/usermessage.js +123 -0
  18. package/dist/composablepattern/agent.d.ts +169 -0
  19. package/dist/composablepattern/agent.js +598 -0
  20. package/dist/composablepattern/codebolt-storage.d.ts +67 -0
  21. package/dist/composablepattern/codebolt-storage.js +320 -0
  22. package/dist/composablepattern/document.d.ts +149 -0
  23. package/dist/composablepattern/document.js +405 -0
  24. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +12 -0
  25. package/dist/composablepattern/examples/codebolt-integration-example.js +218 -0
  26. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +40 -0
  27. package/dist/composablepattern/examples/codebolt-storage-example.js +223 -0
  28. package/dist/composablepattern/examples/custom-steps-example.d.ts +20 -0
  29. package/dist/composablepattern/examples/custom-steps-example.js +455 -0
  30. package/dist/composablepattern/examples/document-agent.d.ts +17 -0
  31. package/dist/composablepattern/examples/document-agent.js +107 -0
  32. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +8 -0
  33. package/dist/composablepattern/examples/simple-codebolt-integration.js +164 -0
  34. package/dist/composablepattern/examples/weather-agent.d.ts +18 -0
  35. package/dist/composablepattern/examples/weather-agent.js +86 -0
  36. package/dist/composablepattern/examples/workflow-example.d.ts +12 -0
  37. package/dist/composablepattern/examples/workflow-example.js +463 -0
  38. package/dist/composablepattern/index.d.ts +63 -0
  39. package/dist/composablepattern/index.js +115 -0
  40. package/dist/composablepattern/memory.d.ts +89 -0
  41. package/dist/composablepattern/memory.js +141 -0
  42. package/dist/composablepattern/tool.d.ts +84 -0
  43. package/dist/composablepattern/tool.js +260 -0
  44. package/dist/composablepattern/types.d.ts +194 -0
  45. package/dist/composablepattern/types.js +6 -0
  46. package/dist/composablepattern/user-context.d.ts +214 -0
  47. package/dist/composablepattern/user-context.js +275 -0
  48. package/dist/composablepattern/workflow.d.ts +388 -0
  49. package/dist/composablepattern/workflow.js +562 -0
  50. package/dist/processor/agent/agentStep.d.ts +49 -0
  51. package/dist/processor/agent/agentStep.js +241 -0
  52. package/dist/processor/agent/toolExecutor.d.ts +19 -0
  53. package/dist/processor/agent/toolExecutor.js +90 -0
  54. package/dist/processor/index.d.ts +7 -0
  55. package/dist/processor/index.js +36 -0
  56. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +20 -0
  57. package/dist/processor/messageModifiers/baseMessageModifier.js +55 -0
  58. package/dist/processor/processors/baseProcessor.d.ts +14 -0
  59. package/dist/processor/processors/baseProcessor.js +29 -0
  60. package/dist/processor/tools/baseTool.d.ts +10 -0
  61. package/dist/processor/tools/baseTool.js +20 -0
  62. package/dist/processor/tools/toolList.d.ts +9 -0
  63. package/dist/processor/tools/toolList.js +22 -0
  64. package/dist/processor/types/interfaces.d.ts +94 -0
  65. package/dist/processor/types/interfaces.js +2 -0
  66. package/dist/processor-pieces/base/baseMessageModifier.d.ts +12 -0
  67. package/dist/processor-pieces/base/baseMessageModifier.js +15 -0
  68. package/dist/processor-pieces/base/basePostInferenceProcessor.d.ts +13 -0
  69. package/dist/processor-pieces/base/basePostInferenceProcessor.js +18 -0
  70. package/dist/processor-pieces/base/basePostToolCallProcessor.d.ts +15 -0
  71. package/dist/processor-pieces/base/basePostToolCallProcessor.js +25 -0
  72. package/dist/processor-pieces/base/basePreInferenceProcessor.d.ts +12 -0
  73. package/dist/processor-pieces/base/basePreInferenceProcessor.js +17 -0
  74. package/dist/processor-pieces/base/basePreToolCallProcessor.d.ts +18 -0
  75. package/dist/processor-pieces/base/basePreToolCallProcessor.js +66 -0
  76. package/dist/processor-pieces/base/index.d.ts +9 -0
  77. package/dist/processor-pieces/base/index.js +18 -0
  78. package/dist/processor-pieces/index.d.ts +1 -0
  79. package/dist/processor-pieces/index.js +59 -0
  80. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +22 -0
  81. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +144 -0
  82. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +13 -0
  83. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +68 -0
  84. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +25 -0
  85. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +453 -0
  86. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +15 -0
  87. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +75 -0
  88. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +11 -0
  89. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +46 -0
  90. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +18 -0
  91. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +104 -0
  92. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +23 -0
  93. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +173 -0
  94. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +14 -0
  95. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +130 -0
  96. package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +36 -0
  97. package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +418 -0
  98. package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +26 -0
  99. package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
  100. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +12 -0
  101. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +60 -0
  102. package/dist/processor-pieces/messageModifiers/ideContextModifier.d.ts +34 -0
  103. package/dist/processor-pieces/messageModifiers/ideContextModifier.js +157 -0
  104. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +18 -0
  105. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +222 -0
  106. package/dist/processor-pieces/messageModifiers/index.d.ts +11 -0
  107. package/dist/processor-pieces/messageModifiers/index.js +26 -0
  108. package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +15 -0
  109. package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +129 -0
  110. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +20 -0
  111. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
  112. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +22 -0
  113. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +194 -0
  114. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
  115. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -0
  116. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -0
  117. package/dist/processor-pieces/postToolCallProcessors/index.js +2 -0
  118. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.d.ts +25 -0
  119. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +225 -0
  120. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +35 -0
  121. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
  122. package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
  123. package/dist/processor-pieces/preInferenceProcessors/index.js +2 -0
  124. package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +1 -0
  125. package/dist/processor-pieces/pretoolCallProcessors/index.js +2 -0
  126. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +41 -0
  127. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +197 -0
  128. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +26 -0
  129. package/dist/processor-pieces/processors/chatCompressionProcessor.js +90 -0
  130. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +81 -0
  131. package/dist/processor-pieces/processors/chatRecordingProcessor.js +329 -0
  132. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +40 -0
  133. package/dist/processor-pieces/processors/contextManagementProcessor.js +305 -0
  134. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +30 -0
  135. package/dist/processor-pieces/processors/loopDetectionProcessor.js +137 -0
  136. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +30 -0
  137. package/dist/processor-pieces/processors/responseValidationProcessor.js +228 -0
  138. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +99 -0
  139. package/dist/processor-pieces/processors/telemetryProcessor.js +311 -0
  140. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +37 -0
  141. package/dist/processor-pieces/processors/tokenManagementProcessor.js +178 -0
  142. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +43 -0
  143. package/dist/processor-pieces/processors/toolExecutionProcessor.js +207 -0
  144. package/dist/processor-pieces/tools/fileTools.d.ts +26 -0
  145. package/dist/processor-pieces/tools/fileTools.js +162 -0
  146. package/dist/processor-pieces/utils/messageModifierHelper.d.ts +4 -0
  147. package/dist/processor-pieces/utils/messageModifierHelper.js +58 -0
  148. package/dist/types/commonTypes.d.ts +4 -0
  149. package/dist/types/processorTypes.d.ts +67 -0
  150. package/dist/types/processorTypes.js +58 -0
  151. package/dist/unified/agent/agent.d.ts +17 -0
  152. package/dist/unified/agent/agent.js +79 -0
  153. package/dist/unified/agent/team.d.ts +2 -0
  154. package/dist/unified/agent/team.js +6 -0
  155. package/dist/unified/agent/tools.d.ts +44 -0
  156. package/dist/unified/agent/tools.js +487 -0
  157. package/dist/unified/agent/workflow.d.ts +24 -0
  158. package/dist/unified/agent/workflow.js +275 -0
  159. package/dist/unified/agent/workflowControls.d.ts +11 -0
  160. package/dist/unified/agent/workflowControls.js +20 -0
  161. package/dist/unified/agent/workflowSteps.d.ts +63 -0
  162. package/dist/unified/agent/workflowSteps.js +284 -0
  163. package/dist/unified/base/agentStep.d.ts +32 -0
  164. package/dist/unified/base/agentStep.js +96 -0
  165. package/dist/unified/base/create/createInitialPromptGenerators.d.ts +5 -0
  166. package/dist/unified/base/create/createInitialPromptGenerators.js +17 -0
  167. package/dist/unified/base/index.d.ts +5 -0
  168. package/dist/unified/base/index.js +13 -0
  169. package/dist/unified/base/initialPromptGenerator.d.ts +48 -0
  170. package/dist/unified/base/initialPromptGenerator.js +118 -0
  171. package/dist/unified/base/responseExecutor.d.ts +36 -0
  172. package/dist/unified/base/responseExecutor.js +283 -0
  173. package/dist/unified/index.d.ts +18 -0
  174. package/dist/unified/index.js +42 -0
  175. package/dist/unified/team/team.d.ts +1 -0
  176. package/dist/unified/team/team.js +2 -0
  177. package/dist/unified/types/libTypes.d.ts +378 -0
  178. package/dist/unified/types/libTypes.js +6 -0
  179. package/dist/unified/types/types.d.ts +212 -0
  180. package/dist/unified/types/types.js +43 -0
  181. package/dist/unified/utils/utils.d.ts +40 -0
  182. package/dist/unified/utils/utils.js +219 -0
  183. package/package.json +29 -7
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @fileoverview Document Agent Example
3
+ * @description Example showing how to create a document processing agent using the composable pattern
4
+ */
5
+ import { ComposableAgent } from '../index';
6
+ export declare const processDocumentTool: import("../types").Tool<{
7
+ content: string;
8
+ operation: "summarize" | "extract_keywords" | "chunk" | "analyze";
9
+ }, {
10
+ result: string;
11
+ metadata: Record<string, any>;
12
+ } | {
13
+ result: string;
14
+ metadata?: undefined;
15
+ }>;
16
+ export declare const documentAgent: ComposableAgent;
17
+ export declare function runDocumentExample(): Promise<import("../types").ExecutionResult>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Document Agent Example
4
+ * @description Example showing how to create a document processing agent using the composable pattern
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.documentAgent = exports.processDocumentTool = void 0;
8
+ exports.runDocumentExample = runDocumentExample;
9
+ const index_1 = require("../index");
10
+ // Create document processing tool
11
+ exports.processDocumentTool = (0, index_1.createTool)({
12
+ id: 'process-document',
13
+ description: 'Process and analyze a document',
14
+ inputSchema: index_1.z.object({
15
+ content: index_1.z.string().describe('Document content to process'),
16
+ operation: index_1.z.enum(['summarize', 'extract_keywords', 'chunk', 'analyze']).describe('Operation to perform')
17
+ }),
18
+ outputSchema: index_1.z.object({
19
+ result: index_1.z.string(),
20
+ metadata: index_1.z.record(index_1.z.any()).optional()
21
+ }),
22
+ execute: async ({ context }) => {
23
+ const doc = index_1.MDocument.fromText(context.content);
24
+ switch (context.operation) {
25
+ case 'summarize':
26
+ // Simple summarization (in real usage, you might use an LLM for this)
27
+ const words = context.content.split(/\s+/);
28
+ const summary = words.slice(0, 50).join(' ') + (words.length > 50 ? '...' : '');
29
+ return {
30
+ result: `Summary: ${summary}`,
31
+ metadata: doc.getMetadata()
32
+ };
33
+ case 'extract_keywords':
34
+ // Simple keyword extraction
35
+ const keywordPattern = /\b[A-Z][a-z]+\b/g;
36
+ const keywords = [...new Set(context.content.match(keywordPattern) || [])].slice(0, 10);
37
+ return {
38
+ result: `Keywords: ${keywords.join(', ')}`,
39
+ metadata: { keywordCount: keywords.length }
40
+ };
41
+ case 'chunk':
42
+ const chunks = doc.chunk({ size: 500, strategy: 'paragraph' });
43
+ return {
44
+ result: `Document chunked into ${chunks.length} pieces`,
45
+ metadata: { chunkCount: chunks.length, chunks: chunks.slice(0, 3) }
46
+ };
47
+ case 'analyze':
48
+ const metadata = doc.getMetadata();
49
+ return {
50
+ result: `Document analysis: ${metadata.wordCount} words, ${metadata.charCount} characters`,
51
+ metadata
52
+ };
53
+ default:
54
+ return { result: 'Unknown operation' };
55
+ }
56
+ },
57
+ });
58
+ // Create a document from sample text
59
+ const doc = index_1.MDocument.fromText(`
60
+ Climate change poses significant challenges to global agriculture.
61
+ Rising temperatures and changing precipitation patterns affect crop yields.
62
+ Farmers worldwide are adapting their practices to mitigate these impacts.
63
+
64
+ Sustainable farming techniques, including crop rotation and precision agriculture,
65
+ are becoming increasingly important. Technology plays a crucial role in
66
+ monitoring soil conditions and optimizing resource usage.
67
+ `);
68
+ // Create document agent
69
+ exports.documentAgent = new index_1.ComposableAgent({
70
+ name: 'Document Processing Agent',
71
+ instructions: `
72
+ You are a helpful document processing assistant that can analyze, summarize, and extract information from documents.
73
+
74
+ Your capabilities include:
75
+ - Summarizing document content
76
+ - Extracting keywords and key topics
77
+ - Chunking documents for processing
78
+ - Analyzing document structure and metadata
79
+
80
+ Use the process-document tool to perform these operations.
81
+ `,
82
+ model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
83
+ tools: { processDocumentTool: exports.processDocumentTool },
84
+ memory: (0, index_1.createCodeBoltAgentMemory)()
85
+ });
86
+ // Example usage
87
+ async function runDocumentExample() {
88
+ try {
89
+ console.log('Running document processing agent example...');
90
+ const result = await exports.documentAgent.execute(`Please analyze this document about climate change and agriculture: "${doc.getContent()}"`);
91
+ if (result.success) {
92
+ console.log('Agent response:', result.message);
93
+ }
94
+ else {
95
+ console.error('Agent failed:', result.error);
96
+ }
97
+ return result;
98
+ }
99
+ catch (error) {
100
+ console.error('Example failed:', error);
101
+ throw error;
102
+ }
103
+ }
104
+ // Run example if this file is executed directly
105
+ if (require.main === module) {
106
+ runDocumentExample().catch(console.error);
107
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Simple CodeBolt Integration Example
3
+ * @description Shows the new simplified integration where codeboltjs automatically saves user messages
4
+ */
5
+ declare const myAgent: any;
6
+ declare const researchAgent: any;
7
+ declare const writingAgent: any;
8
+ export { myAgent, researchAgent, writingAgent };
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Simple CodeBolt Integration Example
4
+ * @description Shows the new simplified integration where codeboltjs automatically saves user messages
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.writingAgent = exports.researchAgent = exports.myAgent = void 0;
8
+ // This is how simple it now is - no manual saveUserMessage needed!
9
+ const codebolt = require('@codebolt/codeboltjs');
10
+ const { ComposableAgent, createTool, z } = require('@codebolt/agent/composable');
11
+ // Create a simple tool
12
+ const weatherTool = createTool({
13
+ id: 'get-weather',
14
+ description: 'Get current weather for a location',
15
+ inputSchema: z.object({
16
+ location: z.string().describe('City name'),
17
+ }),
18
+ outputSchema: z.object({
19
+ temperature: z.number(),
20
+ conditions: z.string(),
21
+ location: 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 agent
33
+ const myAgent = new 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: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
41
+ tools: { weatherTool },
42
+ processing: {
43
+ processMentionedMCPs: true, // Auto-add mentioned MCPs as tools
44
+ processRemixPrompt: true, // Use remix prompt to enhance instructions
45
+ processMentionedFiles: true, // Include mentioned file contents
46
+ processMentionedAgents: true // Add mentioned agents as sub-agents
47
+ }
48
+ });
49
+ exports.myAgent = myAgent;
50
+ // Simple CodeBolt integration - no manual saveUserMessage needed!
51
+ codebolt.onMessage(async (reqMessage) => {
52
+ try {
53
+ // codeboltjs automatically saves the user message now!
54
+ // You can access it anytime with codebolt.userMessage.*
55
+ console.log('Current message:', codebolt.userMessage.getText());
56
+ console.log('Mentioned files:', codebolt.userMessage.getMentionedFiles());
57
+ console.log('Mentioned MCPs:', codebolt.userMessage.getMentionedMCPs());
58
+ // Just run the agent - it automatically gets the user context
59
+ const result = await myAgent.run();
60
+ return result.success ? result.message : 'Error occurred';
61
+ }
62
+ catch (error) {
63
+ console.error('Error:', error);
64
+ return 'Sorry, something went wrong.';
65
+ }
66
+ });
67
+ // Example: Multiple agents sharing the same user context
68
+ const researchAgent = new ComposableAgent({
69
+ name: 'Research Agent',
70
+ instructions: 'Research topics and provide detailed information.',
71
+ model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
72
+ processing: { processMentionedFiles: true }
73
+ });
74
+ exports.researchAgent = researchAgent;
75
+ const writingAgent = new ComposableAgent({
76
+ name: 'Writing Agent',
77
+ instructions: 'Write content based on research and requirements.',
78
+ model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
79
+ processing: { processRemixPrompt: true }
80
+ });
81
+ exports.writingAgent = writingAgent;
82
+ // Alternative onMessage handler using multiple agents
83
+ codebolt.onMessage(async (reqMessage) => {
84
+ try {
85
+ // Access user context directly from codebolt
86
+ const messageText = codebolt.userMessage.getText().toLowerCase();
87
+ const hasFiles = codebolt.userMessage.getMentionedFiles().length > 0;
88
+ const hasRemixPrompt = !!codebolt.userMessage.getRemixPrompt();
89
+ let result;
90
+ if (messageText.includes('research') || hasFiles) {
91
+ result = await researchAgent.run();
92
+ }
93
+ else if (messageText.includes('write') || hasRemixPrompt) {
94
+ result = await writingAgent.run();
95
+ }
96
+ else {
97
+ result = await myAgent.run();
98
+ }
99
+ return result.success ? result.message : 'Error occurred';
100
+ }
101
+ catch (error) {
102
+ console.error('Error:', error);
103
+ return 'Sorry, something went wrong.';
104
+ }
105
+ });
106
+ // Example: Using session data for state management
107
+ codebolt.onMessage(async (reqMessage) => {
108
+ try {
109
+ // Store conversation state
110
+ const conversationId = codebolt.userMessage.getThreadId() || 'default';
111
+ const userId = codebolt.userMessage.getMessageId() || 'anonymous';
112
+ // Set session data
113
+ codebolt.userMessage.setSessionData('conversationId', conversationId);
114
+ codebolt.userMessage.setSessionData('userId', userId);
115
+ // Configure processing based on user preferences (could be stored in DB)
116
+ if (userId === 'power-user') {
117
+ codebolt.userMessage.updateProcessingConfig({
118
+ processMentionedMCPs: true,
119
+ processMentionedFiles: true,
120
+ processRemixPrompt: true,
121
+ processMentionedAgents: true
122
+ });
123
+ }
124
+ const result = await myAgent.run();
125
+ // Store result for conversation continuity
126
+ codebolt.userMessage.setSessionData('lastResult', result.message);
127
+ return result.message;
128
+ }
129
+ catch (error) {
130
+ console.error('Error:', error);
131
+ return 'Error processing request';
132
+ }
133
+ });
134
+ // Example: Conditional processing based on message content
135
+ codebolt.onMessage(async (reqMessage) => {
136
+ try {
137
+ const files = codebolt.userMessage.getMentionedFiles();
138
+ const mcps = codebolt.userMessage.getMentionedMCPs();
139
+ // Conditionally update processing config
140
+ if (files.some((f) => f.endsWith('.env') || f.endsWith('.secret'))) {
141
+ // Don't process sensitive files
142
+ codebolt.userMessage.updateProcessingConfig({
143
+ processMentionedFiles: false
144
+ });
145
+ }
146
+ if (mcps.some((mcp) => mcp.toolbox === 'admin')) {
147
+ // Only process admin MCPs for authorized users
148
+ const isAdmin = checkUserPermissions(codebolt.userMessage.getMessageId());
149
+ codebolt.userMessage.updateProcessingConfig({
150
+ processMentionedMCPs: isAdmin
151
+ });
152
+ }
153
+ const result = await myAgent.run();
154
+ return result.message;
155
+ }
156
+ catch (error) {
157
+ console.error('Error:', error);
158
+ return 'Error processing request';
159
+ }
160
+ });
161
+ function checkUserPermissions(userId) {
162
+ // Mock permission check
163
+ return userId === 'admin-user';
164
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview Weather Agent Example
3
+ * @description Example showing how to create a weather agent using the composable pattern
4
+ */
5
+ import { ComposableAgent } from '../index';
6
+ export declare const weatherTool: import("../types").Tool<{
7
+ location: string;
8
+ }, {
9
+ temperature: number;
10
+ feelsLike: number;
11
+ humidity: number;
12
+ windSpeed: number;
13
+ windGust: number;
14
+ conditions: string;
15
+ location: string;
16
+ }>;
17
+ export declare const codeboltagent: ComposableAgent;
18
+ export declare function runWeatherExample(): Promise<import("../types").ExecutionResult>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Weather Agent Example
4
+ * @description Example showing how to create a weather agent using the composable pattern
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.codeboltagent = exports.weatherTool = void 0;
8
+ exports.runWeatherExample = runWeatherExample;
9
+ const index_1 = require("../index");
10
+ // Mock weather function (in real usage, this would call a weather API)
11
+ async function getWeather(location) {
12
+ // This is a mock implementation
13
+ // In real usage, you would call a weather API like OpenWeatherMap
14
+ return {
15
+ temperature: 22,
16
+ feelsLike: 25,
17
+ humidity: 65,
18
+ windSpeed: 10,
19
+ windGust: 15,
20
+ conditions: 'Partly cloudy',
21
+ location: location
22
+ };
23
+ }
24
+ // Create weather tool
25
+ exports.weatherTool = (0, index_1.createTool)({
26
+ id: 'get-weather',
27
+ description: 'Get current weather for a location',
28
+ inputSchema: index_1.z.object({
29
+ location: index_1.z.string().describe('City name'),
30
+ }),
31
+ outputSchema: index_1.z.object({
32
+ temperature: index_1.z.number(),
33
+ feelsLike: index_1.z.number(),
34
+ humidity: index_1.z.number(),
35
+ windSpeed: index_1.z.number(),
36
+ windGust: index_1.z.number(),
37
+ conditions: index_1.z.string(),
38
+ location: index_1.z.string(),
39
+ }),
40
+ execute: async ({ context }) => {
41
+ return await getWeather(context.location);
42
+ },
43
+ });
44
+ // Create agent
45
+ exports.codeboltagent = new index_1.ComposableAgent({
46
+ name: 'Weather Agent',
47
+ instructions: `
48
+ You are a helpful weather assistant that provides accurate weather information and can help planning activities based on the weather.
49
+
50
+ Your primary function is to help users get weather details for specific locations. When responding:
51
+ - Always ask for a location if none is provided
52
+ - If the location name isn't in English, please translate it
53
+ - If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
54
+ - Include relevant details like humidity, wind conditions, and precipitation
55
+ - Keep responses concise but informative
56
+ - If the user asks for activities and provides the weather forecast, suggest activities based on the weather forecast.
57
+ - If the user asks for activities, respond in the format they request.
58
+
59
+ Use the weatherTool to fetch current weather data.
60
+ `,
61
+ model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
62
+ tools: { weatherTool: exports.weatherTool },
63
+ memory: (0, index_1.createCodeBoltDbMemory)(),
64
+ });
65
+ // Example usage
66
+ async function runWeatherExample() {
67
+ try {
68
+ console.log('Running weather agent example...');
69
+ const result = await exports.codeboltagent.execute('What is the weather like in New York?');
70
+ if (result.success) {
71
+ console.log('Agent response:', result.message);
72
+ }
73
+ else {
74
+ console.error('Agent failed:', result.error);
75
+ }
76
+ return result;
77
+ }
78
+ catch (error) {
79
+ console.error('Example failed:', error);
80
+ throw error;
81
+ }
82
+ }
83
+ // Run example if this file is executed directly
84
+ if (require.main === module) {
85
+ runWeatherExample().catch(console.error);
86
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Workflow Examples
3
+ * @description Examples showing how to create and execute workflows with multiple agents
4
+ */
5
+ import { Workflow } from '../workflow';
6
+ export declare const contentCreationWorkflow: Workflow;
7
+ export declare const customerSupportWorkflow: Workflow;
8
+ export declare const dataProcessingWorkflow: Workflow;
9
+ export declare function runContentWorkflowExample(): Promise<import("../workflow").WorkflowResult>;
10
+ export declare function runCustomerSupportExample(): Promise<import("../workflow").WorkflowResult>;
11
+ export declare function runDataProcessingExample(): Promise<import("../workflow").WorkflowResult>;
12
+ export declare function runAllWorkflowExamples(): Promise<void>;