@codebolt/agent 2.2.2 ā 2.2.3
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/dist/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +6 -1
- package/dist/composablepattern/document.js +2 -35
- package/dist/local-tools/fileTools.d.ts +26 -0
- package/dist/local-tools/fileTools.js +162 -0
- package/dist/processor/types/interfaces.d.ts +44 -21
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
- package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
- package/dist/processor-pieces/additionalModifiers/index.js +28 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
- package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
- package/dist/processor-pieces/preToolCall/index.js +18 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/tool.d.ts +99 -0
- package/dist/unified/agent/tool.js +440 -0
- package/dist/unified/base/initialPromptGenerator.js +5 -5
- package/dist/unified/base/responseExecutor.js +6 -6
- package/dist/unified/examples/agentExample.d.ts +46 -0
- package/dist/unified/examples/agentExample.js +464 -0
- package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
- package/dist/unified/examples/documentationPatternExample.js +385 -0
- package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
- package/dist/unified/examples/followUpProcessorsExample.js +311 -0
- package/dist/unified/examples/orchestratorExample.d.ts +16 -0
- package/dist/unified/examples/orchestratorExample.js +415 -0
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
- package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
- package/dist/unified/examples/workflowExample.d.ts +12 -0
- package/dist/unified/examples/workflowExample.js +497 -0
- package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
- package/dist/unified/orchestrator/orchestrator.js +519 -0
- package/package.json +15 -15
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/followupquestionbuilder.d.ts +0 -75
- package/dist/followupquestionbuilder.js +0 -197
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -23
- package/dist/llmoutputhandler.d.ts +0 -102
- package/dist/llmoutputhandler.js +0 -452
- package/dist/promptbuilder.d.ts +0 -382
- package/dist/promptbuilder.js +0 -805
- package/dist/systemprompt.d.ts +0 -20
- package/dist/systemprompt.js +0 -48
- package/dist/taskInstruction.d.ts +0 -37
- package/dist/taskInstruction.js +0 -57
- package/dist/usermessage.d.ts +0 -70
- package/dist/usermessage.js +0 -123
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Orchestrator Pattern Example for Unified Agent Framework
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates how to create and use an orchestrator that can
|
|
6
|
+
* dynamically coordinate agents, workflows, and tools based on the pattern
|
|
7
|
+
* described in the documentation.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.runOrchestratorExamples = runOrchestratorExamples;
|
|
11
|
+
exports.orchestratorPatternExample = orchestratorPatternExample;
|
|
12
|
+
exports.dynamicResourceSelectionExample = dynamicResourceSelectionExample;
|
|
13
|
+
exports.orchestratorAsToolExample = orchestratorAsToolExample;
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const index_1 = require("../index");
|
|
16
|
+
// ================================
|
|
17
|
+
// Example: Multi-Resource Orchestration
|
|
18
|
+
// ================================
|
|
19
|
+
async function orchestratorPatternExample() {
|
|
20
|
+
console.log('=== Orchestrator Pattern Example ===');
|
|
21
|
+
// Create Agent 1: Research Agent
|
|
22
|
+
const agent1 = (0, index_1.createAgent)({
|
|
23
|
+
name: 'Research Agent',
|
|
24
|
+
instructions: 'You are a research specialist. Gather and synthesize information on given topics.',
|
|
25
|
+
description: 'Specializes in research and information synthesis',
|
|
26
|
+
tools: [
|
|
27
|
+
(0, index_1.createTool)({
|
|
28
|
+
id: 'research-tool',
|
|
29
|
+
name: 'Research Tool',
|
|
30
|
+
description: 'Conduct research on a given topic',
|
|
31
|
+
inputSchema: zod_1.z.object({
|
|
32
|
+
topic: zod_1.z.string(),
|
|
33
|
+
depth: zod_1.z.enum(['basic', 'detailed', 'comprehensive']).optional().default('detailed')
|
|
34
|
+
}),
|
|
35
|
+
execute: async ({ input }) => {
|
|
36
|
+
// Simulate research
|
|
37
|
+
return {
|
|
38
|
+
findings: `Comprehensive research on ${input.topic}`,
|
|
39
|
+
sources: ['Source 1', 'Source 2', 'Source 3'],
|
|
40
|
+
confidence: 0.85,
|
|
41
|
+
summary: `Key insights about ${input.topic} based on current research.`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
// Create Agent 2: Analysis Agent
|
|
48
|
+
const agent2 = (0, index_1.createAgent)({
|
|
49
|
+
name: 'Analysis Agent',
|
|
50
|
+
instructions: 'You are an analytical expert. Analyze data and provide insights.',
|
|
51
|
+
description: 'Specializes in data analysis and insight generation',
|
|
52
|
+
tools: [
|
|
53
|
+
(0, index_1.createTool)({
|
|
54
|
+
id: 'analysis-tool',
|
|
55
|
+
name: 'Analysis Tool',
|
|
56
|
+
description: 'Analyze data and generate insights',
|
|
57
|
+
inputSchema: zod_1.z.object({
|
|
58
|
+
data: zod_1.z.string(),
|
|
59
|
+
analysisType: zod_1.z.enum(['trend', 'pattern', 'correlation']).optional().default('trend')
|
|
60
|
+
}),
|
|
61
|
+
execute: async ({ input }) => {
|
|
62
|
+
// Simulate analysis
|
|
63
|
+
return {
|
|
64
|
+
insights: `Analysis reveals key trends in: ${input.data}`,
|
|
65
|
+
metrics: { accuracy: 0.92, relevance: 0.88 },
|
|
66
|
+
recommendations: ['Recommendation 1', 'Recommendation 2']
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
// Create Workflow 1: Research and Analysis Pipeline
|
|
73
|
+
const workflow1Config = {
|
|
74
|
+
name: 'Research and Analysis Pipeline',
|
|
75
|
+
description: 'Comprehensive research followed by detailed analysis',
|
|
76
|
+
steps: [
|
|
77
|
+
(0, index_1.createAgentStep)({
|
|
78
|
+
id: 'research-step',
|
|
79
|
+
name: 'Research Phase',
|
|
80
|
+
description: 'Conduct initial research',
|
|
81
|
+
agent: 'research-agent', // Reference by ID
|
|
82
|
+
message: 'Research the topic: {{topic}} with {{depth}} level of detail',
|
|
83
|
+
outputMapping: {
|
|
84
|
+
researchFindings: 'agentResult.response',
|
|
85
|
+
researchData: 'agentResult.toolResults'
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
(0, index_1.createTransformStep)({
|
|
89
|
+
id: 'prepare-analysis',
|
|
90
|
+
name: 'Prepare Analysis Data',
|
|
91
|
+
description: 'Transform research data for analysis',
|
|
92
|
+
transform: (data) => ({
|
|
93
|
+
analysisInput: `Research findings: ${data.researchFindings}`,
|
|
94
|
+
analysisType: 'trend'
|
|
95
|
+
})
|
|
96
|
+
}),
|
|
97
|
+
(0, index_1.createAgentStep)({
|
|
98
|
+
id: 'analysis-step',
|
|
99
|
+
name: 'Analysis Phase',
|
|
100
|
+
description: 'Analyze research findings',
|
|
101
|
+
agent: 'analysis-agent', // Reference by ID
|
|
102
|
+
message: 'Analyze this data: {{analysisInput}} using {{analysisType}} analysis',
|
|
103
|
+
outputMapping: {
|
|
104
|
+
finalInsights: 'agentResult.response',
|
|
105
|
+
analysisMetrics: 'agentResult.toolResults'
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
],
|
|
109
|
+
initialData: {
|
|
110
|
+
topic: 'Artificial Intelligence Trends',
|
|
111
|
+
depth: 'comprehensive'
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const workflow1 = (0, index_1.createWorkflow)(workflow1Config);
|
|
115
|
+
// Add agents to workflow context
|
|
116
|
+
workflow1.addAgent('research-agent', agent1);
|
|
117
|
+
workflow1.addAgent('analysis-agent', agent2);
|
|
118
|
+
// Create standalone tools
|
|
119
|
+
const summaryTool = (0, index_1.createTool)({
|
|
120
|
+
id: 'summary-tool',
|
|
121
|
+
name: 'Summary Generator',
|
|
122
|
+
description: 'Generate executive summaries',
|
|
123
|
+
inputSchema: zod_1.z.object({
|
|
124
|
+
content: zod_1.z.string(),
|
|
125
|
+
length: zod_1.z.enum(['short', 'medium', 'long']).optional().default('medium')
|
|
126
|
+
}),
|
|
127
|
+
execute: async ({ input }) => {
|
|
128
|
+
return {
|
|
129
|
+
summary: `Executive summary of: ${input.content.substring(0, 100)}...`,
|
|
130
|
+
keyPoints: ['Point 1', 'Point 2', 'Point 3'],
|
|
131
|
+
wordCount: input.length === 'short' ? 150 : input.length === 'medium' ? 300 : 500
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const reportTool = (0, index_1.createTool)({
|
|
136
|
+
id: 'report-generator',
|
|
137
|
+
name: 'Report Generator',
|
|
138
|
+
description: 'Generate formatted reports',
|
|
139
|
+
inputSchema: zod_1.z.object({
|
|
140
|
+
data: zod_1.z.record(zod_1.z.unknown()),
|
|
141
|
+
format: zod_1.z.enum(['pdf', 'html', 'markdown']).optional().default('markdown')
|
|
142
|
+
}),
|
|
143
|
+
execute: async ({ input }) => {
|
|
144
|
+
return {
|
|
145
|
+
report: `# Generated Report\n\nData: ${JSON.stringify(input.data, null, 2)}`,
|
|
146
|
+
format: input.format,
|
|
147
|
+
generatedAt: new Date().toISOString()
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
// Create Orchestrator Configuration
|
|
152
|
+
const orchestratorConfig = {
|
|
153
|
+
name: 'Multi-Resource Orchestrator',
|
|
154
|
+
description: 'Orchestrates agents, workflows, and tools dynamically',
|
|
155
|
+
instructions: `You are an intelligent orchestrator that can coordinate multiple resources:
|
|
156
|
+
|
|
157
|
+
AVAILABLE RESOURCES:
|
|
158
|
+
- Agents: agent1 (research), agent2 (analysis)
|
|
159
|
+
- Workflows: workflow1 (research and analysis pipeline)
|
|
160
|
+
- Tools: summary-tool, report-generator
|
|
161
|
+
|
|
162
|
+
DECISION MAKING:
|
|
163
|
+
1. For research tasks ā use agent1 or workflow1
|
|
164
|
+
2. For analysis tasks ā use agent2 or workflow1
|
|
165
|
+
3. For summarization ā use summary-tool
|
|
166
|
+
4. For report generation ā use report-generator
|
|
167
|
+
5. For complex multi-step processes ā use workflow1
|
|
168
|
+
|
|
169
|
+
Always consider:
|
|
170
|
+
- What the user is asking for
|
|
171
|
+
- What resources are best suited
|
|
172
|
+
- Whether a workflow or individual agents/tools are more appropriate
|
|
173
|
+
- The current context and previous executions
|
|
174
|
+
|
|
175
|
+
Make intelligent decisions about resource selection and execution order.`,
|
|
176
|
+
agents: {
|
|
177
|
+
agent1,
|
|
178
|
+
agent2
|
|
179
|
+
},
|
|
180
|
+
workflows: {
|
|
181
|
+
workflow1
|
|
182
|
+
},
|
|
183
|
+
tools: {
|
|
184
|
+
'summary-tool': summaryTool,
|
|
185
|
+
'report-generator': reportTool
|
|
186
|
+
},
|
|
187
|
+
limits: {
|
|
188
|
+
maxSteps: 10,
|
|
189
|
+
maxExecutionTime: 300000 // 5 minutes
|
|
190
|
+
},
|
|
191
|
+
decisionConfig: {
|
|
192
|
+
explainDecisions: true,
|
|
193
|
+
confidenceThreshold: 0.7,
|
|
194
|
+
askConfirmation: false
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
// Create the orchestrator
|
|
198
|
+
const orchestrator = (0, index_1.createOrchestrator)(orchestratorConfig);
|
|
199
|
+
// Create runtime context
|
|
200
|
+
const runtimeContext = (0, index_1.createRuntimeContext)({
|
|
201
|
+
userId: 'user123',
|
|
202
|
+
customData: {
|
|
203
|
+
userPreferences: {
|
|
204
|
+
reportFormat: 'markdown',
|
|
205
|
+
summaryLength: 'medium'
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
console.log('Starting orchestration...');
|
|
210
|
+
// Test Case 1: Simple research request
|
|
211
|
+
console.log('\n--- Test Case 1: Research Request ---');
|
|
212
|
+
const result1 = await orchestrator.loop('I need comprehensive research on emerging AI technologies in healthcare', { runtimeContext });
|
|
213
|
+
console.log('Research orchestration result:', {
|
|
214
|
+
success: result1.success,
|
|
215
|
+
steps: result1.executionSteps.length,
|
|
216
|
+
response: result1.response.substring(0, 200) + '...',
|
|
217
|
+
metrics: result1.metrics
|
|
218
|
+
});
|
|
219
|
+
// Test Case 2: Complex multi-step request
|
|
220
|
+
console.log('\n--- Test Case 2: Complex Multi-Step Request ---');
|
|
221
|
+
const result2 = await orchestrator.loop('Research AI in finance, analyze the trends, and generate a comprehensive report with executive summary', { runtimeContext: (0, index_1.createRuntimeContext)() });
|
|
222
|
+
console.log('Complex orchestration result:', {
|
|
223
|
+
success: result2.success,
|
|
224
|
+
steps: result2.executionSteps.length,
|
|
225
|
+
response: result2.response.substring(0, 200) + '...',
|
|
226
|
+
resourcesUsed: {
|
|
227
|
+
agents: result2.metrics.agentsExecuted,
|
|
228
|
+
workflows: result2.metrics.workflowsExecuted,
|
|
229
|
+
tools: result2.metrics.toolsExecuted
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
// Test Case 3: Workflow-specific request
|
|
233
|
+
console.log('\n--- Test Case 3: Workflow Request ---');
|
|
234
|
+
const result3 = await orchestrator.loop('Run the research and analysis workflow for blockchain technology', { runtimeContext: (0, index_1.createRuntimeContext)() });
|
|
235
|
+
console.log('Workflow orchestration result:', {
|
|
236
|
+
success: result3.success,
|
|
237
|
+
steps: result3.executionSteps.length,
|
|
238
|
+
workflowsExecuted: result3.metrics.workflowsExecuted,
|
|
239
|
+
averageConfidence: result3.metrics.averageConfidence
|
|
240
|
+
});
|
|
241
|
+
return { result1, result2, result3 };
|
|
242
|
+
}
|
|
243
|
+
// ================================
|
|
244
|
+
// Example: Dynamic Resource Selection
|
|
245
|
+
// ================================
|
|
246
|
+
async function dynamicResourceSelectionExample() {
|
|
247
|
+
console.log('\n=== Dynamic Resource Selection Example ===');
|
|
248
|
+
// Create specialized agents for different domains
|
|
249
|
+
const techAgent = (0, index_1.createAgent)({
|
|
250
|
+
name: 'Technology Expert',
|
|
251
|
+
instructions: 'You are a technology expert specializing in software, hardware, and emerging tech.',
|
|
252
|
+
tools: []
|
|
253
|
+
});
|
|
254
|
+
const businessAgent = (0, index_1.createAgent)({
|
|
255
|
+
name: 'Business Strategist',
|
|
256
|
+
instructions: 'You are a business strategist focusing on market analysis and strategic planning.',
|
|
257
|
+
tools: []
|
|
258
|
+
});
|
|
259
|
+
const creativeAgent = (0, index_1.createAgent)({
|
|
260
|
+
name: 'Creative Director',
|
|
261
|
+
instructions: 'You are a creative director specializing in content creation and design.',
|
|
262
|
+
tools: []
|
|
263
|
+
});
|
|
264
|
+
// Create domain-specific workflows
|
|
265
|
+
const techWorkflow = (0, index_1.createWorkflow)({
|
|
266
|
+
name: 'Technology Assessment',
|
|
267
|
+
description: 'Comprehensive technology evaluation workflow',
|
|
268
|
+
steps: [
|
|
269
|
+
(0, index_1.createAgentStep)({
|
|
270
|
+
id: 'tech-analysis',
|
|
271
|
+
name: 'Technology Analysis',
|
|
272
|
+
agent: techAgent,
|
|
273
|
+
message: 'Analyze the technology: {{topic}} from technical feasibility perspective'
|
|
274
|
+
})
|
|
275
|
+
]
|
|
276
|
+
});
|
|
277
|
+
const businessWorkflow = (0, index_1.createWorkflow)({
|
|
278
|
+
name: 'Business Analysis',
|
|
279
|
+
description: 'Business impact and market analysis workflow',
|
|
280
|
+
steps: [
|
|
281
|
+
(0, index_1.createAgentStep)({
|
|
282
|
+
id: 'business-analysis',
|
|
283
|
+
name: 'Business Analysis',
|
|
284
|
+
agent: businessAgent,
|
|
285
|
+
message: 'Analyze the business implications of: {{topic}}'
|
|
286
|
+
})
|
|
287
|
+
]
|
|
288
|
+
});
|
|
289
|
+
// Smart orchestrator that selects resources based on context
|
|
290
|
+
const smartOrchestrator = (0, index_1.createOrchestrator)({
|
|
291
|
+
name: 'Smart Domain Orchestrator',
|
|
292
|
+
instructions: `You are a smart orchestrator that selects the most appropriate resources based on the domain and context of the user's request.
|
|
293
|
+
|
|
294
|
+
DOMAIN DETECTION:
|
|
295
|
+
- Technology-related queries ā use techAgent or techWorkflow
|
|
296
|
+
- Business-related queries ā use businessAgent or businessWorkflow
|
|
297
|
+
- Creative-related queries ā use creativeAgent
|
|
298
|
+
- Multi-domain queries ā use multiple agents/workflows
|
|
299
|
+
|
|
300
|
+
RESOURCE SELECTION LOGIC:
|
|
301
|
+
1. Analyze the user's request to identify the primary domain(s)
|
|
302
|
+
2. Select the most appropriate agent(s) or workflow(s)
|
|
303
|
+
3. For complex requests, coordinate multiple resources
|
|
304
|
+
4. Always explain your resource selection reasoning`,
|
|
305
|
+
agents: {
|
|
306
|
+
techAgent,
|
|
307
|
+
businessAgent,
|
|
308
|
+
creativeAgent
|
|
309
|
+
},
|
|
310
|
+
workflows: {
|
|
311
|
+
techWorkflow,
|
|
312
|
+
businessWorkflow
|
|
313
|
+
},
|
|
314
|
+
decisionConfig: {
|
|
315
|
+
explainDecisions: true,
|
|
316
|
+
confidenceThreshold: 0.6
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
// Test different types of requests
|
|
320
|
+
const testCases = [
|
|
321
|
+
'Evaluate the technical feasibility of implementing blockchain in our supply chain',
|
|
322
|
+
'What are the market opportunities for AI-powered customer service tools?',
|
|
323
|
+
'Create a creative campaign concept for our new mobile app launch',
|
|
324
|
+
'Analyze both the technical and business aspects of adopting cloud-native architecture'
|
|
325
|
+
];
|
|
326
|
+
const results = [];
|
|
327
|
+
for (const [index, testCase] of testCases.entries()) {
|
|
328
|
+
console.log(`\n--- Test Case ${index + 1}: ${testCase.substring(0, 50)}... ---`);
|
|
329
|
+
const result = await smartOrchestrator.loop(testCase, {
|
|
330
|
+
runtimeContext: (0, index_1.createRuntimeContext)()
|
|
331
|
+
});
|
|
332
|
+
console.log('Result:', {
|
|
333
|
+
success: result.success,
|
|
334
|
+
resourcesUsed: {
|
|
335
|
+
agents: result.metrics.agentsExecuted,
|
|
336
|
+
workflows: result.metrics.workflowsExecuted
|
|
337
|
+
},
|
|
338
|
+
confidence: result.metrics.averageConfidence,
|
|
339
|
+
executionTime: result.totalExecutionTime
|
|
340
|
+
});
|
|
341
|
+
results.push(result);
|
|
342
|
+
}
|
|
343
|
+
return results;
|
|
344
|
+
}
|
|
345
|
+
// ================================
|
|
346
|
+
// Example: Orchestrator as a Tool
|
|
347
|
+
// ================================
|
|
348
|
+
async function orchestratorAsToolExample() {
|
|
349
|
+
var _a;
|
|
350
|
+
console.log('\n=== Orchestrator as Tool Example ===');
|
|
351
|
+
// Create a simple orchestrator
|
|
352
|
+
const subOrchestrator = (0, index_1.createOrchestrator)({
|
|
353
|
+
name: 'Sub-Orchestrator',
|
|
354
|
+
instructions: 'You coordinate research and analysis tasks.',
|
|
355
|
+
agents: {
|
|
356
|
+
researcher: (0, index_1.createAgent)({
|
|
357
|
+
name: 'Researcher',
|
|
358
|
+
instructions: 'Conduct research on given topics.'
|
|
359
|
+
}),
|
|
360
|
+
analyzer: (0, index_1.createAgent)({
|
|
361
|
+
name: 'Analyzer',
|
|
362
|
+
instructions: 'Analyze research data and provide insights.'
|
|
363
|
+
})
|
|
364
|
+
},
|
|
365
|
+
workflows: {}
|
|
366
|
+
});
|
|
367
|
+
// Create a tool that wraps the orchestrator
|
|
368
|
+
const orchestratorTool = (0, index_1.createTool)({
|
|
369
|
+
id: 'research-orchestrator',
|
|
370
|
+
name: 'Research Orchestrator',
|
|
371
|
+
description: 'Orchestrate research and analysis using multiple agents',
|
|
372
|
+
inputSchema: zod_1.z.object({
|
|
373
|
+
task: zod_1.z.string(),
|
|
374
|
+
requirements: zod_1.z.array(zod_1.z.string()).optional()
|
|
375
|
+
}),
|
|
376
|
+
execute: async ({ input }) => {
|
|
377
|
+
const result = await subOrchestrator.loop(input.task);
|
|
378
|
+
return {
|
|
379
|
+
orchestrationResult: result.response,
|
|
380
|
+
stepsExecuted: result.executionSteps.length,
|
|
381
|
+
success: result.success,
|
|
382
|
+
metrics: result.metrics
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
// Create a main agent that can use the orchestrator as a tool
|
|
387
|
+
const mainAgent = (0, index_1.createAgent)({
|
|
388
|
+
name: 'Main Coordinator',
|
|
389
|
+
instructions: 'You are a main coordinator that can delegate complex tasks to specialized orchestrators.',
|
|
390
|
+
tools: [orchestratorTool]
|
|
391
|
+
});
|
|
392
|
+
// Test using orchestrator as a tool
|
|
393
|
+
const result = await mainAgent.execute('I need a comprehensive analysis of renewable energy trends. Use the research orchestrator to coordinate this task.');
|
|
394
|
+
console.log('Orchestrator as tool result:', {
|
|
395
|
+
success: result.success,
|
|
396
|
+
response: result.response.substring(0, 300) + '...',
|
|
397
|
+
toolsUsed: ((_a = result.toolResults) === null || _a === void 0 ? void 0 : _a.length) || 0
|
|
398
|
+
});
|
|
399
|
+
return result;
|
|
400
|
+
}
|
|
401
|
+
// ================================
|
|
402
|
+
// Run All Examples
|
|
403
|
+
// ================================
|
|
404
|
+
async function runOrchestratorExamples() {
|
|
405
|
+
try {
|
|
406
|
+
console.log('š Starting Orchestrator Examples...\n');
|
|
407
|
+
await orchestratorPatternExample();
|
|
408
|
+
await dynamicResourceSelectionExample();
|
|
409
|
+
await orchestratorAsToolExample();
|
|
410
|
+
console.log('\nā
All orchestrator examples completed successfully!');
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
console.error('ā Orchestrator example failed:', error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example demonstrating how to use pre-tool call processors
|
|
3
|
+
* with the Unified Agent Framework
|
|
4
|
+
*/
|
|
5
|
+
import { LocalToolInterceptorProcessor } from '../processors';
|
|
6
|
+
import type { CodeboltAPI, OpenAITool } from '../types/libTypes';
|
|
7
|
+
/**
|
|
8
|
+
* Example 1: Basic Local Tool Interception
|
|
9
|
+
*/
|
|
10
|
+
export declare function basicLocalToolInterceptionExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Example 2: Tool Validation and Parameter Modification
|
|
13
|
+
*/
|
|
14
|
+
export declare function toolValidationAndModificationExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Example 3: Advanced Local Tool Handling with Custom Business Logic
|
|
17
|
+
*/
|
|
18
|
+
export declare function advancedLocalToolHandlingExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Example 4: Dynamic Processor Management
|
|
21
|
+
*/
|
|
22
|
+
export declare function dynamicProcessorManagementExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Example 5: Custom Processor with Monitoring
|
|
25
|
+
*/
|
|
26
|
+
export declare class CustomToolMonitoringProcessor extends LocalToolInterceptorProcessor {
|
|
27
|
+
private toolExecutionMetrics;
|
|
28
|
+
processInput(input: any): Promise<any[]>;
|
|
29
|
+
private updateMetrics;
|
|
30
|
+
private getToolMetrics;
|
|
31
|
+
getAllMetrics(): Record<string, any>;
|
|
32
|
+
}
|
|
33
|
+
export declare function customMonitoringProcessorExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<{
|
|
34
|
+
result: any;
|
|
35
|
+
metrics: Record<string, any>;
|
|
36
|
+
}>;
|