@agentforge/patterns 0.16.56 → 0.16.57
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 +63 -43
- package/dist/index.js +63 -43
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2691,8 +2691,14 @@ function getRoutingStrategy(name) {
|
|
|
2691
2691
|
return routingStrategies[name];
|
|
2692
2692
|
}
|
|
2693
2693
|
|
|
2694
|
-
// src/multi-agent/utils.ts
|
|
2695
|
-
|
|
2694
|
+
// src/multi-agent/utils-react-detection.ts
|
|
2695
|
+
function isReActAgent(obj) {
|
|
2696
|
+
return Boolean(
|
|
2697
|
+
obj && typeof obj === "object" && "invoke" in obj && typeof obj.invoke === "function" && "stream" in obj && typeof obj.stream === "function" && (obj.constructor?.name === "CompiledGraph" || obj.constructor?.name === "CompiledStateGraph")
|
|
2698
|
+
);
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2701
|
+
// src/multi-agent/utils-shared.ts
|
|
2696
2702
|
function isRecord2(value) {
|
|
2697
2703
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2698
2704
|
}
|
|
@@ -2714,6 +2720,8 @@ function getReActResultShape(value) {
|
|
|
2714
2720
|
iteration: value.iteration
|
|
2715
2721
|
};
|
|
2716
2722
|
}
|
|
2723
|
+
|
|
2724
|
+
// src/multi-agent/utils-react-result.ts
|
|
2717
2725
|
function safeSerializeContent(content) {
|
|
2718
2726
|
if (content === null || content === void 0) {
|
|
2719
2727
|
return void 0;
|
|
@@ -2748,34 +2756,59 @@ function safeSerializeContent(content) {
|
|
|
2748
2756
|
return fallback.length > 0 ? fallback : void 0;
|
|
2749
2757
|
}
|
|
2750
2758
|
function extractResponse(resultShape) {
|
|
2751
|
-
const
|
|
2752
|
-
const lastMessage = messages?.[messages.length - 1];
|
|
2759
|
+
const lastMessage = resultShape.messages?.[resultShape.messages.length - 1];
|
|
2753
2760
|
const serialized = safeSerializeContent(lastMessage?.content);
|
|
2754
2761
|
return serialized ?? "No response";
|
|
2755
2762
|
}
|
|
2756
2763
|
function extractToolsUsed(resultShape) {
|
|
2757
|
-
const
|
|
2758
|
-
const names = actions?.map((action) => action.name).filter((name) => typeof name === "string" && name.length > 0) || [];
|
|
2764
|
+
const names = resultShape.actions?.map((action) => action.name).filter((name) => typeof name === "string" && name.length > 0) ?? [];
|
|
2759
2765
|
return [...new Set(names)];
|
|
2760
2766
|
}
|
|
2761
2767
|
function extractIteration(resultShape) {
|
|
2762
|
-
|
|
2763
|
-
return typeof iteration === "number" && Number.isFinite(iteration) ? iteration : 0;
|
|
2768
|
+
return typeof resultShape.iteration === "number" && Number.isFinite(resultShape.iteration) ? resultShape.iteration : 0;
|
|
2764
2769
|
}
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2770
|
+
|
|
2771
|
+
// src/multi-agent/utils-react-wrapper.ts
|
|
2772
|
+
var logger2 = createPatternLogger("agentforge:patterns:multi-agent:utils");
|
|
2773
|
+
function findCurrentAssignment(state, workerId) {
|
|
2774
|
+
return state.activeAssignments.find(
|
|
2775
|
+
(assignment) => assignment.workerId === workerId && !state.completedTasks.some((task) => task.assignmentId === assignment.id)
|
|
2769
2776
|
);
|
|
2770
2777
|
}
|
|
2778
|
+
function buildWorkerConfig(workerId, runnableConfig) {
|
|
2779
|
+
const parentThreadId = runnableConfig?.configurable?.thread_id;
|
|
2780
|
+
const workerThreadId = parentThreadId !== void 0 ? `${parentThreadId}:worker:${workerId}` : void 0;
|
|
2781
|
+
if (!workerThreadId) {
|
|
2782
|
+
return runnableConfig;
|
|
2783
|
+
}
|
|
2784
|
+
return {
|
|
2785
|
+
...runnableConfig,
|
|
2786
|
+
configurable: {
|
|
2787
|
+
...runnableConfig?.configurable ?? {},
|
|
2788
|
+
thread_id: workerThreadId
|
|
2789
|
+
}
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
function createSuccessfulTaskResult(assignmentId, workerId, response, toolsUsed, iteration) {
|
|
2793
|
+
return {
|
|
2794
|
+
assignmentId,
|
|
2795
|
+
workerId,
|
|
2796
|
+
result: response,
|
|
2797
|
+
completedAt: Date.now(),
|
|
2798
|
+
success: true,
|
|
2799
|
+
metadata: {
|
|
2800
|
+
agent_type: "react",
|
|
2801
|
+
iterations: iteration,
|
|
2802
|
+
tools_used: toolsUsed
|
|
2803
|
+
}
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
2771
2806
|
function wrapReActAgent(workerId, agent, verbose = false) {
|
|
2772
2807
|
return async (state, config) => {
|
|
2773
2808
|
try {
|
|
2774
2809
|
logger2.debug("Wrapping ReAct agent execution", { workerId });
|
|
2775
2810
|
const runnableConfig = toRunnableConfig(config);
|
|
2776
|
-
const currentAssignment = state
|
|
2777
|
-
(assignment) => assignment.workerId === workerId && !state.completedTasks.some((task2) => task2.assignmentId === assignment.id)
|
|
2778
|
-
);
|
|
2811
|
+
const currentAssignment = findCurrentAssignment(state, workerId);
|
|
2779
2812
|
if (!currentAssignment) {
|
|
2780
2813
|
logger2.debug("No active assignment found", { workerId });
|
|
2781
2814
|
return {};
|
|
@@ -2786,26 +2819,17 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2786
2819
|
assignmentId: currentAssignment.id,
|
|
2787
2820
|
taskPreview: task.substring(0, 100) + (task.length > 100 ? "..." : "")
|
|
2788
2821
|
});
|
|
2789
|
-
const
|
|
2790
|
-
const
|
|
2791
|
-
...runnableConfig,
|
|
2792
|
-
configurable: {
|
|
2793
|
-
...runnableConfig?.configurable ?? {},
|
|
2794
|
-
thread_id: workerThreadId
|
|
2795
|
-
}
|
|
2796
|
-
} : runnableConfig;
|
|
2822
|
+
const workerConfig = buildWorkerConfig(workerId, runnableConfig);
|
|
2823
|
+
const workerThreadId = workerConfig?.configurable?.thread_id;
|
|
2797
2824
|
logger2.debug("Invoking ReAct agent with worker-specific config", {
|
|
2798
2825
|
workerId,
|
|
2799
2826
|
...runnableConfig?.configurable?.thread_id !== void 0 ? { parentThreadId: String(runnableConfig.configurable.thread_id) } : {},
|
|
2800
|
-
...workerThreadId ? { workerThreadId } : {},
|
|
2827
|
+
...workerThreadId ? { workerThreadId: String(workerThreadId) } : {},
|
|
2801
2828
|
hasConfig: !!workerConfig
|
|
2802
2829
|
});
|
|
2803
2830
|
const result = await agent.invoke(
|
|
2804
|
-
{
|
|
2805
|
-
messages: [{ role: "user", content: task }]
|
|
2806
|
-
},
|
|
2831
|
+
{ messages: [{ role: "user", content: task }] },
|
|
2807
2832
|
workerConfig
|
|
2808
|
-
// Worker-specific config with unique thread_id
|
|
2809
2833
|
);
|
|
2810
2834
|
const resultShape = getReActResultShape(result);
|
|
2811
2835
|
const response = extractResponse(resultShape);
|
|
@@ -2817,20 +2841,16 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2817
2841
|
if (uniqueTools.length > 0) {
|
|
2818
2842
|
logger2.debug("Tools used by ReAct agent", { workerId, tools: uniqueTools });
|
|
2819
2843
|
}
|
|
2820
|
-
const taskResult = {
|
|
2821
|
-
assignmentId: currentAssignment.id,
|
|
2822
|
-
workerId,
|
|
2823
|
-
result: response,
|
|
2824
|
-
completedAt: Date.now(),
|
|
2825
|
-
success: true,
|
|
2826
|
-
metadata: {
|
|
2827
|
-
agent_type: "react",
|
|
2828
|
-
iterations: extractIteration(resultShape),
|
|
2829
|
-
tools_used: uniqueTools
|
|
2830
|
-
}
|
|
2831
|
-
};
|
|
2832
2844
|
return {
|
|
2833
|
-
completedTasks: [
|
|
2845
|
+
completedTasks: [
|
|
2846
|
+
createSuccessfulTaskResult(
|
|
2847
|
+
currentAssignment.id,
|
|
2848
|
+
workerId,
|
|
2849
|
+
response,
|
|
2850
|
+
uniqueTools,
|
|
2851
|
+
extractIteration(resultShape)
|
|
2852
|
+
)
|
|
2853
|
+
]
|
|
2834
2854
|
};
|
|
2835
2855
|
} catch (error) {
|
|
2836
2856
|
const errorMessage = handleNodeError(error, `react-agent:${workerId}`, verbose);
|
|
@@ -2900,7 +2920,7 @@ function createAssignmentMessages(assignments) {
|
|
|
2900
2920
|
}
|
|
2901
2921
|
}));
|
|
2902
2922
|
}
|
|
2903
|
-
function
|
|
2923
|
+
function findCurrentAssignment2(state, workerId) {
|
|
2904
2924
|
return state.activeAssignments.find(
|
|
2905
2925
|
(assignment) => assignment.workerId === workerId && !state.completedTasks.some((task) => task.assignmentId === assignment.id)
|
|
2906
2926
|
);
|
|
@@ -3350,7 +3370,7 @@ function createWorkerNode(config) {
|
|
|
3350
3370
|
iteration: state.iteration,
|
|
3351
3371
|
activeAssignments: state.activeAssignments.length
|
|
3352
3372
|
});
|
|
3353
|
-
const currentAssignment =
|
|
3373
|
+
const currentAssignment = findCurrentAssignment2(state, id);
|
|
3354
3374
|
if (!currentAssignment) {
|
|
3355
3375
|
logger3.debug("No active assignment found for worker", {
|
|
3356
3376
|
workerId: id,
|
package/dist/index.js
CHANGED
|
@@ -2593,8 +2593,14 @@ function getRoutingStrategy(name) {
|
|
|
2593
2593
|
return routingStrategies[name];
|
|
2594
2594
|
}
|
|
2595
2595
|
|
|
2596
|
-
// src/multi-agent/utils.ts
|
|
2597
|
-
|
|
2596
|
+
// src/multi-agent/utils-react-detection.ts
|
|
2597
|
+
function isReActAgent(obj) {
|
|
2598
|
+
return Boolean(
|
|
2599
|
+
obj && typeof obj === "object" && "invoke" in obj && typeof obj.invoke === "function" && "stream" in obj && typeof obj.stream === "function" && (obj.constructor?.name === "CompiledGraph" || obj.constructor?.name === "CompiledStateGraph")
|
|
2600
|
+
);
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
// src/multi-agent/utils-shared.ts
|
|
2598
2604
|
function isRecord2(value) {
|
|
2599
2605
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2600
2606
|
}
|
|
@@ -2616,6 +2622,8 @@ function getReActResultShape(value) {
|
|
|
2616
2622
|
iteration: value.iteration
|
|
2617
2623
|
};
|
|
2618
2624
|
}
|
|
2625
|
+
|
|
2626
|
+
// src/multi-agent/utils-react-result.ts
|
|
2619
2627
|
function safeSerializeContent(content) {
|
|
2620
2628
|
if (content === null || content === void 0) {
|
|
2621
2629
|
return void 0;
|
|
@@ -2650,34 +2658,59 @@ function safeSerializeContent(content) {
|
|
|
2650
2658
|
return fallback.length > 0 ? fallback : void 0;
|
|
2651
2659
|
}
|
|
2652
2660
|
function extractResponse(resultShape) {
|
|
2653
|
-
const
|
|
2654
|
-
const lastMessage = messages?.[messages.length - 1];
|
|
2661
|
+
const lastMessage = resultShape.messages?.[resultShape.messages.length - 1];
|
|
2655
2662
|
const serialized = safeSerializeContent(lastMessage?.content);
|
|
2656
2663
|
return serialized ?? "No response";
|
|
2657
2664
|
}
|
|
2658
2665
|
function extractToolsUsed(resultShape) {
|
|
2659
|
-
const
|
|
2660
|
-
const names = actions?.map((action) => action.name).filter((name) => typeof name === "string" && name.length > 0) || [];
|
|
2666
|
+
const names = resultShape.actions?.map((action) => action.name).filter((name) => typeof name === "string" && name.length > 0) ?? [];
|
|
2661
2667
|
return [...new Set(names)];
|
|
2662
2668
|
}
|
|
2663
2669
|
function extractIteration(resultShape) {
|
|
2664
|
-
|
|
2665
|
-
return typeof iteration === "number" && Number.isFinite(iteration) ? iteration : 0;
|
|
2670
|
+
return typeof resultShape.iteration === "number" && Number.isFinite(resultShape.iteration) ? resultShape.iteration : 0;
|
|
2666
2671
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2672
|
+
|
|
2673
|
+
// src/multi-agent/utils-react-wrapper.ts
|
|
2674
|
+
var logger2 = createPatternLogger("agentforge:patterns:multi-agent:utils");
|
|
2675
|
+
function findCurrentAssignment(state, workerId) {
|
|
2676
|
+
return state.activeAssignments.find(
|
|
2677
|
+
(assignment) => assignment.workerId === workerId && !state.completedTasks.some((task) => task.assignmentId === assignment.id)
|
|
2671
2678
|
);
|
|
2672
2679
|
}
|
|
2680
|
+
function buildWorkerConfig(workerId, runnableConfig) {
|
|
2681
|
+
const parentThreadId = runnableConfig?.configurable?.thread_id;
|
|
2682
|
+
const workerThreadId = parentThreadId !== void 0 ? `${parentThreadId}:worker:${workerId}` : void 0;
|
|
2683
|
+
if (!workerThreadId) {
|
|
2684
|
+
return runnableConfig;
|
|
2685
|
+
}
|
|
2686
|
+
return {
|
|
2687
|
+
...runnableConfig,
|
|
2688
|
+
configurable: {
|
|
2689
|
+
...runnableConfig?.configurable ?? {},
|
|
2690
|
+
thread_id: workerThreadId
|
|
2691
|
+
}
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
function createSuccessfulTaskResult(assignmentId, workerId, response, toolsUsed, iteration) {
|
|
2695
|
+
return {
|
|
2696
|
+
assignmentId,
|
|
2697
|
+
workerId,
|
|
2698
|
+
result: response,
|
|
2699
|
+
completedAt: Date.now(),
|
|
2700
|
+
success: true,
|
|
2701
|
+
metadata: {
|
|
2702
|
+
agent_type: "react",
|
|
2703
|
+
iterations: iteration,
|
|
2704
|
+
tools_used: toolsUsed
|
|
2705
|
+
}
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2673
2708
|
function wrapReActAgent(workerId, agent, verbose = false) {
|
|
2674
2709
|
return async (state, config) => {
|
|
2675
2710
|
try {
|
|
2676
2711
|
logger2.debug("Wrapping ReAct agent execution", { workerId });
|
|
2677
2712
|
const runnableConfig = toRunnableConfig(config);
|
|
2678
|
-
const currentAssignment = state
|
|
2679
|
-
(assignment) => assignment.workerId === workerId && !state.completedTasks.some((task2) => task2.assignmentId === assignment.id)
|
|
2680
|
-
);
|
|
2713
|
+
const currentAssignment = findCurrentAssignment(state, workerId);
|
|
2681
2714
|
if (!currentAssignment) {
|
|
2682
2715
|
logger2.debug("No active assignment found", { workerId });
|
|
2683
2716
|
return {};
|
|
@@ -2688,26 +2721,17 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2688
2721
|
assignmentId: currentAssignment.id,
|
|
2689
2722
|
taskPreview: task.substring(0, 100) + (task.length > 100 ? "..." : "")
|
|
2690
2723
|
});
|
|
2691
|
-
const
|
|
2692
|
-
const
|
|
2693
|
-
...runnableConfig,
|
|
2694
|
-
configurable: {
|
|
2695
|
-
...runnableConfig?.configurable ?? {},
|
|
2696
|
-
thread_id: workerThreadId
|
|
2697
|
-
}
|
|
2698
|
-
} : runnableConfig;
|
|
2724
|
+
const workerConfig = buildWorkerConfig(workerId, runnableConfig);
|
|
2725
|
+
const workerThreadId = workerConfig?.configurable?.thread_id;
|
|
2699
2726
|
logger2.debug("Invoking ReAct agent with worker-specific config", {
|
|
2700
2727
|
workerId,
|
|
2701
2728
|
...runnableConfig?.configurable?.thread_id !== void 0 ? { parentThreadId: String(runnableConfig.configurable.thread_id) } : {},
|
|
2702
|
-
...workerThreadId ? { workerThreadId } : {},
|
|
2729
|
+
...workerThreadId ? { workerThreadId: String(workerThreadId) } : {},
|
|
2703
2730
|
hasConfig: !!workerConfig
|
|
2704
2731
|
});
|
|
2705
2732
|
const result = await agent.invoke(
|
|
2706
|
-
{
|
|
2707
|
-
messages: [{ role: "user", content: task }]
|
|
2708
|
-
},
|
|
2733
|
+
{ messages: [{ role: "user", content: task }] },
|
|
2709
2734
|
workerConfig
|
|
2710
|
-
// Worker-specific config with unique thread_id
|
|
2711
2735
|
);
|
|
2712
2736
|
const resultShape = getReActResultShape(result);
|
|
2713
2737
|
const response = extractResponse(resultShape);
|
|
@@ -2719,20 +2743,16 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2719
2743
|
if (uniqueTools.length > 0) {
|
|
2720
2744
|
logger2.debug("Tools used by ReAct agent", { workerId, tools: uniqueTools });
|
|
2721
2745
|
}
|
|
2722
|
-
const taskResult = {
|
|
2723
|
-
assignmentId: currentAssignment.id,
|
|
2724
|
-
workerId,
|
|
2725
|
-
result: response,
|
|
2726
|
-
completedAt: Date.now(),
|
|
2727
|
-
success: true,
|
|
2728
|
-
metadata: {
|
|
2729
|
-
agent_type: "react",
|
|
2730
|
-
iterations: extractIteration(resultShape),
|
|
2731
|
-
tools_used: uniqueTools
|
|
2732
|
-
}
|
|
2733
|
-
};
|
|
2734
2746
|
return {
|
|
2735
|
-
completedTasks: [
|
|
2747
|
+
completedTasks: [
|
|
2748
|
+
createSuccessfulTaskResult(
|
|
2749
|
+
currentAssignment.id,
|
|
2750
|
+
workerId,
|
|
2751
|
+
response,
|
|
2752
|
+
uniqueTools,
|
|
2753
|
+
extractIteration(resultShape)
|
|
2754
|
+
)
|
|
2755
|
+
]
|
|
2736
2756
|
};
|
|
2737
2757
|
} catch (error) {
|
|
2738
2758
|
const errorMessage = handleNodeError(error, `react-agent:${workerId}`, verbose);
|
|
@@ -2802,7 +2822,7 @@ function createAssignmentMessages(assignments) {
|
|
|
2802
2822
|
}
|
|
2803
2823
|
}));
|
|
2804
2824
|
}
|
|
2805
|
-
function
|
|
2825
|
+
function findCurrentAssignment2(state, workerId) {
|
|
2806
2826
|
return state.activeAssignments.find(
|
|
2807
2827
|
(assignment) => assignment.workerId === workerId && !state.completedTasks.some((task) => task.assignmentId === assignment.id)
|
|
2808
2828
|
);
|
|
@@ -3252,7 +3272,7 @@ function createWorkerNode(config) {
|
|
|
3252
3272
|
iteration: state.iteration,
|
|
3253
3273
|
activeAssignments: state.activeAssignments.length
|
|
3254
3274
|
});
|
|
3255
|
-
const currentAssignment =
|
|
3275
|
+
const currentAssignment = findCurrentAssignment2(state, id);
|
|
3256
3276
|
if (!currentAssignment) {
|
|
3257
3277
|
logger3.debug("No active assignment found for worker", {
|
|
3258
3278
|
workerId: id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/patterns",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.57",
|
|
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.
|
|
44
|
+
"@agentforge/core": "0.16.57",
|
|
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.
|
|
50
|
+
"@agentforge/testing": "0.16.57",
|
|
51
51
|
"@eslint/js": "^9.17.0",
|
|
52
52
|
"@types/node": "^22.10.2",
|
|
53
53
|
"eslint": "^9.17.0",
|