agents-library 1.1.0
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.
Potentially problematic release.
This version of agents-library might be problematic. Click here for more details.
- package/dist/base-agent.d.ts +172 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +255 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/base-bot.d.ts +282 -0
- package/dist/base-bot.d.ts.map +1 -0
- package/dist/base-bot.js +375 -0
- package/dist/base-bot.js.map +1 -0
- package/dist/common/result.d.ts +51 -0
- package/dist/common/result.d.ts.map +1 -0
- package/dist/common/result.js +45 -0
- package/dist/common/result.js.map +1 -0
- package/dist/common/types.d.ts +57 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +42 -0
- package/dist/common/types.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/kadi-event-publisher.d.ts +163 -0
- package/dist/kadi-event-publisher.d.ts.map +1 -0
- package/dist/kadi-event-publisher.js +286 -0
- package/dist/kadi-event-publisher.js.map +1 -0
- package/dist/memory/arcadedb-adapter.d.ts +159 -0
- package/dist/memory/arcadedb-adapter.d.ts.map +1 -0
- package/dist/memory/arcadedb-adapter.js +314 -0
- package/dist/memory/arcadedb-adapter.js.map +1 -0
- package/dist/memory/file-storage-adapter.d.ts +122 -0
- package/dist/memory/file-storage-adapter.d.ts.map +1 -0
- package/dist/memory/file-storage-adapter.js +352 -0
- package/dist/memory/file-storage-adapter.js.map +1 -0
- package/dist/memory/memory-service.d.ts +208 -0
- package/dist/memory/memory-service.d.ts.map +1 -0
- package/dist/memory/memory-service.js +410 -0
- package/dist/memory/memory-service.js.map +1 -0
- package/dist/memory/types.d.ts +126 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +41 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/producer-tool-utils.d.ts +474 -0
- package/dist/producer-tool-utils.d.ts.map +1 -0
- package/dist/producer-tool-utils.js +664 -0
- package/dist/producer-tool-utils.js.map +1 -0
- package/dist/providers/anthropic-provider.d.ts +160 -0
- package/dist/providers/anthropic-provider.d.ts.map +1 -0
- package/dist/providers/anthropic-provider.js +527 -0
- package/dist/providers/anthropic-provider.js.map +1 -0
- package/dist/providers/model-manager-provider.d.ts +91 -0
- package/dist/providers/model-manager-provider.d.ts.map +1 -0
- package/dist/providers/model-manager-provider.js +355 -0
- package/dist/providers/model-manager-provider.js.map +1 -0
- package/dist/providers/provider-manager.d.ts +111 -0
- package/dist/providers/provider-manager.d.ts.map +1 -0
- package/dist/providers/provider-manager.js +337 -0
- package/dist/providers/provider-manager.js.map +1 -0
- package/dist/providers/types.d.ts +145 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +23 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/shadow-agent-factory.d.ts +623 -0
- package/dist/shadow-agent-factory.d.ts.map +1 -0
- package/dist/shadow-agent-factory.js +1117 -0
- package/dist/shadow-agent-factory.js.map +1 -0
- package/dist/types/agent-config.d.ts +307 -0
- package/dist/types/agent-config.d.ts.map +1 -0
- package/dist/types/agent-config.js +15 -0
- package/dist/types/agent-config.js.map +1 -0
- package/dist/types/event-schemas.d.ts +358 -0
- package/dist/types/event-schemas.d.ts.map +1 -0
- package/dist/types/event-schemas.js +188 -0
- package/dist/types/event-schemas.js.map +1 -0
- package/dist/types/tool-schemas.d.ts +498 -0
- package/dist/types/tool-schemas.d.ts.map +1 -0
- package/dist/types/tool-schemas.js +457 -0
- package/dist/types/tool-schemas.js.map +1 -0
- package/dist/utils/logger.d.ts +135 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +205 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/timer.d.ts +186 -0
- package/dist/utils/timer.d.ts.map +1 -0
- package/dist/utils/timer.js +211 -0
- package/dist/utils/timer.js.map +1 -0
- package/dist/worker-agent-factory.d.ts +688 -0
- package/dist/worker-agent-factory.d.ts.map +1 -0
- package/dist/worker-agent-factory.js +1517 -0
- package/dist/worker-agent-factory.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Producer Tool Utilities
|
|
3
|
+
* ========================
|
|
4
|
+
*
|
|
5
|
+
* Shared utilities for agent-producer to invoke shrimp-task-manager tools
|
|
6
|
+
* via KĀDI broker protocol with consistent error handling and retry logic.
|
|
7
|
+
*
|
|
8
|
+
* Includes Option C orchestration pattern (Claude API streaming with tool invocation)
|
|
9
|
+
* for agent-producer workflow orchestration.
|
|
10
|
+
*
|
|
11
|
+
* Design Principles:
|
|
12
|
+
* - Standardized error classification for retry logic
|
|
13
|
+
* - Configurable timeout with sensible defaults
|
|
14
|
+
* - Type-safe result handling with discriminated unions
|
|
15
|
+
* - Graceful degradation on failure
|
|
16
|
+
* - Streaming-first architecture with tool interruption support
|
|
17
|
+
*
|
|
18
|
+
* @module producer-tool-utils
|
|
19
|
+
*/
|
|
20
|
+
import { classifyToolError, ErrorType } from './types/tool-schemas.js';
|
|
21
|
+
import { validateTopicPattern } from './kadi-event-publisher.js';
|
|
22
|
+
import { logger, MODULE_AGENT } from './utils/logger.js';
|
|
23
|
+
import { timer } from './utils/timer.js';
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Async Response Manager (Singleton)
|
|
26
|
+
// ============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* Manages pending async tool responses from kadi-broker
|
|
29
|
+
*
|
|
30
|
+
* When a tool returns {status: "pending", requestId: "..."}, this manager
|
|
31
|
+
* subscribes to kadi.ability.response notifications and resolves pending promises.
|
|
32
|
+
*/
|
|
33
|
+
class AsyncResponseManager {
|
|
34
|
+
static instance;
|
|
35
|
+
pendingResponses = new Map();
|
|
36
|
+
subscribed = false;
|
|
37
|
+
constructor() { }
|
|
38
|
+
static getInstance() {
|
|
39
|
+
if (!AsyncResponseManager.instance) {
|
|
40
|
+
AsyncResponseManager.instance = new AsyncResponseManager();
|
|
41
|
+
}
|
|
42
|
+
return AsyncResponseManager.instance;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to kadi.ability.response notifications (once per process)
|
|
46
|
+
*/
|
|
47
|
+
async subscribeToAbilityResponses(client) {
|
|
48
|
+
if (this.subscribed) {
|
|
49
|
+
return; // Already subscribed
|
|
50
|
+
}
|
|
51
|
+
// Subscribe to kadi.ability.response events via kadi-core v0.6.0 subscribe API
|
|
52
|
+
await client.subscribe('kadi.ability.response', (event) => {
|
|
53
|
+
const { requestId, result, error } = event || {};
|
|
54
|
+
const pending = this.pendingResponses.get(requestId);
|
|
55
|
+
if (!pending) {
|
|
56
|
+
// This response is for a different request or already handled
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Clear timeout timer
|
|
60
|
+
clearTimeout(pending.timer);
|
|
61
|
+
this.pendingResponses.delete(requestId);
|
|
62
|
+
// Resolve or reject the promise
|
|
63
|
+
if (error) {
|
|
64
|
+
pending.reject(new Error(`Async tool failed: ${error}`));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
pending.resolve(result);
|
|
68
|
+
}
|
|
69
|
+
}, { broker: 'default' });
|
|
70
|
+
this.subscribed = true;
|
|
71
|
+
logger.info(MODULE_AGENT, 'AsyncResponseManager: Subscribed to kadi.ability.response notifications', timer.elapsed('main'));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Wait for async ability response from kadi-broker
|
|
75
|
+
*/
|
|
76
|
+
waitForResponse(requestId, timeout) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
// Setup timeout
|
|
79
|
+
const timer = setTimeout(() => {
|
|
80
|
+
this.pendingResponses.delete(requestId);
|
|
81
|
+
reject(new Error(`Timeout waiting for async tool result: ${requestId}`));
|
|
82
|
+
}, timeout);
|
|
83
|
+
// Register promise resolver
|
|
84
|
+
this.pendingResponses.set(requestId, {
|
|
85
|
+
resolve,
|
|
86
|
+
reject,
|
|
87
|
+
timer
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Utility Functions
|
|
94
|
+
// ============================================================================
|
|
95
|
+
/**
|
|
96
|
+
* Invoke shrimp-task-manager tool via KĀDI broker protocol
|
|
97
|
+
*
|
|
98
|
+
* Provides consistent error handling, timeout management, and error classification
|
|
99
|
+
* for tools exposed by shrimp-task-manager MCP server. Uses KĀDI protocol.invokeTool()
|
|
100
|
+
* with standardized response handling.
|
|
101
|
+
*
|
|
102
|
+
* Error Classification:
|
|
103
|
+
* - **Transient errors** (retry recommended):
|
|
104
|
+
* - Network errors (ECONNREFUSED, ENOTFOUND)
|
|
105
|
+
* - Timeout errors
|
|
106
|
+
* - Rate limiting (429)
|
|
107
|
+
* - Service unavailable (503)
|
|
108
|
+
*
|
|
109
|
+
* - **Permanent errors** (fail-fast):
|
|
110
|
+
* - Validation errors (400)
|
|
111
|
+
* - Authentication errors (401, 403)
|
|
112
|
+
* - Not found errors (404)
|
|
113
|
+
* - Invalid input errors
|
|
114
|
+
*
|
|
115
|
+
* Response Handling:
|
|
116
|
+
* - Success (200-299): Returns { success: true, data: responseData }
|
|
117
|
+
* - Client error (400-499): Returns { success: false, error: { type: 'permanent', message } }
|
|
118
|
+
* - Server error (500-599): Returns { success: false, error: { type: 'transient', message } }
|
|
119
|
+
* - Network error: Returns { success: false, error: { type: 'transient', message } }
|
|
120
|
+
*
|
|
121
|
+
* @param protocol - KĀDI broker protocol instance (from client.getBrokerProtocol())
|
|
122
|
+
* @param toolName - Name of shrimp tool to invoke (e.g., 'shrimp_plan_task')
|
|
123
|
+
* @param params - Tool input parameters (validated by tool's input schema)
|
|
124
|
+
* @param options - Optional configuration (timeout, targetAgent)
|
|
125
|
+
* @returns Structured result with success flag and data/error
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Success case
|
|
130
|
+
* const result = await invokeShrimTool(
|
|
131
|
+
* protocol,
|
|
132
|
+
* 'shrimp_plan_task',
|
|
133
|
+
* { description: 'Implement feature X', requirements: 'Must be async' }
|
|
134
|
+
* );
|
|
135
|
+
*
|
|
136
|
+
* if (result.success) {
|
|
137
|
+
* console.log('Task planned:', result.data);
|
|
138
|
+
* } else {
|
|
139
|
+
* if (result.error.type === ErrorType.Transient) {
|
|
140
|
+
* // Retry with exponential backoff
|
|
141
|
+
* await retryWithBackoff(() => invokeShrimTool(...));
|
|
142
|
+
* } else {
|
|
143
|
+
* // Fail-fast on permanent errors
|
|
144
|
+
* console.error('Permanent error:', result.error.message);
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // With custom timeout
|
|
152
|
+
* const result = await invokeShrimTool(
|
|
153
|
+
* protocol,
|
|
154
|
+
* 'shrimp_execute_task',
|
|
155
|
+
* { taskId: '123' },
|
|
156
|
+
* { timeout: 60000 } // 60 seconds
|
|
157
|
+
* );
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* // With custom target agent
|
|
163
|
+
* const result = await invokeShrimTool(
|
|
164
|
+
* protocol,
|
|
165
|
+
* 'shrimp_split_tasks',
|
|
166
|
+
* { tasksRaw: JSON.stringify([...]), updateMode: 'append' },
|
|
167
|
+
* { targetAgent: 'mcp-server-shrimp-custom' }
|
|
168
|
+
* );
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export async function invokeShrimTool(protocol, toolName, params, options) {
|
|
172
|
+
// Extract options with defaults
|
|
173
|
+
const timeout = options?.timeout || 30000;
|
|
174
|
+
const targetAgent = options?.targetAgent || 'mcp-server-shrimp-agent-playground';
|
|
175
|
+
const client = options?.client; // KadiClient for async response subscription
|
|
176
|
+
try {
|
|
177
|
+
// Invoke tool via KĀDI protocol
|
|
178
|
+
const response = await protocol.invokeTool({
|
|
179
|
+
targetAgent,
|
|
180
|
+
toolName,
|
|
181
|
+
toolInput: params,
|
|
182
|
+
timeout
|
|
183
|
+
});
|
|
184
|
+
// Check if response is async pending
|
|
185
|
+
if (response && typeof response === 'object' &&
|
|
186
|
+
response.status === 'pending' && response.requestId) {
|
|
187
|
+
console.log(`⏳ Tool is pending, waiting for async result: ${response.requestId}`);
|
|
188
|
+
// Ensure AsyncResponseManager is subscribed (if client provided)
|
|
189
|
+
if (client) {
|
|
190
|
+
const asyncManager = AsyncResponseManager.getInstance();
|
|
191
|
+
asyncManager.subscribeToAbilityResponses(client);
|
|
192
|
+
// Wait for async response
|
|
193
|
+
try {
|
|
194
|
+
const asyncResult = await asyncManager.waitForResponse(response.requestId, timeout);
|
|
195
|
+
console.log(`📤 Async tool result received for ${response.requestId}`);
|
|
196
|
+
// Return the async result
|
|
197
|
+
return {
|
|
198
|
+
success: true,
|
|
199
|
+
data: asyncResult
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error(`❌ Async tool timeout: ${error.message}`);
|
|
204
|
+
return {
|
|
205
|
+
success: false,
|
|
206
|
+
error: {
|
|
207
|
+
type: ErrorType.Transient,
|
|
208
|
+
message: error.message,
|
|
209
|
+
original: error instanceof Error ? error : undefined
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// No client provided - cannot wait for async result
|
|
216
|
+
return {
|
|
217
|
+
success: false,
|
|
218
|
+
error: {
|
|
219
|
+
type: ErrorType.Permanent,
|
|
220
|
+
message: 'Tool returned pending status but no KadiClient provided for async response handling'
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Check response status code (if available)
|
|
226
|
+
// KĀDI protocol returns response with status code and data
|
|
227
|
+
const statusCode = response?.status || response?.statusCode || 200;
|
|
228
|
+
if (statusCode >= 200 && statusCode < 300) {
|
|
229
|
+
// Success response (2xx)
|
|
230
|
+
return {
|
|
231
|
+
success: true,
|
|
232
|
+
data: response?.data || response
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
else if (statusCode >= 400 && statusCode < 500) {
|
|
236
|
+
// Client error (4xx) - permanent error
|
|
237
|
+
return {
|
|
238
|
+
success: false,
|
|
239
|
+
error: {
|
|
240
|
+
type: ErrorType.Permanent,
|
|
241
|
+
message: response?.error || response?.message || `Client error: ${statusCode}`
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
else if (statusCode >= 500 && statusCode < 600) {
|
|
246
|
+
// Server error (5xx) - transient error
|
|
247
|
+
return {
|
|
248
|
+
success: false,
|
|
249
|
+
error: {
|
|
250
|
+
type: ErrorType.Transient,
|
|
251
|
+
message: response?.error || response?.message || `Server error: ${statusCode}`
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// Unknown status code - treat as permanent error
|
|
257
|
+
return {
|
|
258
|
+
success: false,
|
|
259
|
+
error: {
|
|
260
|
+
type: ErrorType.Permanent,
|
|
261
|
+
message: `Unknown status code: ${statusCode}`
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
// Network error, timeout, or other exception
|
|
268
|
+
const classification = classifyToolError(error);
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
error: {
|
|
272
|
+
type: classification.type === 'transient' ? ErrorType.Transient : ErrorType.Permanent,
|
|
273
|
+
message: classification.message,
|
|
274
|
+
original: error instanceof Error ? error : undefined
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Type guard to check if result is a success
|
|
281
|
+
*
|
|
282
|
+
* @param result - Tool invocation result
|
|
283
|
+
* @returns True if result is success
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* if (isToolSuccess(result)) {
|
|
288
|
+
* console.log('Success:', result.data);
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
export function isToolSuccess(result) {
|
|
293
|
+
return result.success === true;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Type guard to check if result is a failure
|
|
297
|
+
*
|
|
298
|
+
* @param result - Tool invocation result
|
|
299
|
+
* @returns True if result is failure
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* if (isToolFailure(result)) {
|
|
304
|
+
* console.error('Failure:', result.error.message);
|
|
305
|
+
* }
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
export function isToolFailure(result) {
|
|
309
|
+
return result.success === false;
|
|
310
|
+
}
|
|
311
|
+
// ============================================================================
|
|
312
|
+
// Orchestration Utility Functions
|
|
313
|
+
// ============================================================================
|
|
314
|
+
/**
|
|
315
|
+
* Orchestrate workflow using Claude API streaming with tool invocation (Option C pattern)
|
|
316
|
+
*
|
|
317
|
+
* Implements agent-producer Option C orchestration flow:
|
|
318
|
+
* 1. Stream Claude API response with tool definitions
|
|
319
|
+
* 2. When Claude requests tool use, pause stream
|
|
320
|
+
* 3. Invoke tool via invokeShrimTool() with KĀDI protocol
|
|
321
|
+
* 4. Resume stream with tool_result
|
|
322
|
+
* 5. Accumulate text blocks for final response
|
|
323
|
+
* 6. Log all tool invocations for debugging
|
|
324
|
+
*
|
|
325
|
+
* Streaming Architecture:
|
|
326
|
+
* - Uses Anthropic SDK streaming API for low-latency responses
|
|
327
|
+
* - Handles streaming interruptions gracefully (tool_use blocks)
|
|
328
|
+
* - Accumulates partial text blocks into final response
|
|
329
|
+
* - Maintains tool invocation log for analysis
|
|
330
|
+
*
|
|
331
|
+
* Error Handling:
|
|
332
|
+
* - Tool invocation failures are passed back to Claude as error tool_result
|
|
333
|
+
* - Stream errors are caught and returned in OrchestrationResult
|
|
334
|
+
* - Graceful degradation if tool invocation fails
|
|
335
|
+
*
|
|
336
|
+
* @param anthropic - Anthropic SDK client instance
|
|
337
|
+
* @param protocol - KĀDI broker protocol instance (from client.getBrokerProtocol())
|
|
338
|
+
* @param prompt - User prompt to send to Claude
|
|
339
|
+
* @param availableTools - Array of tool definitions Claude can use
|
|
340
|
+
* @param options - Optional configuration (max_tokens, temperature, system prompts, etc.)
|
|
341
|
+
* @returns Orchestration result with accumulated text and tool invocation log
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* // Basic usage
|
|
346
|
+
* const result = await orchestrateWithClaude(
|
|
347
|
+
* anthropic,
|
|
348
|
+
* protocol,
|
|
349
|
+
* 'Plan a task to implement feature X',
|
|
350
|
+
* [
|
|
351
|
+
* {
|
|
352
|
+
* name: 'shrimp_plan_task',
|
|
353
|
+
* description: 'Create task plan with requirements',
|
|
354
|
+
* input_schema: {
|
|
355
|
+
* type: 'object',
|
|
356
|
+
* properties: {
|
|
357
|
+
* description: { type: 'string' },
|
|
358
|
+
* requirements: { type: 'string' }
|
|
359
|
+
* },
|
|
360
|
+
* required: ['description']
|
|
361
|
+
* }
|
|
362
|
+
* }
|
|
363
|
+
* ]
|
|
364
|
+
* );
|
|
365
|
+
*
|
|
366
|
+
* if (result.success) {
|
|
367
|
+
* console.log('Claude response:', result.text);
|
|
368
|
+
* console.log('Tools invoked:', result.toolInvocations.length);
|
|
369
|
+
* }
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* // With custom options
|
|
375
|
+
* const result = await orchestrateWithClaude(
|
|
376
|
+
* anthropic,
|
|
377
|
+
* protocol,
|
|
378
|
+
* 'Split tasks for feature implementation',
|
|
379
|
+
* tools,
|
|
380
|
+
* {
|
|
381
|
+
* max_tokens: 16000,
|
|
382
|
+
* temperature: 0.7,
|
|
383
|
+
* system: ['You are a task planning assistant'],
|
|
384
|
+
* toolTimeout: 60000
|
|
385
|
+
* }
|
|
386
|
+
* );
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
export async function orchestrateWithClaude(anthropic, protocol, prompt, availableTools, options) {
|
|
390
|
+
// Extract options with defaults
|
|
391
|
+
const maxTokens = options?.max_tokens || 8000;
|
|
392
|
+
const temperature = options?.temperature || 1.0;
|
|
393
|
+
const system = options?.system || [];
|
|
394
|
+
const model = options?.model || 'claude-sonnet-4-5-20250929';
|
|
395
|
+
const toolTimeout = options?.toolTimeout || 30000;
|
|
396
|
+
const targetAgent = options?.targetAgent || 'mcp-server-shrimp-agent-playground';
|
|
397
|
+
const client = options?.client; // KadiClient for async response handling
|
|
398
|
+
// Initialize result
|
|
399
|
+
const result = {
|
|
400
|
+
text: '',
|
|
401
|
+
toolInvocations: [],
|
|
402
|
+
success: false
|
|
403
|
+
};
|
|
404
|
+
try {
|
|
405
|
+
console.log('🤖 Starting Claude API orchestration...');
|
|
406
|
+
console.log(` Model: ${model}`);
|
|
407
|
+
console.log(` Max tokens: ${maxTokens}`);
|
|
408
|
+
console.log(` Temperature: ${temperature}`);
|
|
409
|
+
console.log(` Available tools: ${availableTools.map(t => t.name).join(', ')}`);
|
|
410
|
+
// Build messages array for Claude API
|
|
411
|
+
const messages = [
|
|
412
|
+
{
|
|
413
|
+
role: 'user',
|
|
414
|
+
content: prompt
|
|
415
|
+
}
|
|
416
|
+
];
|
|
417
|
+
// Orchestration loop - continue until Claude stops requesting tools
|
|
418
|
+
let continueOrchestration = true;
|
|
419
|
+
let iterationCount = 0;
|
|
420
|
+
const maxIterations = 10; // Prevent infinite loops
|
|
421
|
+
while (continueOrchestration && iterationCount < maxIterations) {
|
|
422
|
+
iterationCount++;
|
|
423
|
+
console.log(`\n📡 Orchestration iteration ${iterationCount}/${maxIterations}`);
|
|
424
|
+
// Stream Claude API response
|
|
425
|
+
const stream = await anthropic.messages.stream({
|
|
426
|
+
model,
|
|
427
|
+
max_tokens: maxTokens,
|
|
428
|
+
temperature,
|
|
429
|
+
system: system.length > 0 ? system.join('\n') : undefined,
|
|
430
|
+
messages,
|
|
431
|
+
tools: availableTools.length > 0 ? availableTools : undefined
|
|
432
|
+
});
|
|
433
|
+
// Accumulate content blocks from stream
|
|
434
|
+
let textAccumulator = '';
|
|
435
|
+
const toolUseBlocks = [];
|
|
436
|
+
// Process stream events
|
|
437
|
+
for await (const event of stream) {
|
|
438
|
+
if (event.type === 'content_block_delta') {
|
|
439
|
+
// Handle text delta
|
|
440
|
+
if (event.delta.type === 'text_delta') {
|
|
441
|
+
textAccumulator += event.delta.text;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
else if (event.type === 'content_block_start') {
|
|
445
|
+
// Handle tool use block
|
|
446
|
+
if (event.content_block.type === 'tool_use') {
|
|
447
|
+
console.log(`\n🔧 Claude requested tool: ${event.content_block.name}`);
|
|
448
|
+
toolUseBlocks.push({
|
|
449
|
+
id: event.content_block.id,
|
|
450
|
+
name: event.content_block.name,
|
|
451
|
+
input: event.content_block.input
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// Accumulate text to result
|
|
457
|
+
if (textAccumulator.length > 0) {
|
|
458
|
+
result.text += textAccumulator;
|
|
459
|
+
console.log(`\n📝 Claude response: ${textAccumulator.substring(0, 150)}${textAccumulator.length > 150 ? '...' : ''}`);
|
|
460
|
+
}
|
|
461
|
+
// Check if Claude requested tool use
|
|
462
|
+
if (toolUseBlocks.length > 0) {
|
|
463
|
+
console.log(`\n🛠️ Processing ${toolUseBlocks.length} tool invocation(s)...`);
|
|
464
|
+
// Build tool results for next iteration
|
|
465
|
+
const toolResults = [];
|
|
466
|
+
// Invoke each tool
|
|
467
|
+
for (const toolUse of toolUseBlocks) {
|
|
468
|
+
console.log(`\n → Invoking: ${toolUse.name}`);
|
|
469
|
+
console.log(` Input: ${JSON.stringify(toolUse.input).substring(0, 100)}...`);
|
|
470
|
+
const startTime = Date.now();
|
|
471
|
+
// Invoke tool via invokeShrimTool
|
|
472
|
+
const toolResult = await invokeShrimTool(protocol, toolUse.name, toolUse.input, { timeout: toolTimeout, targetAgent, client });
|
|
473
|
+
const durationMs = Date.now() - startTime;
|
|
474
|
+
// Log tool invocation
|
|
475
|
+
const invocation = {
|
|
476
|
+
toolName: toolUse.name,
|
|
477
|
+
input: toolUse.input,
|
|
478
|
+
result: toolResult,
|
|
479
|
+
timestamp: new Date().toISOString(),
|
|
480
|
+
durationMs
|
|
481
|
+
};
|
|
482
|
+
result.toolInvocations.push(invocation);
|
|
483
|
+
console.log(` ✅ Completed in ${durationMs}ms`);
|
|
484
|
+
console.log(` Success: ${toolResult.success}`);
|
|
485
|
+
// Build tool result for Claude
|
|
486
|
+
if (toolResult.success) {
|
|
487
|
+
toolResults.push({
|
|
488
|
+
type: 'tool_result',
|
|
489
|
+
tool_use_id: toolUse.id,
|
|
490
|
+
content: JSON.stringify(toolResult.data)
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
// Pass error back to Claude
|
|
495
|
+
toolResults.push({
|
|
496
|
+
type: 'tool_result',
|
|
497
|
+
tool_use_id: toolUse.id,
|
|
498
|
+
content: `Error: ${toolResult.error?.message}`,
|
|
499
|
+
is_error: true
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
// Add assistant message with tool use blocks
|
|
504
|
+
messages.push({
|
|
505
|
+
role: 'assistant',
|
|
506
|
+
content: toolUseBlocks.map(tu => ({
|
|
507
|
+
type: 'tool_use',
|
|
508
|
+
id: tu.id,
|
|
509
|
+
name: tu.name,
|
|
510
|
+
input: tu.input
|
|
511
|
+
}))
|
|
512
|
+
});
|
|
513
|
+
// Add user message with tool results
|
|
514
|
+
messages.push({
|
|
515
|
+
role: 'user',
|
|
516
|
+
content: toolResults
|
|
517
|
+
});
|
|
518
|
+
// Continue orchestration loop
|
|
519
|
+
continueOrchestration = true;
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
// No tool use - orchestration complete
|
|
523
|
+
console.log('\n✅ Orchestration complete (no tool use requested)');
|
|
524
|
+
continueOrchestration = false;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (iterationCount >= maxIterations) {
|
|
528
|
+
console.warn('\n⚠️ Orchestration loop exceeded max iterations - stopping');
|
|
529
|
+
result.error = 'Orchestration loop exceeded maximum iterations';
|
|
530
|
+
}
|
|
531
|
+
result.success = true;
|
|
532
|
+
console.log('\n✅ Claude API orchestration succeeded');
|
|
533
|
+
console.log(` Total text length: ${result.text.length} characters`);
|
|
534
|
+
console.log(` Total tool invocations: ${result.toolInvocations.length}`);
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
console.error('\n❌ Claude API orchestration failed');
|
|
539
|
+
console.error(` Error: ${error.message || String(error)}`);
|
|
540
|
+
result.success = false;
|
|
541
|
+
result.error = error.message || String(error);
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
// ============================================================================
|
|
546
|
+
// Event Publishing Utility Functions
|
|
547
|
+
// ============================================================================
|
|
548
|
+
/**
|
|
549
|
+
* Publish standardized tool event to KĀDI broker
|
|
550
|
+
*
|
|
551
|
+
* Creates consistent event structure across all agent-producer tools with
|
|
552
|
+
* required metadata fields (timestamp, agentName, toolName, taskId).
|
|
553
|
+
*
|
|
554
|
+
* Topic Pattern: producer.tool.{eventType}
|
|
555
|
+
* - producer.tool.invoked - Tool invocation started
|
|
556
|
+
* - producer.tool.completed - Tool completed successfully
|
|
557
|
+
* - producer.tool.failed - Tool invocation failed
|
|
558
|
+
*
|
|
559
|
+
* Event Structure:
|
|
560
|
+
* ```typescript
|
|
561
|
+
* {
|
|
562
|
+
* timestamp: string; // ISO 8601 timestamp
|
|
563
|
+
* agentName: string; // 'producer' (default)
|
|
564
|
+
* toolName: string; // Tool that was invoked
|
|
565
|
+
* taskId?: string; // Optional task ID
|
|
566
|
+
* ...data // Additional event data
|
|
567
|
+
* }
|
|
568
|
+
* ```
|
|
569
|
+
*
|
|
570
|
+
* Validation:
|
|
571
|
+
* - Topic pattern validated using validateTopicPattern()
|
|
572
|
+
* - Ensures backward compatibility with existing event conventions
|
|
573
|
+
*
|
|
574
|
+
* Error Handling:
|
|
575
|
+
* - Invalid topic patterns logged as warnings
|
|
576
|
+
* - Publishing failures logged but do not throw
|
|
577
|
+
* - Graceful degradation if broker unavailable
|
|
578
|
+
*
|
|
579
|
+
* @param client - KĀDI client instance (from KadiClient)
|
|
580
|
+
* @param eventType - Event type suffix (e.g., 'invoked', 'completed', 'failed')
|
|
581
|
+
* @param data - Event data payload (will be merged with metadata)
|
|
582
|
+
* @param metadata - Required metadata (toolName, optional taskId, agentName)
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* // Publish tool invocation event
|
|
587
|
+
* await publishToolEvent(
|
|
588
|
+
* client,
|
|
589
|
+
* 'invoked',
|
|
590
|
+
* { input: { description: 'Plan feature X' } },
|
|
591
|
+
* { toolName: 'shrimp_plan_task', taskId: 'task-123' }
|
|
592
|
+
* );
|
|
593
|
+
* // Topic: producer.tool.invoked
|
|
594
|
+
* // Payload: { timestamp, agentName: 'producer', toolName, taskId, input: {...} }
|
|
595
|
+
* ```
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* // Publish tool completion event
|
|
600
|
+
* await publishToolEvent(
|
|
601
|
+
* client,
|
|
602
|
+
* 'completed',
|
|
603
|
+
* { result: { success: true, data: {...} }, durationMs: 1500 },
|
|
604
|
+
* { toolName: 'shrimp_execute_task', taskId: 'task-456' }
|
|
605
|
+
* );
|
|
606
|
+
* // Topic: producer.tool.completed
|
|
607
|
+
* ```
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```typescript
|
|
611
|
+
* // Publish tool failure event
|
|
612
|
+
* await publishToolEvent(
|
|
613
|
+
* client,
|
|
614
|
+
* 'failed',
|
|
615
|
+
* { error: 'Validation failed', errorType: 'permanent' },
|
|
616
|
+
* { toolName: 'shrimp_split_tasks', taskId: 'task-789' }
|
|
617
|
+
* );
|
|
618
|
+
* // Topic: producer.tool.failed
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
export async function publishToolEvent(client, eventType, data, metadata) {
|
|
622
|
+
// Extract metadata with defaults
|
|
623
|
+
const agentName = metadata.agentName || 'producer';
|
|
624
|
+
const toolName = metadata.toolName;
|
|
625
|
+
const taskId = metadata.taskId;
|
|
626
|
+
// Construct topic: producer.tool.{eventType}
|
|
627
|
+
const topic = `producer.tool.${eventType}`;
|
|
628
|
+
// Validate topic pattern
|
|
629
|
+
if (!validateTopicPattern(topic)) {
|
|
630
|
+
console.warn(`⚠️ Invalid topic pattern: ${topic}`);
|
|
631
|
+
console.warn(` Expected format: {platform}.{event_type}.{bot_id}`);
|
|
632
|
+
console.warn(` This may cause routing issues in KĀDI broker`);
|
|
633
|
+
}
|
|
634
|
+
// Build event payload with required metadata
|
|
635
|
+
const eventPayload = {
|
|
636
|
+
timestamp: new Date().toISOString(),
|
|
637
|
+
agentName,
|
|
638
|
+
toolName,
|
|
639
|
+
...(taskId ? { taskId } : {}),
|
|
640
|
+
...data
|
|
641
|
+
};
|
|
642
|
+
try {
|
|
643
|
+
console.log(`📤 Publishing tool event`);
|
|
644
|
+
console.log(` Topic: ${topic}`);
|
|
645
|
+
console.log(` Tool: ${toolName}`);
|
|
646
|
+
if (taskId) {
|
|
647
|
+
console.log(` Task ID: ${taskId}`);
|
|
648
|
+
}
|
|
649
|
+
console.log(` Event type: ${eventType}`);
|
|
650
|
+
console.log(` Payload keys: ${Object.keys(eventPayload).join(', ')}`);
|
|
651
|
+
// Publish event to KĀDI broker
|
|
652
|
+
await client.publish(topic, eventPayload, { broker: 'default', network: 'global' });
|
|
653
|
+
console.log(` ✅ Event published successfully`);
|
|
654
|
+
}
|
|
655
|
+
catch (error) {
|
|
656
|
+
// Log error but don't throw - graceful degradation
|
|
657
|
+
console.error(`❌ Failed to publish tool event (non-fatal)`);
|
|
658
|
+
console.error(` Topic: ${topic}`);
|
|
659
|
+
console.error(` Tool: ${toolName}`);
|
|
660
|
+
console.error(` Error: ${error.message || String(error)}`);
|
|
661
|
+
// Don't throw - event publishing failure should not crash tool execution
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
//# sourceMappingURL=producer-tool-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"producer-tool-utils.js","sourceRoot":"","sources":["../src/producer-tool-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,+EAA+E;AAC/E,qCAAqC;AACrC,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAM,oBAAoB;IAChB,MAAM,CAAC,QAAQ,CAAuB;IACtC,gBAAgB,GAAG,IAAI,GAAG,EAI9B,CAAC;IACG,UAAU,GAAG,KAAK,CAAC;IAE3B,gBAAuB,CAAC;IAExB,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC;YACnC,oBAAoB,CAAC,QAAQ,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC7D,CAAC;QACD,OAAO,oBAAoB,CAAC,QAAQ,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,2BAA2B,CAAC,MAAkB;QAClD,IAAI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