@iqai/adk 0.0.6 → 0.0.7
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/CHANGELOG.md +2 -8
- package/README.md +177 -0
- package/dist/index.d.mts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.js +440 -364
- package/dist/index.mjs +257 -181
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -19,27 +19,47 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
};
|
|
20
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
21
|
|
|
22
|
-
// src/helpers/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
// src/helpers/logger.ts
|
|
23
|
+
function isDebugEnabled() {
|
|
24
|
+
return process.env.NODE_ENV === "development" || process.env.DEBUG === "true";
|
|
25
|
+
}
|
|
26
|
+
var Logger;
|
|
27
|
+
var init_logger = __esm({
|
|
28
|
+
"src/helpers/logger.ts"() {
|
|
29
|
+
Logger = class {
|
|
30
|
+
name;
|
|
31
|
+
isDebugEnabled = isDebugEnabled();
|
|
32
|
+
constructor({ name }) {
|
|
33
|
+
this.name = name;
|
|
34
|
+
}
|
|
35
|
+
debug(message, ...args) {
|
|
36
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
37
|
+
if (this.isDebugEnabled) {
|
|
38
|
+
console.log(`[${time}] \u{1F41B} [DEBUG] \u2728 [${this.name}] ${message}`, ...args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
info(message, ...args) {
|
|
42
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
43
|
+
console.info(`[${time}] \u2139\uFE0F [INFO] \u2728 [${this.name}] ${message}`, ...args);
|
|
44
|
+
}
|
|
45
|
+
warn(message, ...args) {
|
|
46
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
47
|
+
console.warn(`[${time}] \u{1F6A7} [WARN] \u2728 [${this.name}] ${message}`, ...args);
|
|
48
|
+
}
|
|
49
|
+
error(message, ...args) {
|
|
50
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
51
|
+
console.error(`[${time}] \u274C [ERROR] \u2728 [${this.name}] ${message}`, ...args);
|
|
33
52
|
}
|
|
34
53
|
};
|
|
35
54
|
}
|
|
36
55
|
});
|
|
37
56
|
|
|
38
57
|
// src/tools/base/base-tool.ts
|
|
39
|
-
var BaseTool;
|
|
58
|
+
var logger2, BaseTool;
|
|
40
59
|
var init_base_tool = __esm({
|
|
41
60
|
"src/tools/base/base-tool.ts"() {
|
|
42
|
-
|
|
61
|
+
init_logger();
|
|
62
|
+
logger2 = new Logger({ name: "BaseTool" });
|
|
43
63
|
BaseTool = class {
|
|
44
64
|
/**
|
|
45
65
|
* Name of the tool
|
|
@@ -129,8 +149,8 @@ var init_base_tool = __esm({
|
|
|
129
149
|
while (attempts <= (this.shouldRetryOnFailure ? this.maxRetryAttempts : 0)) {
|
|
130
150
|
try {
|
|
131
151
|
if (attempts > 0) {
|
|
132
|
-
|
|
133
|
-
`
|
|
152
|
+
logger2.debug(
|
|
153
|
+
`Retrying tool ${this.name} (attempt ${attempts} of ${this.maxRetryAttempts})...`
|
|
134
154
|
);
|
|
135
155
|
const delay = Math.min(
|
|
136
156
|
this.baseRetryDelay * 2 ** (attempts - 1) + Math.random() * 1e3,
|
|
@@ -475,10 +495,11 @@ var BaseAgent = class {
|
|
|
475
495
|
};
|
|
476
496
|
|
|
477
497
|
// src/agents/llm-agent.ts
|
|
478
|
-
|
|
498
|
+
init_logger();
|
|
479
499
|
|
|
480
500
|
// src/models/llm-registry.ts
|
|
481
|
-
|
|
501
|
+
init_logger();
|
|
502
|
+
var logger = new Logger({ name: "LLMRegistry" });
|
|
482
503
|
var LLMRegistry = class _LLMRegistry {
|
|
483
504
|
/**
|
|
484
505
|
* Map of model name regex to LLM class
|
|
@@ -535,7 +556,7 @@ var LLMRegistry = class _LLMRegistry {
|
|
|
535
556
|
* Logs all registered models for debugging
|
|
536
557
|
*/
|
|
537
558
|
static logRegisteredModels() {
|
|
538
|
-
|
|
559
|
+
logger.debug(
|
|
539
560
|
"Registered LLM models:",
|
|
540
561
|
[..._LLMRegistry.llmRegistry.entries()].map(([regex]) => regex.toString())
|
|
541
562
|
);
|
|
@@ -904,6 +925,7 @@ var Agent = class extends BaseAgent {
|
|
|
904
925
|
* The minimum relevance score for memory augmentation (0-1)
|
|
905
926
|
*/
|
|
906
927
|
memoryRelevanceThreshold;
|
|
928
|
+
logger = new Logger({ name: "LlmAgent" });
|
|
907
929
|
/**
|
|
908
930
|
* Constructor for Agent
|
|
909
931
|
*/
|
|
@@ -936,7 +958,7 @@ var Agent = class extends BaseAgent {
|
|
|
936
958
|
*/
|
|
937
959
|
async executeTool(toolCall, context) {
|
|
938
960
|
const { name, arguments: argsString } = toolCall.function;
|
|
939
|
-
|
|
961
|
+
this.logger.debug(`Executing tool: ${name}`);
|
|
940
962
|
const tool = this.findTool(name);
|
|
941
963
|
if (!tool) {
|
|
942
964
|
console.warn(`Tool '${name}' not found`);
|
|
@@ -954,7 +976,7 @@ var Agent = class extends BaseAgent {
|
|
|
954
976
|
toolContext.toolName = name;
|
|
955
977
|
toolContext.toolId = toolCall.id;
|
|
956
978
|
const result = await tool.runAsync(args, toolContext);
|
|
957
|
-
|
|
979
|
+
this.logger.debug(`Tool ${name} execution complete`);
|
|
958
980
|
return {
|
|
959
981
|
name,
|
|
960
982
|
result: typeof result === "string" ? result : JSON.stringify(result)
|
|
@@ -1123,7 +1145,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1123
1145
|
let stepCount = 0;
|
|
1124
1146
|
while (stepCount < this.maxToolExecutionSteps) {
|
|
1125
1147
|
stepCount++;
|
|
1126
|
-
|
|
1148
|
+
this.logger.debug(`Step ${stepCount}: Thinking...`);
|
|
1127
1149
|
const llmRequest = new LLMRequest({
|
|
1128
1150
|
messages: context.messages,
|
|
1129
1151
|
config: {
|
|
@@ -1140,7 +1162,9 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1140
1162
|
throw new Error("No response from LLM");
|
|
1141
1163
|
}
|
|
1142
1164
|
if (currentResponse.tool_calls && currentResponse.tool_calls.length > 0) {
|
|
1143
|
-
|
|
1165
|
+
this.logger.debug(
|
|
1166
|
+
`Tool calls: ${JSON.stringify(currentResponse.tool_calls)}`
|
|
1167
|
+
);
|
|
1144
1168
|
context.addMessage({
|
|
1145
1169
|
role: "assistant",
|
|
1146
1170
|
content: currentResponse.content || "",
|
|
@@ -1159,7 +1183,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1159
1183
|
});
|
|
1160
1184
|
}
|
|
1161
1185
|
} else {
|
|
1162
|
-
|
|
1186
|
+
this.logger.debug("No tool calls, finishing...");
|
|
1163
1187
|
context.addMessage({
|
|
1164
1188
|
role: "assistant",
|
|
1165
1189
|
content: currentResponse.content || ""
|
|
@@ -1197,7 +1221,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1197
1221
|
let stepCount = 0;
|
|
1198
1222
|
let hadToolCalls = false;
|
|
1199
1223
|
while (stepCount < this.maxToolExecutionSteps) {
|
|
1200
|
-
|
|
1224
|
+
this.logger.debug(`Step ${stepCount}: Thinking...`);
|
|
1201
1225
|
const toolDeclarations = this.tools.map((tool) => tool.getDeclaration()).filter((declaration) => declaration !== null);
|
|
1202
1226
|
const request = {
|
|
1203
1227
|
messages: context.messages,
|
|
@@ -1226,10 +1250,10 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1226
1250
|
function_call: finalResponse.function_call
|
|
1227
1251
|
});
|
|
1228
1252
|
if (!hadToolCalls) {
|
|
1229
|
-
|
|
1253
|
+
this.logger.debug("No tool calls, finishing...");
|
|
1230
1254
|
break;
|
|
1231
1255
|
}
|
|
1232
|
-
|
|
1256
|
+
this.logger.debug(`Step ${stepCount + 1}: Executing tools...`);
|
|
1233
1257
|
stepCount++;
|
|
1234
1258
|
if (finalResponse.function_call) {
|
|
1235
1259
|
const toolCall = {
|
|
@@ -1246,8 +1270,8 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1246
1270
|
content: JSON.stringify(result.result)
|
|
1247
1271
|
});
|
|
1248
1272
|
} else if (finalResponse.tool_calls && finalResponse.tool_calls.length > 0) {
|
|
1249
|
-
|
|
1250
|
-
`
|
|
1273
|
+
this.logger.debug(
|
|
1274
|
+
`Step ${stepCount + 1}: Executing ${finalResponse.tool_calls.length} tool(s)...`
|
|
1251
1275
|
);
|
|
1252
1276
|
context.messages.pop();
|
|
1253
1277
|
context.addMessage({
|
|
@@ -1273,8 +1297,9 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1273
1297
|
};
|
|
1274
1298
|
|
|
1275
1299
|
// src/agents/sequential-agent.ts
|
|
1276
|
-
|
|
1300
|
+
init_logger();
|
|
1277
1301
|
var SequentialAgent = class extends BaseAgent {
|
|
1302
|
+
logger = new Logger({ name: "SequentialAgent" });
|
|
1278
1303
|
/**
|
|
1279
1304
|
* Constructor for SequentialAgent
|
|
1280
1305
|
*/
|
|
@@ -1294,8 +1319,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1294
1319
|
* Executes sub-agents sequentially, passing output from one to the next
|
|
1295
1320
|
*/
|
|
1296
1321
|
async run(options) {
|
|
1297
|
-
|
|
1298
|
-
`
|
|
1322
|
+
this.logger.debug(
|
|
1323
|
+
`Running ${this.subAgents.length} sub-agents in sequence`
|
|
1299
1324
|
);
|
|
1300
1325
|
if (this.subAgents.length === 0) {
|
|
1301
1326
|
return {
|
|
@@ -1312,8 +1337,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1312
1337
|
let finalResponse = null;
|
|
1313
1338
|
for (let i = 0; i < this.subAgents.length; i++) {
|
|
1314
1339
|
const agent = this.subAgents[i];
|
|
1315
|
-
|
|
1316
|
-
`
|
|
1340
|
+
this.logger.debug(
|
|
1341
|
+
`Running sub-agent ${i + 1}/${this.subAgents.length}: ${agent.name}`
|
|
1317
1342
|
);
|
|
1318
1343
|
try {
|
|
1319
1344
|
const response = await agent.run({
|
|
@@ -1329,10 +1354,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1329
1354
|
});
|
|
1330
1355
|
}
|
|
1331
1356
|
} catch (error) {
|
|
1332
|
-
console.error(
|
|
1333
|
-
`[SequentialAgent] Error in sub-agent ${agent.name}:`,
|
|
1334
|
-
error
|
|
1335
|
-
);
|
|
1357
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1336
1358
|
return {
|
|
1337
1359
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1338
1360
|
role: "assistant",
|
|
@@ -1370,8 +1392,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1370
1392
|
* Streams responses from each sub-agent in sequence
|
|
1371
1393
|
*/
|
|
1372
1394
|
async *runStreaming(options) {
|
|
1373
|
-
|
|
1374
|
-
`
|
|
1395
|
+
this.logger.debug(
|
|
1396
|
+
`Streaming ${this.subAgents.length} sub-agents in sequence`
|
|
1375
1397
|
);
|
|
1376
1398
|
if (this.subAgents.length === 0) {
|
|
1377
1399
|
yield {
|
|
@@ -1388,8 +1410,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1388
1410
|
const currentMessages = [...options.messages];
|
|
1389
1411
|
for (let i = 0; i < this.subAgents.length; i++) {
|
|
1390
1412
|
const agent = this.subAgents[i];
|
|
1391
|
-
|
|
1392
|
-
`
|
|
1413
|
+
this.logger.debug(
|
|
1414
|
+
`Streaming sub-agent ${i + 1}/${this.subAgents.length}: ${agent.name}`
|
|
1393
1415
|
);
|
|
1394
1416
|
try {
|
|
1395
1417
|
const streamGenerator = agent.runStreaming({
|
|
@@ -1422,10 +1444,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1422
1444
|
});
|
|
1423
1445
|
}
|
|
1424
1446
|
} catch (error) {
|
|
1425
|
-
console.error(
|
|
1426
|
-
`[SequentialAgent] Error in streaming sub-agent ${agent.name}:`,
|
|
1427
|
-
error
|
|
1428
|
-
);
|
|
1447
|
+
console.error(`Error in streaming sub-agent ${agent.name}:`, error);
|
|
1429
1448
|
yield {
|
|
1430
1449
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1431
1450
|
role: "assistant",
|
|
@@ -1443,8 +1462,9 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1443
1462
|
};
|
|
1444
1463
|
|
|
1445
1464
|
// src/agents/parallel-agent.ts
|
|
1446
|
-
|
|
1465
|
+
init_logger();
|
|
1447
1466
|
var ParallelAgent = class extends BaseAgent {
|
|
1467
|
+
logger = new Logger({ name: "ParallelAgent" });
|
|
1448
1468
|
/**
|
|
1449
1469
|
* Constructor for ParallelAgent
|
|
1450
1470
|
*/
|
|
@@ -1464,8 +1484,8 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1464
1484
|
* Executes all sub-agents in parallel
|
|
1465
1485
|
*/
|
|
1466
1486
|
async run(options) {
|
|
1467
|
-
|
|
1468
|
-
`
|
|
1487
|
+
this.logger.debug(
|
|
1488
|
+
`Running ${this.subAgents.length} sub-agents in parallel`
|
|
1469
1489
|
);
|
|
1470
1490
|
if (this.subAgents.length === 0) {
|
|
1471
1491
|
return {
|
|
@@ -1478,10 +1498,7 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1478
1498
|
messages: options.messages,
|
|
1479
1499
|
config: options.config
|
|
1480
1500
|
}).catch((error) => {
|
|
1481
|
-
console.error(
|
|
1482
|
-
`[ParallelAgent] Error in sub-agent ${agent.name}:`,
|
|
1483
|
-
error
|
|
1484
|
-
);
|
|
1501
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1485
1502
|
return {
|
|
1486
1503
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1487
1504
|
role: "assistant"
|
|
@@ -1509,8 +1526,8 @@ ${result.content || "No content"}
|
|
|
1509
1526
|
* Collects streaming responses from all sub-agents
|
|
1510
1527
|
*/
|
|
1511
1528
|
async *runStreaming(options) {
|
|
1512
|
-
|
|
1513
|
-
`
|
|
1529
|
+
this.logger.debug(
|
|
1530
|
+
`Streaming ${this.subAgents.length} sub-agents in parallel`
|
|
1514
1531
|
);
|
|
1515
1532
|
if (this.subAgents.length === 0) {
|
|
1516
1533
|
yield {
|
|
@@ -1524,10 +1541,7 @@ ${result.content || "No content"}
|
|
|
1524
1541
|
messages: options.messages,
|
|
1525
1542
|
config: options.config
|
|
1526
1543
|
}).catch((error) => {
|
|
1527
|
-
console.error(
|
|
1528
|
-
`[ParallelAgent] Error in sub-agent ${agent.name}:`,
|
|
1529
|
-
error
|
|
1530
|
-
);
|
|
1544
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1531
1545
|
return {
|
|
1532
1546
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1533
1547
|
role: "assistant"
|
|
@@ -1577,7 +1591,7 @@ ${response.content || "No content"}
|
|
|
1577
1591
|
};
|
|
1578
1592
|
|
|
1579
1593
|
// src/agents/loop-agent.ts
|
|
1580
|
-
|
|
1594
|
+
init_logger();
|
|
1581
1595
|
var LoopAgent = class extends BaseAgent {
|
|
1582
1596
|
/**
|
|
1583
1597
|
* Maximum number of iterations to prevent infinite loops
|
|
@@ -1591,6 +1605,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1591
1605
|
* Custom condition check function
|
|
1592
1606
|
*/
|
|
1593
1607
|
conditionCheck;
|
|
1608
|
+
logger = new Logger({ name: "LoopAgent" });
|
|
1594
1609
|
/**
|
|
1595
1610
|
* Constructor for LoopAgent
|
|
1596
1611
|
*/
|
|
@@ -1618,19 +1633,19 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1618
1633
|
*/
|
|
1619
1634
|
async shouldContinue(response, iterationCount, messages, config) {
|
|
1620
1635
|
if (iterationCount >= this.maxIterations) {
|
|
1621
|
-
|
|
1622
|
-
`
|
|
1636
|
+
this.logger.debug(
|
|
1637
|
+
`Maximum iterations (${this.maxIterations}) reached. Stopping loop.`
|
|
1623
1638
|
);
|
|
1624
1639
|
return false;
|
|
1625
1640
|
}
|
|
1626
1641
|
if (this.conditionCheck) {
|
|
1627
1642
|
const shouldContinue = await this.conditionCheck(response);
|
|
1628
|
-
|
|
1643
|
+
this.logger.debug(`Custom condition check result: ${shouldContinue}`);
|
|
1629
1644
|
return shouldContinue;
|
|
1630
1645
|
}
|
|
1631
1646
|
if (this.conditionAgent) {
|
|
1632
|
-
|
|
1633
|
-
`
|
|
1647
|
+
this.logger.debug(
|
|
1648
|
+
`Using condition agent ${this.conditionAgent.name} to check loop condition`
|
|
1634
1649
|
);
|
|
1635
1650
|
const conditionMessages = [
|
|
1636
1651
|
...messages,
|
|
@@ -1650,12 +1665,12 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1650
1665
|
});
|
|
1651
1666
|
const content = conditionResponse.content?.toLowerCase() || "";
|
|
1652
1667
|
const shouldContinue = content.includes("yes") && !content.includes("no");
|
|
1653
|
-
|
|
1654
|
-
`
|
|
1668
|
+
this.logger.debug(
|
|
1669
|
+
`Condition agent result: ${shouldContinue ? "Continue loop" : "Stop loop"}`
|
|
1655
1670
|
);
|
|
1656
1671
|
return shouldContinue;
|
|
1657
1672
|
} catch (error) {
|
|
1658
|
-
console.error("
|
|
1673
|
+
console.error("Error in condition agent:", error);
|
|
1659
1674
|
return false;
|
|
1660
1675
|
}
|
|
1661
1676
|
}
|
|
@@ -1666,8 +1681,8 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1666
1681
|
* Executes the sub-agent in a loop until the condition is met
|
|
1667
1682
|
*/
|
|
1668
1683
|
async run(options) {
|
|
1669
|
-
|
|
1670
|
-
`
|
|
1684
|
+
this.logger.debug(
|
|
1685
|
+
`Starting loop with max ${this.maxIterations} iterations`
|
|
1671
1686
|
);
|
|
1672
1687
|
if (this.subAgents.length === 0) {
|
|
1673
1688
|
return {
|
|
@@ -1682,8 +1697,8 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1682
1697
|
let shouldContinueLoop = true;
|
|
1683
1698
|
while (shouldContinueLoop && iterationCount < this.maxIterations) {
|
|
1684
1699
|
iterationCount++;
|
|
1685
|
-
|
|
1686
|
-
`
|
|
1700
|
+
this.logger.debug(
|
|
1701
|
+
`Running iteration ${iterationCount}/${this.maxIterations}`
|
|
1687
1702
|
);
|
|
1688
1703
|
try {
|
|
1689
1704
|
const response = await subAgent.run({
|
|
@@ -1708,10 +1723,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1708
1723
|
});
|
|
1709
1724
|
}
|
|
1710
1725
|
} catch (error) {
|
|
1711
|
-
console.error(
|
|
1712
|
-
`[LoopAgent] Error in loop iteration ${iterationCount}:`,
|
|
1713
|
-
error
|
|
1714
|
-
);
|
|
1726
|
+
console.error(`Error in loop iteration ${iterationCount}:`, error);
|
|
1715
1727
|
break;
|
|
1716
1728
|
}
|
|
1717
1729
|
}
|
|
@@ -1732,8 +1744,8 @@ ${lastResponse.content || ""}`,
|
|
|
1732
1744
|
* Runs the agent with streaming support
|
|
1733
1745
|
*/
|
|
1734
1746
|
async *runStreaming(options) {
|
|
1735
|
-
|
|
1736
|
-
`
|
|
1747
|
+
this.logger.debug(
|
|
1748
|
+
`Starting loop with max ${this.maxIterations} iterations (streaming)`
|
|
1737
1749
|
);
|
|
1738
1750
|
if (this.subAgents.length === 0) {
|
|
1739
1751
|
yield {
|
|
@@ -1753,8 +1765,8 @@ ${lastResponse.content || ""}`,
|
|
|
1753
1765
|
};
|
|
1754
1766
|
while (shouldContinueLoop && iterationCount < this.maxIterations) {
|
|
1755
1767
|
iterationCount++;
|
|
1756
|
-
|
|
1757
|
-
`
|
|
1768
|
+
this.logger.debug(
|
|
1769
|
+
`Running iteration ${iterationCount}/${this.maxIterations} (streaming)`
|
|
1758
1770
|
);
|
|
1759
1771
|
yield {
|
|
1760
1772
|
content: `Running iteration ${iterationCount}/${this.maxIterations}...`,
|
|
@@ -1779,8 +1791,8 @@ ${lastResponse.content || ""}`,
|
|
|
1779
1791
|
}
|
|
1780
1792
|
}
|
|
1781
1793
|
if (!lastChunk) {
|
|
1782
|
-
|
|
1783
|
-
`
|
|
1794
|
+
this.logger.debug(
|
|
1795
|
+
`No complete chunk received from iteration ${iterationCount}`
|
|
1784
1796
|
);
|
|
1785
1797
|
shouldContinueLoop = false;
|
|
1786
1798
|
continue;
|
|
@@ -1807,8 +1819,8 @@ ${lastResponse.content || ""}`,
|
|
|
1807
1819
|
};
|
|
1808
1820
|
}
|
|
1809
1821
|
} catch (error) {
|
|
1810
|
-
|
|
1811
|
-
`
|
|
1822
|
+
this.logger.debug(
|
|
1823
|
+
`Error in loop iteration ${iterationCount}: ${error instanceof Error ? error.message : String(error)}`
|
|
1812
1824
|
);
|
|
1813
1825
|
yield {
|
|
1814
1826
|
content: `Error in loop iteration ${iterationCount}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -1825,7 +1837,7 @@ ${lastResponse.content || ""}`,
|
|
|
1825
1837
|
};
|
|
1826
1838
|
|
|
1827
1839
|
// src/agents/lang-graph-agent.ts
|
|
1828
|
-
|
|
1840
|
+
init_logger();
|
|
1829
1841
|
var LangGraphAgent = class extends BaseAgent {
|
|
1830
1842
|
/**
|
|
1831
1843
|
* Graph nodes (agents and their connections)
|
|
@@ -1843,6 +1855,7 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
1843
1855
|
* Results from node executions
|
|
1844
1856
|
*/
|
|
1845
1857
|
results = [];
|
|
1858
|
+
logger = new Logger({ name: "LangGraphAgent" });
|
|
1846
1859
|
/**
|
|
1847
1860
|
* Constructor for LangGraphAgent
|
|
1848
1861
|
*/
|
|
@@ -1917,15 +1930,13 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
1917
1930
|
for (const targetName of currentNode.targets) {
|
|
1918
1931
|
const targetNode = this.nodes.get(targetName);
|
|
1919
1932
|
if (!targetNode) {
|
|
1920
|
-
console.error(`
|
|
1933
|
+
console.error(`Target node "${targetName}" not found`);
|
|
1921
1934
|
continue;
|
|
1922
1935
|
}
|
|
1923
1936
|
if (targetNode.condition) {
|
|
1924
1937
|
const shouldExecute = await targetNode.condition(result, context);
|
|
1925
1938
|
if (!shouldExecute) {
|
|
1926
|
-
|
|
1927
|
-
`[LangGraphAgent] Skipping node "${targetName}" due to condition`
|
|
1928
|
-
);
|
|
1939
|
+
this.logger.debug(`Skipping node "${targetName}" due to condition`);
|
|
1929
1940
|
continue;
|
|
1930
1941
|
}
|
|
1931
1942
|
}
|
|
@@ -1950,9 +1961,7 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
1950
1961
|
};
|
|
1951
1962
|
const shouldExecute = await node.condition(mockResponse, mockContext);
|
|
1952
1963
|
if (!shouldExecute) {
|
|
1953
|
-
|
|
1954
|
-
`[LangGraphAgent] Skipping node "${targetName}" due to condition`
|
|
1955
|
-
);
|
|
1964
|
+
this.logger.debug(`Skipping node "${targetName}" due to condition`);
|
|
1956
1965
|
}
|
|
1957
1966
|
return { shouldExecute };
|
|
1958
1967
|
}
|
|
@@ -1965,8 +1974,8 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
1965
1974
|
messages: options.messages,
|
|
1966
1975
|
config: options.config
|
|
1967
1976
|
});
|
|
1968
|
-
|
|
1969
|
-
`
|
|
1977
|
+
this.logger.debug(
|
|
1978
|
+
`Starting graph execution from root node "${this.rootNode}"`
|
|
1970
1979
|
);
|
|
1971
1980
|
if (this.nodes.size === 0) {
|
|
1972
1981
|
return {
|
|
@@ -1987,9 +1996,7 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
1987
1996
|
while (nodesToExecute.length > 0 && stepCount < this.maxSteps) {
|
|
1988
1997
|
stepCount++;
|
|
1989
1998
|
const { node, messages } = nodesToExecute.shift();
|
|
1990
|
-
|
|
1991
|
-
`[LangGraphAgent] Step ${stepCount}: Executing node "${node.name}"`
|
|
1992
|
-
);
|
|
1999
|
+
this.logger.debug(`Step ${stepCount}: Executing node "${node.name}"`);
|
|
1993
2000
|
executedNodes.push(node.name);
|
|
1994
2001
|
try {
|
|
1995
2002
|
const result = await node.agent.run({
|
|
@@ -2037,7 +2044,7 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
2037
2044
|
});
|
|
2038
2045
|
}
|
|
2039
2046
|
} catch (error) {
|
|
2040
|
-
console.error(`
|
|
2047
|
+
console.error(`Error in node "${node.name}":`, error);
|
|
2041
2048
|
return {
|
|
2042
2049
|
content: `Error in node "${node.name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
2043
2050
|
role: "assistant"
|
|
@@ -2061,8 +2068,8 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
2061
2068
|
messages: options.messages,
|
|
2062
2069
|
config: options.config
|
|
2063
2070
|
});
|
|
2064
|
-
|
|
2065
|
-
`
|
|
2071
|
+
this.logger.debug(
|
|
2072
|
+
`Starting graph execution from root node "${this.rootNode}" (streaming)`
|
|
2066
2073
|
);
|
|
2067
2074
|
if (this.nodes.size === 0) {
|
|
2068
2075
|
yield {
|
|
@@ -2090,8 +2097,8 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
2090
2097
|
while (nodesToExecute.length > 0 && stepCount < this.maxSteps) {
|
|
2091
2098
|
stepCount++;
|
|
2092
2099
|
const { node, messages } = nodesToExecute.shift();
|
|
2093
|
-
|
|
2094
|
-
`
|
|
2100
|
+
this.logger.debug(
|
|
2101
|
+
`Step ${stepCount}: Executing node "${node.name}" (streaming)`
|
|
2095
2102
|
);
|
|
2096
2103
|
executedNodes.push(node.name);
|
|
2097
2104
|
try {
|
|
@@ -2146,7 +2153,7 @@ Node output: ${this.extractTextContent(result.content)}` : ""}`,
|
|
|
2146
2153
|
});
|
|
2147
2154
|
}
|
|
2148
2155
|
} catch (error) {
|
|
2149
|
-
console.error(`
|
|
2156
|
+
console.error(`Error in node "${node.name}":`, error);
|
|
2150
2157
|
yield {
|
|
2151
2158
|
content: `Error in node "${node.name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
2152
2159
|
role: "assistant"
|
|
@@ -2206,9 +2213,10 @@ function createFunctionTool(func, options) {
|
|
|
2206
2213
|
init_function_utils();
|
|
2207
2214
|
|
|
2208
2215
|
// src/tools/common/google-search.ts
|
|
2209
|
-
|
|
2216
|
+
init_logger();
|
|
2210
2217
|
init_base_tool();
|
|
2211
2218
|
var GoogleSearch = class extends BaseTool {
|
|
2219
|
+
logger = new Logger({ name: "GoogleSearch" });
|
|
2212
2220
|
/**
|
|
2213
2221
|
* Constructor for GoogleSearch
|
|
2214
2222
|
*/
|
|
@@ -2247,7 +2255,9 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2247
2255
|
* This is a simplified implementation that doesn't actually search, just returns mock results
|
|
2248
2256
|
*/
|
|
2249
2257
|
async runAsync(args, _context) {
|
|
2250
|
-
|
|
2258
|
+
this.logger.debug(
|
|
2259
|
+
`[GoogleSearch] Executing Google search for: ${args.query}`
|
|
2260
|
+
);
|
|
2251
2261
|
return {
|
|
2252
2262
|
results: [
|
|
2253
2263
|
{
|
|
@@ -2710,9 +2720,10 @@ var UserInteractionTool = class extends BaseTool {
|
|
|
2710
2720
|
};
|
|
2711
2721
|
|
|
2712
2722
|
// src/tools/common/exit-loop-tool.ts
|
|
2713
|
-
|
|
2723
|
+
init_logger();
|
|
2714
2724
|
init_base_tool();
|
|
2715
2725
|
var ExitLoopTool = class extends BaseTool {
|
|
2726
|
+
logger = new Logger({ name: "ExitLoopTool" });
|
|
2716
2727
|
/**
|
|
2717
2728
|
* Constructor for ExitLoopTool
|
|
2718
2729
|
*/
|
|
@@ -2740,7 +2751,7 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2740
2751
|
* Execute the exit loop action
|
|
2741
2752
|
*/
|
|
2742
2753
|
async runAsync(_args, context) {
|
|
2743
|
-
|
|
2754
|
+
this.logger.debug("Executing exit loop tool");
|
|
2744
2755
|
if (context.actions) {
|
|
2745
2756
|
context.actions.escalate = true;
|
|
2746
2757
|
} else {
|
|
@@ -2755,9 +2766,10 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2755
2766
|
};
|
|
2756
2767
|
|
|
2757
2768
|
// src/tools/common/get-user-choice-tool.ts
|
|
2758
|
-
|
|
2769
|
+
init_logger();
|
|
2759
2770
|
init_base_tool();
|
|
2760
2771
|
var GetUserChoiceTool = class extends BaseTool {
|
|
2772
|
+
logger = new Logger({ name: "GetUserChoiceTool" });
|
|
2761
2773
|
/**
|
|
2762
2774
|
* Constructor for GetUserChoiceTool
|
|
2763
2775
|
*/
|
|
@@ -2800,13 +2812,11 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2800
2812
|
* and the actual choice will be provided asynchronously
|
|
2801
2813
|
*/
|
|
2802
2814
|
async runAsync(args, context) {
|
|
2803
|
-
|
|
2804
|
-
`
|
|
2805
|
-
", "
|
|
2806
|
-
)}`
|
|
2815
|
+
this.logger.debug(
|
|
2816
|
+
`Executing get_user_choice with options: ${args.options.join(", ")}`
|
|
2807
2817
|
);
|
|
2808
2818
|
if (args.question) {
|
|
2809
|
-
|
|
2819
|
+
this.logger.debug(`Question: ${args.question}`);
|
|
2810
2820
|
}
|
|
2811
2821
|
if (context.actions) {
|
|
2812
2822
|
context.actions.skip_summarization = true;
|
|
@@ -2820,9 +2830,10 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2820
2830
|
};
|
|
2821
2831
|
|
|
2822
2832
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
2823
|
-
|
|
2833
|
+
init_logger();
|
|
2824
2834
|
init_base_tool();
|
|
2825
2835
|
var TransferToAgentTool = class extends BaseTool {
|
|
2836
|
+
logger = new Logger({ name: "TransferToAgentTool" });
|
|
2826
2837
|
/**
|
|
2827
2838
|
* Constructor for TransferToAgentTool
|
|
2828
2839
|
*/
|
|
@@ -2855,9 +2866,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2855
2866
|
* Execute the transfer to agent action
|
|
2856
2867
|
*/
|
|
2857
2868
|
async runAsync(args, context) {
|
|
2858
|
-
|
|
2859
|
-
`[TransferToAgentTool] Executing transfer to agent: ${args.agent_name}`
|
|
2860
|
-
);
|
|
2869
|
+
this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
|
|
2861
2870
|
if (context.actions) {
|
|
2862
2871
|
context.actions.transfer_to_agent = args.agent_name;
|
|
2863
2872
|
} else {
|
|
@@ -2872,9 +2881,10 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2872
2881
|
};
|
|
2873
2882
|
|
|
2874
2883
|
// src/tools/common/load-memory-tool.ts
|
|
2875
|
-
|
|
2884
|
+
init_logger();
|
|
2876
2885
|
init_base_tool();
|
|
2877
2886
|
var LoadMemoryTool = class extends BaseTool {
|
|
2887
|
+
logger = new Logger({ name: "LoadMemoryTool" });
|
|
2878
2888
|
/**
|
|
2879
2889
|
* Constructor for LoadMemoryTool
|
|
2880
2890
|
*/
|
|
@@ -2907,9 +2917,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2907
2917
|
* Execute the memory loading action
|
|
2908
2918
|
*/
|
|
2909
2919
|
async runAsync(args, context) {
|
|
2910
|
-
|
|
2911
|
-
`[LoadMemoryTool] Executing load_memory with query: ${args.query}`
|
|
2912
|
-
);
|
|
2920
|
+
this.logger.debug(`Executing load_memory with query: ${args.query}`);
|
|
2913
2921
|
if (!context.memoryService) {
|
|
2914
2922
|
return {
|
|
2915
2923
|
error: "Memory service is not available",
|
|
@@ -2933,9 +2941,11 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2933
2941
|
};
|
|
2934
2942
|
|
|
2935
2943
|
// src/tools/mcp/client.ts
|
|
2944
|
+
init_logger();
|
|
2936
2945
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2937
2946
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
2938
2947
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
2948
|
+
import { CreateMessageRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2939
2949
|
|
|
2940
2950
|
// src/tools/mcp/types.ts
|
|
2941
2951
|
var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
@@ -2944,6 +2954,8 @@ var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
|
2944
2954
|
McpErrorType2["RESOURCE_CLOSED_ERROR"] = "resource_closed_error";
|
|
2945
2955
|
McpErrorType2["TIMEOUT_ERROR"] = "timeout_error";
|
|
2946
2956
|
McpErrorType2["INVALID_SCHEMA_ERROR"] = "invalid_schema_error";
|
|
2957
|
+
McpErrorType2["SAMPLING_ERROR"] = "SAMPLING_ERROR";
|
|
2958
|
+
McpErrorType2["INVALID_REQUEST_ERROR"] = "INVALID_REQUEST_ERROR";
|
|
2947
2959
|
return McpErrorType2;
|
|
2948
2960
|
})(McpErrorType || {});
|
|
2949
2961
|
var McpError = class extends Error {
|
|
@@ -2991,8 +3003,11 @@ var McpClientService = class {
|
|
|
2991
3003
|
client = null;
|
|
2992
3004
|
transport = null;
|
|
2993
3005
|
isClosing = false;
|
|
3006
|
+
samplingHandler = null;
|
|
3007
|
+
logger = new Logger({ name: "McpClientService" });
|
|
2994
3008
|
constructor(config) {
|
|
2995
3009
|
this.config = config;
|
|
3010
|
+
this.samplingHandler = config.samplingHandler || null;
|
|
2996
3011
|
}
|
|
2997
3012
|
/**
|
|
2998
3013
|
* Initializes and returns an MCP client based on configuration.
|
|
@@ -3041,6 +3056,7 @@ var McpClientService = class {
|
|
|
3041
3056
|
} else {
|
|
3042
3057
|
await connectPromise;
|
|
3043
3058
|
}
|
|
3059
|
+
await this.setupSamplingHandler(client);
|
|
3044
3060
|
if (this.config.debug) {
|
|
3045
3061
|
console.log("\u2705 MCP client connected successfully");
|
|
3046
3062
|
}
|
|
@@ -3192,10 +3208,77 @@ var McpClientService = class {
|
|
|
3192
3208
|
isConnected() {
|
|
3193
3209
|
return !!this.client && !this.isClosing;
|
|
3194
3210
|
}
|
|
3211
|
+
async setupSamplingHandler(client) {
|
|
3212
|
+
if (!this.samplingHandler) {
|
|
3213
|
+
if (this.config.debug) {
|
|
3214
|
+
console.log(
|
|
3215
|
+
"\u26A0\uFE0F No sampling handler provided - sampling requests will be rejected"
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
3218
|
+
return;
|
|
3219
|
+
}
|
|
3220
|
+
client.setRequestHandler(CreateMessageRequestSchema, async (request) => {
|
|
3221
|
+
try {
|
|
3222
|
+
this.logger.debug("Received sampling request:", request);
|
|
3223
|
+
const samplingRequest = request.params;
|
|
3224
|
+
if (!samplingRequest.messages || !Array.isArray(samplingRequest.messages)) {
|
|
3225
|
+
throw new McpError(
|
|
3226
|
+
"Invalid sampling request: messages array is required",
|
|
3227
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3228
|
+
);
|
|
3229
|
+
}
|
|
3230
|
+
if (!samplingRequest.maxTokens || samplingRequest.maxTokens <= 0) {
|
|
3231
|
+
throw new McpError(
|
|
3232
|
+
"Invalid sampling request: maxTokens must be a positive number",
|
|
3233
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3234
|
+
);
|
|
3235
|
+
}
|
|
3236
|
+
const response = await this.samplingHandler({
|
|
3237
|
+
method: request.method,
|
|
3238
|
+
params: request.params
|
|
3239
|
+
});
|
|
3240
|
+
if (this.config.debug) {
|
|
3241
|
+
console.log("\u2705 Sampling request completed successfully");
|
|
3242
|
+
}
|
|
3243
|
+
return response;
|
|
3244
|
+
} catch (error) {
|
|
3245
|
+
console.error("\u274C Error handling sampling request:", error);
|
|
3246
|
+
if (error instanceof McpError) {
|
|
3247
|
+
throw error;
|
|
3248
|
+
}
|
|
3249
|
+
throw new McpError(
|
|
3250
|
+
`Sampling request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3251
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */,
|
|
3252
|
+
error instanceof Error ? error : void 0
|
|
3253
|
+
);
|
|
3254
|
+
}
|
|
3255
|
+
});
|
|
3256
|
+
if (this.config.debug) {
|
|
3257
|
+
console.log("\u{1F3AF} Sampling handler registered successfully");
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
setSamplingHandler(handler) {
|
|
3261
|
+
this.samplingHandler = handler;
|
|
3262
|
+
if (this.client) {
|
|
3263
|
+
this.setupSamplingHandler(this.client).catch((error) => {
|
|
3264
|
+
console.error("Failed to update sampling handler:", error);
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
removeSamplingHandler() {
|
|
3269
|
+
this.samplingHandler = null;
|
|
3270
|
+
if (this.client) {
|
|
3271
|
+
try {
|
|
3272
|
+
this.client.removeRequestHandler?.("sampling/createMessage");
|
|
3273
|
+
} catch (error) {
|
|
3274
|
+
console.error("Failed to remove sampling handler:", error);
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3195
3278
|
};
|
|
3196
3279
|
|
|
3197
3280
|
// src/tools/mcp/create-tool.ts
|
|
3198
|
-
|
|
3281
|
+
init_logger();
|
|
3199
3282
|
init_base_tool();
|
|
3200
3283
|
|
|
3201
3284
|
// src/tools/mcp/schema-conversion.ts
|
|
@@ -3398,6 +3481,7 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
3398
3481
|
mcpTool;
|
|
3399
3482
|
client;
|
|
3400
3483
|
clientService = null;
|
|
3484
|
+
logger = new Logger({ name: "McpToolAdapter" });
|
|
3401
3485
|
constructor(mcpTool, client) {
|
|
3402
3486
|
const metadata = mcpTool.metadata || {};
|
|
3403
3487
|
super({
|
|
@@ -3430,10 +3514,7 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
3430
3514
|
}
|
|
3431
3515
|
}
|
|
3432
3516
|
async runAsync(args, _context) {
|
|
3433
|
-
|
|
3434
|
-
`[McpToolAdapter] Executing MCP tool ${this.name} with args:`,
|
|
3435
|
-
args
|
|
3436
|
-
);
|
|
3517
|
+
this.logger.debug(`Executing MCP tool ${this.name} with args:`, args);
|
|
3437
3518
|
try {
|
|
3438
3519
|
if (typeof this.mcpTool.execute === "function") {
|
|
3439
3520
|
return await this.mcpTool.execute(args);
|
|
@@ -3753,11 +3834,11 @@ var BaseLLMConnection = class {
|
|
|
3753
3834
|
};
|
|
3754
3835
|
|
|
3755
3836
|
// src/models/anthropic-llm.ts
|
|
3756
|
-
|
|
3837
|
+
init_logger();
|
|
3757
3838
|
import axios from "axios";
|
|
3758
3839
|
|
|
3759
3840
|
// src/models/anthropic-llm-connection.ts
|
|
3760
|
-
|
|
3841
|
+
init_logger();
|
|
3761
3842
|
var AnthropicLLMConnection = class extends BaseLLMConnection {
|
|
3762
3843
|
/**
|
|
3763
3844
|
* Axios instance for API calls
|
|
@@ -3785,6 +3866,7 @@ var AnthropicLLMConnection = class extends BaseLLMConnection {
|
|
|
3785
3866
|
responseCallback;
|
|
3786
3867
|
errorCallback;
|
|
3787
3868
|
endCallback;
|
|
3869
|
+
logger = new Logger({ name: "AnthropicLlmConnection" });
|
|
3788
3870
|
/**
|
|
3789
3871
|
* Constructor
|
|
3790
3872
|
*/
|
|
@@ -3887,12 +3969,10 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3887
3969
|
if (!content?.length) return [];
|
|
3888
3970
|
const toolUses = [];
|
|
3889
3971
|
for (const block of content) {
|
|
3890
|
-
|
|
3891
|
-
`[AnthropicLLMConnection] Processing content block of type: ${block.type}`
|
|
3892
|
-
);
|
|
3972
|
+
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
3893
3973
|
if (block.type === "tool_use") {
|
|
3894
|
-
|
|
3895
|
-
"
|
|
3974
|
+
this.logger.debug(
|
|
3975
|
+
"Found tool_use block:",
|
|
3896
3976
|
JSON.stringify(block, null, 2)
|
|
3897
3977
|
);
|
|
3898
3978
|
toolUses.push({
|
|
@@ -3902,12 +3982,10 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3902
3982
|
});
|
|
3903
3983
|
}
|
|
3904
3984
|
}
|
|
3905
|
-
|
|
3906
|
-
`[AnthropicLLMConnection] Found ${toolUses.length} tool uses in content`
|
|
3907
|
-
);
|
|
3985
|
+
this.logger.debug(`Found ${toolUses.length} tool uses in content`);
|
|
3908
3986
|
if (toolUses.length > 0) {
|
|
3909
|
-
|
|
3910
|
-
"
|
|
3987
|
+
this.logger.debug(
|
|
3988
|
+
"Extracted tool uses:",
|
|
3911
3989
|
JSON.stringify(toolUses, null, 2)
|
|
3912
3990
|
);
|
|
3913
3991
|
}
|
|
@@ -4003,8 +4081,8 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4003
4081
|
}
|
|
4004
4082
|
const toolUses = this.extractToolUses(apiResponse.content);
|
|
4005
4083
|
const toolCalls = this.convertToolCalls(toolUses);
|
|
4006
|
-
|
|
4007
|
-
|
|
4084
|
+
this.logger.debug(
|
|
4085
|
+
`- Extracted ${toolUses.length} tool uses in content and converted ${toolCalls?.length || 0} tool calls`
|
|
4008
4086
|
);
|
|
4009
4087
|
const llmResponse = new LLMResponse({
|
|
4010
4088
|
role: "assistant",
|
|
@@ -4017,16 +4095,13 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4017
4095
|
content: llmResponse.content?.substring(0, 50) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4018
4096
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4019
4097
|
};
|
|
4020
|
-
|
|
4021
|
-
"
|
|
4098
|
+
this.logger.debug(
|
|
4099
|
+
"Final LLMResponse object:",
|
|
4022
4100
|
JSON.stringify(logObject, null, 2)
|
|
4023
4101
|
);
|
|
4024
4102
|
return llmResponse;
|
|
4025
4103
|
} catch (error) {
|
|
4026
|
-
|
|
4027
|
-
"[AnthropicLLMConnection] Error sending message to Anthropic:",
|
|
4028
|
-
error
|
|
4029
|
-
);
|
|
4104
|
+
this.logger.debug("Error sending message to Anthropic:", error);
|
|
4030
4105
|
throw error;
|
|
4031
4106
|
}
|
|
4032
4107
|
}
|
|
@@ -4046,6 +4121,7 @@ var AnthropicLLM = class extends BaseLLM {
|
|
|
4046
4121
|
* Default parameters for requests
|
|
4047
4122
|
*/
|
|
4048
4123
|
defaultParams;
|
|
4124
|
+
logger = new Logger({ name: "AnthropicLLM" });
|
|
4049
4125
|
/**
|
|
4050
4126
|
* Constructor for AnthropicLLM
|
|
4051
4127
|
*/
|
|
@@ -4178,12 +4254,10 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4178
4254
|
if (!content?.length) return [];
|
|
4179
4255
|
const toolUses = [];
|
|
4180
4256
|
for (const block of content) {
|
|
4181
|
-
|
|
4182
|
-
`[AnthropicLLM] Processing content block of type: ${block.type}`
|
|
4183
|
-
);
|
|
4257
|
+
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
4184
4258
|
if (block.type === "tool_use") {
|
|
4185
|
-
|
|
4186
|
-
`
|
|
4259
|
+
this.logger.debug(
|
|
4260
|
+
`Found tool_use block: ${JSON.stringify(block, null, 2)}`
|
|
4187
4261
|
);
|
|
4188
4262
|
toolUses.push({
|
|
4189
4263
|
id: block.id || "unknown-id",
|
|
@@ -4192,8 +4266,8 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4192
4266
|
});
|
|
4193
4267
|
}
|
|
4194
4268
|
}
|
|
4195
|
-
|
|
4196
|
-
`
|
|
4269
|
+
this.logger.debug(
|
|
4270
|
+
`Found ${toolUses.length} tool uses in content`,
|
|
4197
4271
|
toolUses
|
|
4198
4272
|
);
|
|
4199
4273
|
return toolUses;
|
|
@@ -4217,12 +4291,12 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4217
4291
|
},
|
|
4218
4292
|
responseType: stream ? "stream" : "json"
|
|
4219
4293
|
});
|
|
4220
|
-
|
|
4221
|
-
`
|
|
4294
|
+
this.logger.debug(
|
|
4295
|
+
`API Response done with ${response.status}:`,
|
|
4222
4296
|
response.data
|
|
4223
4297
|
);
|
|
4224
|
-
|
|
4225
|
-
"
|
|
4298
|
+
this.logger.debug(
|
|
4299
|
+
"API Response content:",
|
|
4226
4300
|
response.data.content.map((block) => ({ type: block.type }))
|
|
4227
4301
|
);
|
|
4228
4302
|
return response.data;
|
|
@@ -4250,7 +4324,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4250
4324
|
top_p: llmRequest.config.top_p ?? this.defaultParams.top_p,
|
|
4251
4325
|
tools: tools?.length ? tools : void 0
|
|
4252
4326
|
};
|
|
4253
|
-
|
|
4327
|
+
this.logger.debug("API Request:", {
|
|
4254
4328
|
model: params.model,
|
|
4255
4329
|
messageCount: params.messages.length,
|
|
4256
4330
|
systemMessage: params.system ? "present" : "none",
|
|
@@ -4260,7 +4334,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4260
4334
|
throw new Error("Streaming is not supported in this implementation");
|
|
4261
4335
|
}
|
|
4262
4336
|
const response = await this.callAnthropicAPI(params);
|
|
4263
|
-
|
|
4337
|
+
this.logger.debug("Full Response Content:", response.content);
|
|
4264
4338
|
let content = "";
|
|
4265
4339
|
for (const block of response.content) {
|
|
4266
4340
|
if (block.type === "text") {
|
|
@@ -4269,8 +4343,8 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4269
4343
|
}
|
|
4270
4344
|
const toolUses = this.extractToolUses(response.content);
|
|
4271
4345
|
const toolCalls = this.convertToolUses(toolUses);
|
|
4272
|
-
|
|
4273
|
-
|
|
4346
|
+
this.logger.debug("Extracted Tool Uses:", toolUses);
|
|
4347
|
+
this.logger.debug("Converted Tool Calls:", toolCalls);
|
|
4274
4348
|
const llmResponse = new LLMResponse({
|
|
4275
4349
|
role: "assistant",
|
|
4276
4350
|
content,
|
|
@@ -4282,13 +4356,13 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4282
4356
|
content: llmResponse.content?.substring(0, 50) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4283
4357
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4284
4358
|
};
|
|
4285
|
-
|
|
4286
|
-
"
|
|
4359
|
+
this.logger.debug(
|
|
4360
|
+
"Final LLMResponse object:",
|
|
4287
4361
|
JSON.stringify(logObject, null, 2)
|
|
4288
4362
|
);
|
|
4289
4363
|
yield llmResponse;
|
|
4290
4364
|
} catch (error) {
|
|
4291
|
-
|
|
4365
|
+
this.logger.debug("Error:", error);
|
|
4292
4366
|
throw error;
|
|
4293
4367
|
}
|
|
4294
4368
|
}
|
|
@@ -4683,7 +4757,7 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4683
4757
|
};
|
|
4684
4758
|
|
|
4685
4759
|
// src/models/openai-llm.ts
|
|
4686
|
-
|
|
4760
|
+
init_logger();
|
|
4687
4761
|
import OpenAI from "openai";
|
|
4688
4762
|
|
|
4689
4763
|
// src/models/openai-llm-connection.ts
|
|
@@ -4943,6 +5017,7 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
4943
5017
|
* Default parameters for requests
|
|
4944
5018
|
*/
|
|
4945
5019
|
defaultParams;
|
|
5020
|
+
logger = new Logger({ name: "OpenAILLM" });
|
|
4946
5021
|
/**
|
|
4947
5022
|
* Constructor for OpenAILLM
|
|
4948
5023
|
*/
|
|
@@ -5092,8 +5167,8 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5092
5167
|
* Convert OpenAI streaming chunk to LLMResponse
|
|
5093
5168
|
*/
|
|
5094
5169
|
convertChunk(chunk) {
|
|
5095
|
-
|
|
5096
|
-
`
|
|
5170
|
+
this.logger.debug(
|
|
5171
|
+
`Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
|
|
5097
5172
|
);
|
|
5098
5173
|
const content = chunk.delta?.content;
|
|
5099
5174
|
const result = new LLMResponse({
|
|
@@ -5135,24 +5210,24 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5135
5210
|
presence_penalty: llmRequest.config.presence_penalty ?? this.defaultParams.presence_penalty,
|
|
5136
5211
|
stream: shouldStream
|
|
5137
5212
|
};
|
|
5138
|
-
|
|
5139
|
-
`
|
|
5213
|
+
this.logger.debug(
|
|
5214
|
+
`Request parameters - model: ${params.model}, messages: ${params.messages.length}, functions: ${params.tools ? params.tools.length : 0}, streaming: ${shouldStream}`
|
|
5140
5215
|
);
|
|
5141
5216
|
if (tools && tools.length > 0) {
|
|
5142
5217
|
params.tools = tools;
|
|
5143
5218
|
}
|
|
5144
5219
|
try {
|
|
5145
5220
|
if (shouldStream) {
|
|
5146
|
-
|
|
5221
|
+
this.logger.debug("Starting streaming request");
|
|
5147
5222
|
const streamResponse = await this.client.chat.completions.create(params);
|
|
5148
5223
|
let partialFunctionCall;
|
|
5149
5224
|
const partialToolCalls = /* @__PURE__ */ new Map();
|
|
5150
5225
|
let accumulatedContent = "";
|
|
5151
5226
|
const asyncIterable = streamResponse;
|
|
5152
|
-
|
|
5227
|
+
this.logger.debug("Stream response received, processing chunks");
|
|
5153
5228
|
for await (const chunk of asyncIterable) {
|
|
5154
5229
|
if (!chunk.choices || chunk.choices.length === 0) {
|
|
5155
|
-
|
|
5230
|
+
this.logger.debug("Empty chunk received, skipping");
|
|
5156
5231
|
continue;
|
|
5157
5232
|
}
|
|
5158
5233
|
const choice = chunk.choices[0];
|
|
@@ -5160,8 +5235,8 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5160
5235
|
if (responseChunk.content !== null) {
|
|
5161
5236
|
accumulatedContent += responseChunk.content;
|
|
5162
5237
|
}
|
|
5163
|
-
|
|
5164
|
-
`
|
|
5238
|
+
this.logger.debug(
|
|
5239
|
+
`Chunk received - delta: "${choice.delta?.content || ""}"`,
|
|
5165
5240
|
`responseChunk content: "${responseChunk.content || ""}"`,
|
|
5166
5241
|
`is_partial: ${responseChunk.is_partial}`,
|
|
5167
5242
|
`accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
@@ -5190,12 +5265,12 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5190
5265
|
}
|
|
5191
5266
|
responseChunk.tool_calls = Array.from(partialToolCalls.values());
|
|
5192
5267
|
}
|
|
5193
|
-
|
|
5268
|
+
this.logger.debug("Yielding chunk to caller");
|
|
5194
5269
|
yield responseChunk;
|
|
5195
5270
|
}
|
|
5196
5271
|
if (accumulatedContent.length > 0) {
|
|
5197
|
-
|
|
5198
|
-
`
|
|
5272
|
+
this.logger.debug(
|
|
5273
|
+
`Yielding final accumulated content: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
5199
5274
|
);
|
|
5200
5275
|
yield new LLMResponse({
|
|
5201
5276
|
content: accumulatedContent,
|
|
@@ -5203,14 +5278,14 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5203
5278
|
is_partial: false
|
|
5204
5279
|
});
|
|
5205
5280
|
}
|
|
5206
|
-
|
|
5281
|
+
this.logger.debug("Finished processing all stream chunks");
|
|
5207
5282
|
} else {
|
|
5208
|
-
|
|
5283
|
+
this.logger.debug("Making non-streaming request");
|
|
5209
5284
|
const response = await this.client.chat.completions.create(params);
|
|
5210
5285
|
if (!response.choices || response.choices.length === 0) {
|
|
5211
5286
|
throw new Error("No response from OpenAI");
|
|
5212
5287
|
}
|
|
5213
|
-
|
|
5288
|
+
this.logger.debug("Non-streaming response received");
|
|
5214
5289
|
yield this.convertResponse(response.choices[0]);
|
|
5215
5290
|
}
|
|
5216
5291
|
} catch (error) {
|
|
@@ -5797,7 +5872,7 @@ var InMemoryMemoryService = class {
|
|
|
5797
5872
|
};
|
|
5798
5873
|
|
|
5799
5874
|
// src/memory/persistent-memory-service.ts
|
|
5800
|
-
|
|
5875
|
+
init_logger();
|
|
5801
5876
|
import fs2 from "fs";
|
|
5802
5877
|
import path2 from "path";
|
|
5803
5878
|
var PersistentMemoryService = class {
|
|
@@ -5813,6 +5888,7 @@ var PersistentMemoryService = class {
|
|
|
5813
5888
|
* File prefix for memory files
|
|
5814
5889
|
*/
|
|
5815
5890
|
filePrefix;
|
|
5891
|
+
logger = new Logger({ name: "PersistentMemoryService" });
|
|
5816
5892
|
/**
|
|
5817
5893
|
* Constructor for PersistentMemoryService
|
|
5818
5894
|
*/
|
|
@@ -5901,7 +5977,7 @@ var PersistentMemoryService = class {
|
|
|
5901
5977
|
}
|
|
5902
5978
|
}
|
|
5903
5979
|
}
|
|
5904
|
-
|
|
5980
|
+
this.logger.debug(
|
|
5905
5981
|
`Loaded ${this.inMemoryService.getAllSessions().length} sessions from persistent storage`
|
|
5906
5982
|
);
|
|
5907
5983
|
} catch (error) {
|