@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,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Documentation Pattern Example
|
|
4
|
+
*
|
|
5
|
+
* This example implements the exact pattern described in the Orchestrator.md documentation
|
|
6
|
+
* showing how agents, workflows, and tools can be used as tools within an orchestrator.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.documentationPatternExample = documentationPatternExample;
|
|
10
|
+
exports.nestedOrchestrationExample = nestedOrchestrationExample;
|
|
11
|
+
exports.agentWorkflowToolAsToolsExample = agentWorkflowToolAsToolsExample;
|
|
12
|
+
exports.runDocumentationPatternExamples = runDocumentationPatternExamples;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const index_1 = require("../index");
|
|
15
|
+
// ================================
|
|
16
|
+
// Documentation Pattern Implementation
|
|
17
|
+
// ================================
|
|
18
|
+
async function documentationPatternExample() {
|
|
19
|
+
console.log('=== Documentation Pattern Example ===');
|
|
20
|
+
console.log('Implementing the exact pattern from Orchestrator.md\n');
|
|
21
|
+
// Create Agent 1 - Research and Text Synthesis
|
|
22
|
+
const agent1 = (0, index_1.createAgent)({
|
|
23
|
+
name: 'Research Agent',
|
|
24
|
+
instructions: 'You are a research specialist focused on gathering information and synthesizing text.',
|
|
25
|
+
description: 'Specializes in research and text synthesis',
|
|
26
|
+
tools: [
|
|
27
|
+
(0, index_1.createTool)({
|
|
28
|
+
id: 'research-city-info',
|
|
29
|
+
name: 'Research City Information',
|
|
30
|
+
description: 'Research comprehensive information about a city',
|
|
31
|
+
inputSchema: zod_1.z.object({
|
|
32
|
+
city: zod_1.z.string(),
|
|
33
|
+
aspects: zod_1.z.array(zod_1.z.string()).optional().default(['demographics', 'economy', 'culture'])
|
|
34
|
+
}),
|
|
35
|
+
execute: async ({ input }) => {
|
|
36
|
+
// Simulate city research
|
|
37
|
+
return {
|
|
38
|
+
city: input.city,
|
|
39
|
+
demographics: `${input.city} has a diverse population with various age groups and backgrounds.`,
|
|
40
|
+
economy: `${input.city}'s economy is driven by multiple sectors including technology and services.`,
|
|
41
|
+
culture: `${input.city} has a rich cultural heritage with numerous attractions and events.`,
|
|
42
|
+
summary: `Comprehensive research completed for ${input.city} covering ${input.aspects.join(', ')}.`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
// Create Agent 2 - Text Processing and Enhancement
|
|
49
|
+
const agent2 = (0, index_1.createAgent)({
|
|
50
|
+
name: 'Text Processing Agent',
|
|
51
|
+
instructions: 'You are a text processing specialist focused on enhancing and refining content.',
|
|
52
|
+
description: 'Specializes in text processing and content enhancement',
|
|
53
|
+
tools: [
|
|
54
|
+
(0, index_1.createTool)({
|
|
55
|
+
id: 'enhance-text',
|
|
56
|
+
name: 'Text Enhancement Tool',
|
|
57
|
+
description: 'Enhance and refine text content',
|
|
58
|
+
inputSchema: zod_1.z.object({
|
|
59
|
+
text: zod_1.z.string(),
|
|
60
|
+
style: zod_1.z.enum(['formal', 'casual', 'academic']).optional().default('formal'),
|
|
61
|
+
length: zod_1.z.enum(['short', 'medium', 'long']).optional().default('medium')
|
|
62
|
+
}),
|
|
63
|
+
execute: async ({ input }) => {
|
|
64
|
+
// Simulate text enhancement
|
|
65
|
+
return {
|
|
66
|
+
originalText: input.text,
|
|
67
|
+
enhancedText: `Enhanced ${input.style} version: ${input.text}`,
|
|
68
|
+
improvements: ['Improved clarity', 'Better structure', 'Enhanced readability'],
|
|
69
|
+
wordCount: input.length === 'short' ? 150 : input.length === 'medium' ? 300 : 500
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
// Create Agent Step 1 - as shown in documentation
|
|
76
|
+
const agentStep1 = (0, index_1.createAgentStep)({
|
|
77
|
+
id: 'agent-step',
|
|
78
|
+
name: 'Research and Text Synthesis Step',
|
|
79
|
+
description: 'This step is used to do research and text synthesis.',
|
|
80
|
+
agent: agent1,
|
|
81
|
+
message: 'Research comprehensive information about {{city}} and synthesize the findings.',
|
|
82
|
+
inputMapping: {
|
|
83
|
+
city: 'city'
|
|
84
|
+
},
|
|
85
|
+
outputMapping: {
|
|
86
|
+
researchResults: 'agentResult.response',
|
|
87
|
+
cityData: 'agentResult.toolResults'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
// Create Agent Step 2 - as shown in documentation
|
|
91
|
+
const agentStep2 = (0, index_1.createAgentStep)({
|
|
92
|
+
id: 'agent-step-two',
|
|
93
|
+
name: 'Text Processing Step',
|
|
94
|
+
description: 'This step is used to process and enhance text.',
|
|
95
|
+
agent: agent2,
|
|
96
|
+
message: 'Process and enhance this text: {{text}}. Make it {{style}} and {{length}}.',
|
|
97
|
+
inputMapping: {
|
|
98
|
+
text: 'researchResults',
|
|
99
|
+
style: 'textStyle',
|
|
100
|
+
length: 'textLength'
|
|
101
|
+
},
|
|
102
|
+
outputMapping: {
|
|
103
|
+
finalText: 'agentResult.response',
|
|
104
|
+
enhancements: 'agentResult.toolResults'
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// Create Workflow 1 - as shown in documentation
|
|
108
|
+
const workflow1Config = {
|
|
109
|
+
name: 'Research and Processing Workflow',
|
|
110
|
+
description: 'Sequential workflow for research and text processing',
|
|
111
|
+
steps: [agentStep1, agentStep2],
|
|
112
|
+
initialData: {
|
|
113
|
+
city: 'San Francisco',
|
|
114
|
+
textStyle: 'formal',
|
|
115
|
+
textLength: 'medium'
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const workflow1 = (0, index_1.createWorkflow)(workflow1Config);
|
|
119
|
+
// Add agents to workflow context
|
|
120
|
+
workflow1.addAgent('agent1', agent1);
|
|
121
|
+
workflow1.addAgent('agent2', agent2);
|
|
122
|
+
// Create Orchestrator - as shown in documentation
|
|
123
|
+
const orchestratorConfig = {
|
|
124
|
+
name: 'Test Network',
|
|
125
|
+
description: 'Test orchestrator network demonstrating the documentation pattern',
|
|
126
|
+
instructions: `You are a test orchestrator that coordinates agents and workflows.
|
|
127
|
+
|
|
128
|
+
Available Resources:
|
|
129
|
+
- agent1: Research and text synthesis specialist
|
|
130
|
+
- agent2: Text processing and enhancement specialist
|
|
131
|
+
- workflow1: Complete research and processing pipeline
|
|
132
|
+
|
|
133
|
+
Decision Logic:
|
|
134
|
+
1. For research tasks → use agent1 or workflow1
|
|
135
|
+
2. For text processing → use agent2 or workflow1
|
|
136
|
+
3. For complete research + processing → use workflow1
|
|
137
|
+
4. Always consider the most efficient resource for the task`,
|
|
138
|
+
agents: {
|
|
139
|
+
agent1,
|
|
140
|
+
agent2
|
|
141
|
+
},
|
|
142
|
+
workflows: {
|
|
143
|
+
workflow1
|
|
144
|
+
},
|
|
145
|
+
limits: {
|
|
146
|
+
maxSteps: 10,
|
|
147
|
+
maxExecutionTime: 300000 // 5 minutes
|
|
148
|
+
},
|
|
149
|
+
decisionConfig: {
|
|
150
|
+
explainDecisions: true,
|
|
151
|
+
confidenceThreshold: 0.7
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const orchestrator = (0, index_1.createOrchestrator)(orchestratorConfig);
|
|
155
|
+
// Create Runtime Context - as shown in documentation
|
|
156
|
+
const runtimeContext = (0, index_1.createRuntimeContext)({
|
|
157
|
+
userId: 'test-user',
|
|
158
|
+
customData: {
|
|
159
|
+
preferences: {
|
|
160
|
+
city: 'New York',
|
|
161
|
+
outputStyle: 'formal',
|
|
162
|
+
outputLength: 'long'
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
// Execute orchestrator loop - as shown in documentation
|
|
167
|
+
console.log('Executing orchestrator loop...');
|
|
168
|
+
const result = await orchestrator.loop('I need comprehensive research about New York City and then process that information into a formal, detailed report.', { runtimeContext });
|
|
169
|
+
console.log('\nOrchestrator execution completed:');
|
|
170
|
+
console.log('Success:', result.success);
|
|
171
|
+
console.log('Total Steps:', result.executionSteps.length);
|
|
172
|
+
console.log('Execution Time:', result.totalExecutionTime, 'ms');
|
|
173
|
+
console.log('Resources Used:');
|
|
174
|
+
console.log(' - Agents:', result.metrics.agentsExecuted);
|
|
175
|
+
console.log(' - Workflows:', result.metrics.workflowsExecuted);
|
|
176
|
+
console.log(' - Tools:', result.metrics.toolsExecuted);
|
|
177
|
+
console.log('\nFinal Response:');
|
|
178
|
+
console.log(result.response.substring(0, 300) + '...');
|
|
179
|
+
// Demonstrate step-by-step execution details
|
|
180
|
+
console.log('\n--- Execution Steps ---');
|
|
181
|
+
result.executionSteps.forEach((step, index) => {
|
|
182
|
+
console.log(`${index + 1}. ${step.stepType.toUpperCase()}: ${step.resourceName}`);
|
|
183
|
+
console.log(` Success: ${step.success}`);
|
|
184
|
+
console.log(` Time: ${step.executionTime}ms`);
|
|
185
|
+
if (step.metadata.reasoning) {
|
|
186
|
+
console.log(` Reasoning: ${step.metadata.reasoning}`);
|
|
187
|
+
}
|
|
188
|
+
console.log('');
|
|
189
|
+
});
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
// ================================
|
|
193
|
+
// Advanced Pattern: Nested Orchestration
|
|
194
|
+
// ================================
|
|
195
|
+
async function nestedOrchestrationExample() {
|
|
196
|
+
console.log('\n=== Nested Orchestration Example ===');
|
|
197
|
+
console.log('Demonstrating orchestrators using other orchestrators as tools\n');
|
|
198
|
+
// Create a specialized sub-orchestrator for content creation
|
|
199
|
+
const contentOrchestrator = (0, index_1.createOrchestrator)({
|
|
200
|
+
name: 'Content Creation Orchestrator',
|
|
201
|
+
instructions: 'You specialize in content creation workflows.',
|
|
202
|
+
agents: {
|
|
203
|
+
writer: (0, index_1.createAgent)({
|
|
204
|
+
name: 'Content Writer',
|
|
205
|
+
instructions: 'You are a skilled content writer.'
|
|
206
|
+
}),
|
|
207
|
+
editor: (0, index_1.createAgent)({
|
|
208
|
+
name: 'Content Editor',
|
|
209
|
+
instructions: 'You are a meticulous content editor.'
|
|
210
|
+
})
|
|
211
|
+
},
|
|
212
|
+
workflows: {}
|
|
213
|
+
});
|
|
214
|
+
// Create a tool that wraps the content orchestrator
|
|
215
|
+
const contentOrchestrationTool = (0, index_1.createTool)({
|
|
216
|
+
id: 'content-orchestrator-tool',
|
|
217
|
+
name: 'Content Creation Orchestrator',
|
|
218
|
+
description: 'Execute content creation using specialized orchestrator',
|
|
219
|
+
inputSchema: zod_1.z.object({
|
|
220
|
+
task: zod_1.z.string(),
|
|
221
|
+
requirements: zod_1.z.array(zod_1.z.string()).optional()
|
|
222
|
+
}),
|
|
223
|
+
execute: async ({ input }) => {
|
|
224
|
+
const result = await contentOrchestrator.loop(input.task);
|
|
225
|
+
return {
|
|
226
|
+
content: result.response,
|
|
227
|
+
success: result.success,
|
|
228
|
+
stepsExecuted: result.executionSteps.length,
|
|
229
|
+
executionTime: result.totalExecutionTime
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
// Create main orchestrator that can use the content orchestrator as a tool
|
|
234
|
+
const mainOrchestrator = (0, index_1.createOrchestrator)({
|
|
235
|
+
name: 'Main Orchestrator',
|
|
236
|
+
instructions: 'You coordinate high-level tasks and can delegate to specialized orchestrators.',
|
|
237
|
+
agents: {
|
|
238
|
+
coordinator: (0, index_1.createAgent)({
|
|
239
|
+
name: 'Task Coordinator',
|
|
240
|
+
instructions: 'You coordinate complex tasks across multiple systems.',
|
|
241
|
+
tools: [contentOrchestrationTool]
|
|
242
|
+
})
|
|
243
|
+
},
|
|
244
|
+
workflows: {},
|
|
245
|
+
tools: {
|
|
246
|
+
'content-orchestrator': contentOrchestrationTool.toOpenAITool()
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
// Test nested orchestration
|
|
250
|
+
const result = await mainOrchestrator.loop('Create a comprehensive blog post about artificial intelligence trends, including research, writing, and editing phases.');
|
|
251
|
+
console.log('Nested orchestration result:');
|
|
252
|
+
console.log('Success:', result.success);
|
|
253
|
+
console.log('Total Steps:', result.executionSteps.length);
|
|
254
|
+
console.log('Response:', result.response.substring(0, 200) + '...');
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
// ================================
|
|
258
|
+
// Pattern: Agents, Workflows, and Tools as Tools
|
|
259
|
+
// ================================
|
|
260
|
+
async function agentWorkflowToolAsToolsExample() {
|
|
261
|
+
console.log('\n=== Agents, Workflows, and Tools as Tools Example ===');
|
|
262
|
+
console.log('Demonstrating how each resource type can be used as a tool\n');
|
|
263
|
+
// 1. Agent as a Tool
|
|
264
|
+
const researchAgent = (0, index_1.createAgent)({
|
|
265
|
+
name: 'Research Specialist',
|
|
266
|
+
instructions: 'You conduct thorough research on any topic.'
|
|
267
|
+
});
|
|
268
|
+
const agentAsTool = researchAgent.toTool();
|
|
269
|
+
console.log('✓ Created agent as tool:', agentAsTool.name);
|
|
270
|
+
// 2. Workflow as a Tool
|
|
271
|
+
const analysisWorkflow = (0, index_1.createWorkflow)({
|
|
272
|
+
name: 'Analysis Pipeline',
|
|
273
|
+
description: 'Complete analysis workflow',
|
|
274
|
+
steps: [
|
|
275
|
+
(0, index_1.createAgentStep)({
|
|
276
|
+
id: 'analyze',
|
|
277
|
+
name: 'Analysis Step',
|
|
278
|
+
agent: researchAgent,
|
|
279
|
+
message: 'Analyze: {{topic}}'
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
});
|
|
283
|
+
const workflowAsTool = (0, index_1.createTool)({
|
|
284
|
+
id: 'analysis-workflow-tool',
|
|
285
|
+
name: 'Analysis Workflow',
|
|
286
|
+
description: 'Execute complete analysis workflow',
|
|
287
|
+
inputSchema: zod_1.z.object({
|
|
288
|
+
topic: zod_1.z.string(),
|
|
289
|
+
depth: zod_1.z.enum(['basic', 'detailed']).optional().default('detailed')
|
|
290
|
+
}),
|
|
291
|
+
execute: async ({ input }) => {
|
|
292
|
+
analysisWorkflow.updateContext({ topic: input.topic, depth: input.depth });
|
|
293
|
+
const result = await analysisWorkflow.execute();
|
|
294
|
+
return {
|
|
295
|
+
analysisResult: result.data,
|
|
296
|
+
success: result.success,
|
|
297
|
+
executionTime: result.executionTime
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
console.log('✓ Created workflow as tool:', workflowAsTool.name);
|
|
302
|
+
// 3. Regular Tool
|
|
303
|
+
const calculatorTool = (0, index_1.createTool)({
|
|
304
|
+
id: 'calculator',
|
|
305
|
+
name: 'Calculator',
|
|
306
|
+
description: 'Perform mathematical calculations',
|
|
307
|
+
inputSchema: zod_1.z.object({
|
|
308
|
+
expression: zod_1.z.string()
|
|
309
|
+
}),
|
|
310
|
+
execute: async ({ input }) => {
|
|
311
|
+
// Simple calculation simulation
|
|
312
|
+
return {
|
|
313
|
+
expression: input.expression,
|
|
314
|
+
result: `Calculated result for: ${input.expression}`,
|
|
315
|
+
timestamp: new Date().toISOString()
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
console.log('✓ Created regular tool:', calculatorTool.name);
|
|
320
|
+
// Create orchestrator that can use all three types as tools
|
|
321
|
+
const multiToolOrchestrator = (0, index_1.createOrchestrator)({
|
|
322
|
+
name: 'Multi-Tool Orchestrator',
|
|
323
|
+
instructions: `You can use various types of tools:
|
|
324
|
+
|
|
325
|
+
1. Agent tools - for complex reasoning and conversation
|
|
326
|
+
2. Workflow tools - for structured multi-step processes
|
|
327
|
+
3. Regular tools - for specific functions
|
|
328
|
+
|
|
329
|
+
Choose the appropriate tool type based on the task complexity and requirements.`,
|
|
330
|
+
agents: {
|
|
331
|
+
coordinator: (0, index_1.createAgent)({
|
|
332
|
+
name: 'Tool Coordinator',
|
|
333
|
+
instructions: 'You coordinate the use of different tool types.',
|
|
334
|
+
tools: [agentAsTool, workflowAsTool, calculatorTool]
|
|
335
|
+
})
|
|
336
|
+
},
|
|
337
|
+
workflows: {},
|
|
338
|
+
tools: {
|
|
339
|
+
'agent-tool': researchAgent.toOpenAITool(),
|
|
340
|
+
'workflow-tool': workflowAsTool.toOpenAITool(),
|
|
341
|
+
'calculator-tool': calculatorTool.toOpenAITool()
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
// Test using different tool types
|
|
345
|
+
const testCases = [
|
|
346
|
+
'Research the latest developments in quantum computing', // Should use agent tool
|
|
347
|
+
'Perform a complete analysis of market trends in renewable energy', // Should use workflow tool
|
|
348
|
+
'Calculate the compound interest for $10,000 at 5% for 10 years' // Should use calculator tool
|
|
349
|
+
];
|
|
350
|
+
const results = [];
|
|
351
|
+
for (const [index, testCase] of testCases.entries()) {
|
|
352
|
+
console.log(`\n--- Test Case ${index + 1}: ${testCase.substring(0, 40)}... ---`);
|
|
353
|
+
const result = await multiToolOrchestrator.loop(testCase);
|
|
354
|
+
console.log('Result:', {
|
|
355
|
+
success: result.success,
|
|
356
|
+
toolsUsed: result.metrics.toolsExecuted,
|
|
357
|
+
agentsUsed: result.metrics.agentsExecuted,
|
|
358
|
+
workflowsUsed: result.metrics.workflowsExecuted
|
|
359
|
+
});
|
|
360
|
+
results.push(result);
|
|
361
|
+
}
|
|
362
|
+
return results;
|
|
363
|
+
}
|
|
364
|
+
// ================================
|
|
365
|
+
// Run All Documentation Pattern Examples
|
|
366
|
+
// ================================
|
|
367
|
+
async function runDocumentationPatternExamples() {
|
|
368
|
+
try {
|
|
369
|
+
console.log('🚀 Starting Documentation Pattern Examples...\n');
|
|
370
|
+
await documentationPatternExample();
|
|
371
|
+
await nestedOrchestrationExample();
|
|
372
|
+
await agentWorkflowToolAsToolsExample();
|
|
373
|
+
console.log('\n✅ All documentation pattern examples completed successfully!');
|
|
374
|
+
console.log('\nKey Patterns Demonstrated:');
|
|
375
|
+
console.log('1. ✓ Agent as a tool');
|
|
376
|
+
console.log('2. ✓ Tool as a tool');
|
|
377
|
+
console.log('3. ✓ Workflow as a tool');
|
|
378
|
+
console.log('4. ✓ Orchestrator coordination');
|
|
379
|
+
console.log('5. ✓ Dynamic resource selection');
|
|
380
|
+
console.log('6. ✓ Nested orchestration');
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
console.error('❌ Documentation pattern example failed:', error);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example demonstrating how to use follow-up conversation processors
|
|
3
|
+
* with the Unified Agent Framework
|
|
4
|
+
*/
|
|
5
|
+
import { ConversationCompactorProcessor } from '../processors';
|
|
6
|
+
import type { CodeboltAPI, OpenAITool } from '../types/libTypes';
|
|
7
|
+
/**
|
|
8
|
+
* Example 1: Basic Follow-Up Processor Usage
|
|
9
|
+
*/
|
|
10
|
+
export declare function basicFollowUpProcessorExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Example 2: Advanced Processor Configuration
|
|
13
|
+
*/
|
|
14
|
+
export declare function advancedFollowUpProcessorExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Example 3: Dynamic Processor Management
|
|
17
|
+
*/
|
|
18
|
+
export declare function dynamicProcessorManagementExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Example 4: Processor Event Monitoring
|
|
21
|
+
*/
|
|
22
|
+
export declare function processorEventMonitoringExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Example 5: Custom Processor Creation
|
|
25
|
+
*/
|
|
26
|
+
export declare class CustomMetricsProcessor extends ConversationCompactorProcessor {
|
|
27
|
+
private metricsCollected;
|
|
28
|
+
processInput(input: any): Promise<any[]>;
|
|
29
|
+
private getAverageProcessingTime;
|
|
30
|
+
getMetrics(): {
|
|
31
|
+
timestamp: string;
|
|
32
|
+
messageCount: number;
|
|
33
|
+
toolCount: number;
|
|
34
|
+
processingTime: number;
|
|
35
|
+
}[];
|
|
36
|
+
}
|
|
37
|
+
export declare function customProcessorExample(codebolt: CodeboltAPI, tools: OpenAITool[]): Promise<{
|
|
38
|
+
result: any;
|
|
39
|
+
metrics: {
|
|
40
|
+
timestamp: string;
|
|
41
|
+
messageCount: number;
|
|
42
|
+
toolCount: number;
|
|
43
|
+
processingTime: number;
|
|
44
|
+
}[];
|
|
45
|
+
}>;
|