@agentforge/patterns 0.16.89 → 0.16.90

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/index.cjs CHANGED
@@ -1140,32 +1140,17 @@ var plannerLogger = createPatternLogger("agentforge:patterns:plan-execute:planne
1140
1140
  var executorLogger = createPatternLogger("agentforge:patterns:plan-execute:executor");
1141
1141
  var replannerLogger = createPatternLogger("agentforge:patterns:plan-execute:replanner");
1142
1142
 
1143
- // src/plan-execute/serialization.ts
1143
+ // src/plan-execute/model-response.ts
1144
1144
  function hasTextContentPart(value) {
1145
1145
  return typeof value === "object" && value !== null && "text" in value && typeof value.text === "string";
1146
1146
  }
1147
- function stringifyWithFallback(value, fallbackLabel) {
1147
+ function stringifyModelContent(value) {
1148
1148
  try {
1149
1149
  const serialized = JSON.stringify(value);
1150
- if (serialized === void 0) {
1151
- return "undefined";
1152
- }
1153
- return serialized;
1154
- } catch (error) {
1155
- const reason = error instanceof Error ? error.message : String(error);
1156
- return `[${fallbackLabel}: ${reason}]`;
1157
- }
1158
- }
1159
- function toJsonSafeValue(value) {
1160
- try {
1161
- const serialized = JSON.stringify(value);
1162
- if (serialized === void 0) {
1163
- return void 0;
1164
- }
1165
- return JSON.parse(serialized);
1150
+ return serialized === void 0 ? "undefined" : serialized;
1166
1151
  } catch (error) {
1167
1152
  const reason = error instanceof Error ? error.message : String(error);
1168
- return `[Unserializable step result: ${reason}]`;
1153
+ return `[Unserializable model content: ${reason}]`;
1169
1154
  }
1170
1155
  }
1171
1156
  function normalizeModelContent(content) {
@@ -1183,10 +1168,15 @@ function normalizeModelContent(content) {
1183
1168
  return textParts.join("\n");
1184
1169
  }
1185
1170
  }
1186
- return stringifyWithFallback(content, "Unserializable model content");
1171
+ return stringifyModelContent(content);
1187
1172
  }
1188
- function serializePlanExecuteResult(result) {
1189
- return stringifyWithFallback(result, "Unserializable step result");
1173
+ function parseModelResponse(content, context) {
1174
+ const normalized = normalizeModelContent(content);
1175
+ try {
1176
+ return JSON.parse(normalized);
1177
+ } catch (parseError) {
1178
+ throw new Error(`Failed to parse ${context} from LLM response: ${parseError}`);
1179
+ }
1190
1180
  }
1191
1181
 
1192
1182
  // src/plan-execute/planner-node.ts
@@ -1215,19 +1205,13 @@ function createPlannerNode(config) {
1215
1205
  new import_messages2.HumanMessage(userPrompt)
1216
1206
  ];
1217
1207
  const response = await model.invoke(messages);
1218
- const content = normalizeModelContent(response.content);
1219
- let plan;
1220
- try {
1221
- const parsed = JSON.parse(content);
1222
- plan = {
1223
- steps: parsed.steps.slice(0, maxSteps),
1224
- goal: parsed.goal || state.input || "",
1225
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1226
- confidence: parsed.confidence
1227
- };
1228
- } catch (parseError) {
1229
- throw new Error(`Failed to parse plan from LLM response: ${parseError}`);
1230
- }
1208
+ const parsed = parseModelResponse(response.content, "plan");
1209
+ const plan = {
1210
+ steps: parsed.steps.slice(0, maxSteps),
1211
+ goal: parsed.goal || state.input || "",
1212
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1213
+ confidence: parsed.confidence
1214
+ };
1231
1215
  plannerLogger.info("Plan created", {
1232
1216
  stepCount: plan.steps.length,
1233
1217
  goal: plan.goal.substring(0, 100),
@@ -1418,6 +1402,37 @@ function createExecutorNode(config) {
1418
1402
 
1419
1403
  // src/plan-execute/replanner-node.ts
1420
1404
  var import_messages3 = require("@langchain/core/messages");
1405
+
1406
+ // src/plan-execute/serialization.ts
1407
+ function stringifyWithFallback(value, fallbackLabel) {
1408
+ try {
1409
+ const serialized = JSON.stringify(value);
1410
+ if (serialized === void 0) {
1411
+ return "undefined";
1412
+ }
1413
+ return serialized;
1414
+ } catch (error) {
1415
+ const reason = error instanceof Error ? error.message : String(error);
1416
+ return `[${fallbackLabel}: ${reason}]`;
1417
+ }
1418
+ }
1419
+ function toJsonSafeValue(value) {
1420
+ try {
1421
+ const serialized = JSON.stringify(value);
1422
+ if (serialized === void 0) {
1423
+ return void 0;
1424
+ }
1425
+ return JSON.parse(serialized);
1426
+ } catch (error) {
1427
+ const reason = error instanceof Error ? error.message : String(error);
1428
+ return `[Unserializable step result: ${reason}]`;
1429
+ }
1430
+ }
1431
+ function serializePlanExecuteResult(result) {
1432
+ return stringifyWithFallback(result, "Unserializable step result");
1433
+ }
1434
+
1435
+ // src/plan-execute/replanner-node.ts
1421
1436
  function createReplannerNode(config) {
1422
1437
  const {
1423
1438
  model,
@@ -1455,13 +1470,7 @@ function createReplannerNode(config) {
1455
1470
  new import_messages3.HumanMessage(userPrompt)
1456
1471
  ];
1457
1472
  const response = await model.invoke(messages);
1458
- const content = normalizeModelContent(response.content);
1459
- let decision;
1460
- try {
1461
- decision = JSON.parse(content);
1462
- } catch (parseError) {
1463
- throw new Error(`Failed to parse replan decision from LLM response: ${parseError}`);
1464
- }
1473
+ const decision = parseModelResponse(response.content, "replan decision");
1465
1474
  if (decision.shouldReplan) {
1466
1475
  replannerLogger.info("Replanning triggered", {
1467
1476
  reason: decision.reason,
package/dist/index.js CHANGED
@@ -1042,32 +1042,17 @@ var plannerLogger = createPatternLogger("agentforge:patterns:plan-execute:planne
1042
1042
  var executorLogger = createPatternLogger("agentforge:patterns:plan-execute:executor");
1043
1043
  var replannerLogger = createPatternLogger("agentforge:patterns:plan-execute:replanner");
1044
1044
 
1045
- // src/plan-execute/serialization.ts
1045
+ // src/plan-execute/model-response.ts
1046
1046
  function hasTextContentPart(value) {
1047
1047
  return typeof value === "object" && value !== null && "text" in value && typeof value.text === "string";
1048
1048
  }
1049
- function stringifyWithFallback(value, fallbackLabel) {
1049
+ function stringifyModelContent(value) {
1050
1050
  try {
1051
1051
  const serialized = JSON.stringify(value);
1052
- if (serialized === void 0) {
1053
- return "undefined";
1054
- }
1055
- return serialized;
1056
- } catch (error) {
1057
- const reason = error instanceof Error ? error.message : String(error);
1058
- return `[${fallbackLabel}: ${reason}]`;
1059
- }
1060
- }
1061
- function toJsonSafeValue(value) {
1062
- try {
1063
- const serialized = JSON.stringify(value);
1064
- if (serialized === void 0) {
1065
- return void 0;
1066
- }
1067
- return JSON.parse(serialized);
1052
+ return serialized === void 0 ? "undefined" : serialized;
1068
1053
  } catch (error) {
1069
1054
  const reason = error instanceof Error ? error.message : String(error);
1070
- return `[Unserializable step result: ${reason}]`;
1055
+ return `[Unserializable model content: ${reason}]`;
1071
1056
  }
1072
1057
  }
1073
1058
  function normalizeModelContent(content) {
@@ -1085,10 +1070,15 @@ function normalizeModelContent(content) {
1085
1070
  return textParts.join("\n");
1086
1071
  }
1087
1072
  }
1088
- return stringifyWithFallback(content, "Unserializable model content");
1073
+ return stringifyModelContent(content);
1089
1074
  }
1090
- function serializePlanExecuteResult(result) {
1091
- return stringifyWithFallback(result, "Unserializable step result");
1075
+ function parseModelResponse(content, context) {
1076
+ const normalized = normalizeModelContent(content);
1077
+ try {
1078
+ return JSON.parse(normalized);
1079
+ } catch (parseError) {
1080
+ throw new Error(`Failed to parse ${context} from LLM response: ${parseError}`);
1081
+ }
1092
1082
  }
1093
1083
 
1094
1084
  // src/plan-execute/planner-node.ts
@@ -1117,19 +1107,13 @@ function createPlannerNode(config) {
1117
1107
  new HumanMessage2(userPrompt)
1118
1108
  ];
1119
1109
  const response = await model.invoke(messages);
1120
- const content = normalizeModelContent(response.content);
1121
- let plan;
1122
- try {
1123
- const parsed = JSON.parse(content);
1124
- plan = {
1125
- steps: parsed.steps.slice(0, maxSteps),
1126
- goal: parsed.goal || state.input || "",
1127
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1128
- confidence: parsed.confidence
1129
- };
1130
- } catch (parseError) {
1131
- throw new Error(`Failed to parse plan from LLM response: ${parseError}`);
1132
- }
1110
+ const parsed = parseModelResponse(response.content, "plan");
1111
+ const plan = {
1112
+ steps: parsed.steps.slice(0, maxSteps),
1113
+ goal: parsed.goal || state.input || "",
1114
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1115
+ confidence: parsed.confidence
1116
+ };
1133
1117
  plannerLogger.info("Plan created", {
1134
1118
  stepCount: plan.steps.length,
1135
1119
  goal: plan.goal.substring(0, 100),
@@ -1320,6 +1304,37 @@ function createExecutorNode(config) {
1320
1304
 
1321
1305
  // src/plan-execute/replanner-node.ts
1322
1306
  import { HumanMessage as HumanMessage3, SystemMessage as SystemMessage3 } from "@langchain/core/messages";
1307
+
1308
+ // src/plan-execute/serialization.ts
1309
+ function stringifyWithFallback(value, fallbackLabel) {
1310
+ try {
1311
+ const serialized = JSON.stringify(value);
1312
+ if (serialized === void 0) {
1313
+ return "undefined";
1314
+ }
1315
+ return serialized;
1316
+ } catch (error) {
1317
+ const reason = error instanceof Error ? error.message : String(error);
1318
+ return `[${fallbackLabel}: ${reason}]`;
1319
+ }
1320
+ }
1321
+ function toJsonSafeValue(value) {
1322
+ try {
1323
+ const serialized = JSON.stringify(value);
1324
+ if (serialized === void 0) {
1325
+ return void 0;
1326
+ }
1327
+ return JSON.parse(serialized);
1328
+ } catch (error) {
1329
+ const reason = error instanceof Error ? error.message : String(error);
1330
+ return `[Unserializable step result: ${reason}]`;
1331
+ }
1332
+ }
1333
+ function serializePlanExecuteResult(result) {
1334
+ return stringifyWithFallback(result, "Unserializable step result");
1335
+ }
1336
+
1337
+ // src/plan-execute/replanner-node.ts
1323
1338
  function createReplannerNode(config) {
1324
1339
  const {
1325
1340
  model,
@@ -1357,13 +1372,7 @@ function createReplannerNode(config) {
1357
1372
  new HumanMessage3(userPrompt)
1358
1373
  ];
1359
1374
  const response = await model.invoke(messages);
1360
- const content = normalizeModelContent(response.content);
1361
- let decision;
1362
- try {
1363
- decision = JSON.parse(content);
1364
- } catch (parseError) {
1365
- throw new Error(`Failed to parse replan decision from LLM response: ${parseError}`);
1366
- }
1375
+ const decision = parseModelResponse(response.content, "replan decision");
1367
1376
  if (decision.shouldReplan) {
1368
1377
  replannerLogger.info("Replanning triggered", {
1369
1378
  reason: decision.reason,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/patterns",
3
- "version": "0.16.89",
3
+ "version": "0.16.90",
4
4
  "description": "Production-ready agent workflow patterns for TypeScript including ReAct and Planner-Executor, built on LangGraph.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -41,13 +41,13 @@
41
41
  "url": "https://github.com/TVScoundrel/agentforge/issues"
42
42
  },
43
43
  "dependencies": {
44
- "@agentforge/core": "0.16.89",
44
+ "@agentforge/core": "0.16.90",
45
45
  "@langchain/core": "^1.1.17",
46
46
  "@langchain/langgraph": "^1.1.2",
47
47
  "zod": "^3.23.8"
48
48
  },
49
49
  "devDependencies": {
50
- "@agentforge/testing": "0.16.89",
50
+ "@agentforge/testing": "0.16.90",
51
51
  "@eslint/js": "^9.17.0",
52
52
  "@types/node": "^22.10.2",
53
53
  "eslint": "^9.17.0",