@agentforge/patterns 0.5.2 → 0.5.4
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 +12 -8
- package/dist/index.d.cts +181 -1
- package/dist/index.d.ts +181 -1
- package/dist/index.js +12 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -394,7 +394,8 @@ function createReActAgent(config, options) {
|
|
|
394
394
|
systemPrompt = DEFAULT_REACT_SYSTEM_PROMPT,
|
|
395
395
|
maxIterations = 10,
|
|
396
396
|
returnIntermediateSteps = false,
|
|
397
|
-
stopCondition
|
|
397
|
+
stopCondition,
|
|
398
|
+
checkpointer
|
|
398
399
|
} = config;
|
|
399
400
|
const {
|
|
400
401
|
verbose = false,
|
|
@@ -429,7 +430,7 @@ function createReActAgent(config, options) {
|
|
|
429
430
|
return ACTION_NODE;
|
|
430
431
|
};
|
|
431
432
|
const workflow = new import_langgraph.StateGraph(ReActState).addNode(REASONING_NODE, reasoningNode).addNode(ACTION_NODE, actionNode).addNode(OBSERVATION_NODE, observationNode).addEdge("__start__", REASONING_NODE).addConditionalEdges(REASONING_NODE, shouldContinue).addEdge(ACTION_NODE, OBSERVATION_NODE).addEdge(OBSERVATION_NODE, REASONING_NODE);
|
|
432
|
-
return workflow.compile();
|
|
433
|
+
return workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
433
434
|
}
|
|
434
435
|
|
|
435
436
|
// src/react/builder.ts
|
|
@@ -970,7 +971,8 @@ function createPlanExecuteAgent(config) {
|
|
|
970
971
|
executor,
|
|
971
972
|
replanner,
|
|
972
973
|
maxIterations = 5,
|
|
973
|
-
verbose = false
|
|
974
|
+
verbose = false,
|
|
975
|
+
checkpointer
|
|
974
976
|
} = config;
|
|
975
977
|
const plannerNode = createPlannerNode(planner);
|
|
976
978
|
const executorNode = createExecutorNode(executor);
|
|
@@ -1030,7 +1032,7 @@ function createPlanExecuteAgent(config) {
|
|
|
1030
1032
|
finish: import_langgraph2.END
|
|
1031
1033
|
}
|
|
1032
1034
|
);
|
|
1033
|
-
return workflow.compile();
|
|
1035
|
+
return workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
1034
1036
|
}
|
|
1035
1037
|
|
|
1036
1038
|
// src/reflection/state.ts
|
|
@@ -1507,7 +1509,8 @@ function createReflectionAgent(config) {
|
|
|
1507
1509
|
reviser,
|
|
1508
1510
|
maxIterations = 3,
|
|
1509
1511
|
qualityCriteria,
|
|
1510
|
-
verbose = false
|
|
1512
|
+
verbose = false,
|
|
1513
|
+
checkpointer
|
|
1511
1514
|
} = config;
|
|
1512
1515
|
const generatorNode = createGeneratorNode({ ...generator, verbose });
|
|
1513
1516
|
const reflectorNode = createReflectorNode({ ...reflector, qualityCriteria, verbose });
|
|
@@ -1565,7 +1568,7 @@ function createReflectionAgent(config) {
|
|
|
1565
1568
|
error: import_langgraph3.END
|
|
1566
1569
|
}
|
|
1567
1570
|
).addEdge("finisher", import_langgraph3.END);
|
|
1568
|
-
return workflow.compile();
|
|
1571
|
+
return workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
1569
1572
|
}
|
|
1570
1573
|
|
|
1571
1574
|
// src/multi-agent/state.ts
|
|
@@ -2422,7 +2425,8 @@ function createMultiAgentSystem(config) {
|
|
|
2422
2425
|
workers,
|
|
2423
2426
|
aggregator,
|
|
2424
2427
|
maxIterations = 10,
|
|
2425
|
-
verbose = false
|
|
2428
|
+
verbose = false,
|
|
2429
|
+
checkpointer
|
|
2426
2430
|
} = config;
|
|
2427
2431
|
const workflow = new import_langgraph4.StateGraph(MultiAgentState);
|
|
2428
2432
|
const supervisorNode = createSupervisorNode({
|
|
@@ -2475,7 +2479,7 @@ function createMultiAgentSystem(config) {
|
|
|
2475
2479
|
workflow.addConditionalEdges(workerId, workerRouter, ["supervisor"]);
|
|
2476
2480
|
}
|
|
2477
2481
|
workflow.addConditionalEdges("aggregator", aggregatorRouter, [import_langgraph4.END]);
|
|
2478
|
-
const compiled = workflow.compile();
|
|
2482
|
+
const compiled = workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
2479
2483
|
const originalInvoke = compiled.invoke.bind(compiled);
|
|
2480
2484
|
compiled.invoke = async function(input, config2) {
|
|
2481
2485
|
const mergedInput = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
3
|
-
import { CompiledStateGraph } from '@langchain/langgraph';
|
|
3
|
+
import { BaseCheckpointSaver, CompiledStateGraph } from '@langchain/langgraph';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
5
|
import { ToolRegistry, Tool } from '@agentforge/core';
|
|
6
6
|
|
|
@@ -164,6 +164,23 @@ interface ReActAgentConfig {
|
|
|
164
164
|
* Return true to stop the ReAct loop
|
|
165
165
|
*/
|
|
166
166
|
stopCondition?: (state: ReActStateType) => boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Optional checkpointer for state persistence
|
|
169
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
174
|
+
*
|
|
175
|
+
* const checkpointer = new MemorySaver();
|
|
176
|
+
* const agent = createReActAgent({
|
|
177
|
+
* model,
|
|
178
|
+
* tools,
|
|
179
|
+
* checkpointer
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
checkpointer?: BaseCheckpointSaver;
|
|
167
184
|
}
|
|
168
185
|
/**
|
|
169
186
|
* Options for the ReAct agent builder
|
|
@@ -221,6 +238,7 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
|
|
|
221
238
|
* @returns A compiled LangGraph StateGraph
|
|
222
239
|
*
|
|
223
240
|
* @example
|
|
241
|
+
* Basic usage:
|
|
224
242
|
* ```typescript
|
|
225
243
|
* import { createReActAgent } from '@agentforge/patterns';
|
|
226
244
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
@@ -236,6 +254,30 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
|
|
|
236
254
|
* messages: [{ role: 'user', content: 'What is the weather?' }]
|
|
237
255
|
* });
|
|
238
256
|
* ```
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
260
|
+
* ```typescript
|
|
261
|
+
* import { createReActAgent } from '@agentforge/patterns';
|
|
262
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
263
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
264
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
265
|
+
*
|
|
266
|
+
* const checkpointer = new MemorySaver();
|
|
267
|
+
* const askHuman = createAskHumanTool();
|
|
268
|
+
*
|
|
269
|
+
* const agent = createReActAgent({
|
|
270
|
+
* model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
271
|
+
* tools: [askHuman, ...otherTools],
|
|
272
|
+
* checkpointer // Required for askHuman tool
|
|
273
|
+
* });
|
|
274
|
+
*
|
|
275
|
+
* // Invoke with thread_id for conversation continuity
|
|
276
|
+
* const result = await agent.invoke(
|
|
277
|
+
* { messages: [{ role: 'user', content: 'Help me with this task' }] },
|
|
278
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
279
|
+
* );
|
|
280
|
+
* ```
|
|
239
281
|
*/
|
|
240
282
|
declare function createReActAgent(config: ReActAgentConfig, options?: ReActBuilderOptions): CompiledStateGraph<any, any>;
|
|
241
283
|
|
|
@@ -887,6 +929,23 @@ interface PlanExecuteAgentConfig {
|
|
|
887
929
|
* Verbose logging
|
|
888
930
|
*/
|
|
889
931
|
verbose?: boolean;
|
|
932
|
+
/**
|
|
933
|
+
* Optional checkpointer for state persistence
|
|
934
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* ```typescript
|
|
938
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
939
|
+
*
|
|
940
|
+
* const checkpointer = new MemorySaver();
|
|
941
|
+
* const agent = createPlanExecuteAgent({
|
|
942
|
+
* planner: { model },
|
|
943
|
+
* executor: { tools },
|
|
944
|
+
* checkpointer
|
|
945
|
+
* });
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
checkpointer?: BaseCheckpointSaver;
|
|
890
949
|
}
|
|
891
950
|
/**
|
|
892
951
|
* Node function type for Plan-Execute pattern
|
|
@@ -919,6 +978,7 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
919
978
|
* @returns A compiled LangGraph StateGraph
|
|
920
979
|
*
|
|
921
980
|
* @example
|
|
981
|
+
* Basic usage:
|
|
922
982
|
* ```typescript
|
|
923
983
|
* import { createPlanExecuteAgent } from '@agentforge/patterns';
|
|
924
984
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
@@ -942,6 +1002,30 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
942
1002
|
* input: 'Research the latest AI developments and summarize them'
|
|
943
1003
|
* });
|
|
944
1004
|
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
1008
|
+
* ```typescript
|
|
1009
|
+
* import { createPlanExecuteAgent } from '@agentforge/patterns';
|
|
1010
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
1011
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
1012
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
1013
|
+
*
|
|
1014
|
+
* const checkpointer = new MemorySaver();
|
|
1015
|
+
* const askHuman = createAskHumanTool();
|
|
1016
|
+
*
|
|
1017
|
+
* const agent = createPlanExecuteAgent({
|
|
1018
|
+
* planner: { model: new ChatOpenAI({ model: 'gpt-4' }), maxSteps: 5 },
|
|
1019
|
+
* executor: { tools: [askHuman, ...otherTools] },
|
|
1020
|
+
* checkpointer // Required for askHuman tool
|
|
1021
|
+
* });
|
|
1022
|
+
*
|
|
1023
|
+
* // Invoke with thread_id for conversation continuity
|
|
1024
|
+
* const result = await agent.invoke(
|
|
1025
|
+
* { input: 'Help me plan this project' },
|
|
1026
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
1027
|
+
* );
|
|
1028
|
+
* ```
|
|
945
1029
|
*/
|
|
946
1030
|
declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): any;
|
|
947
1031
|
|
|
@@ -1525,6 +1609,24 @@ interface ReflectionAgentConfig {
|
|
|
1525
1609
|
* Whether to include verbose logging
|
|
1526
1610
|
*/
|
|
1527
1611
|
verbose?: boolean;
|
|
1612
|
+
/**
|
|
1613
|
+
* Optional checkpointer for state persistence
|
|
1614
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
1615
|
+
*
|
|
1616
|
+
* @example
|
|
1617
|
+
* ```typescript
|
|
1618
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
1619
|
+
*
|
|
1620
|
+
* const checkpointer = new MemorySaver();
|
|
1621
|
+
* const agent = createReflectionAgent({
|
|
1622
|
+
* generator: { model },
|
|
1623
|
+
* reflector: { model },
|
|
1624
|
+
* reviser: { model },
|
|
1625
|
+
* checkpointer
|
|
1626
|
+
* });
|
|
1627
|
+
* ```
|
|
1628
|
+
*/
|
|
1629
|
+
checkpointer?: BaseCheckpointSaver;
|
|
1528
1630
|
}
|
|
1529
1631
|
/**
|
|
1530
1632
|
* Node function type for reflection pattern
|
|
@@ -1630,6 +1732,7 @@ declare function createFinisherNode(): (state: ReflectionStateType) => Promise<P
|
|
|
1630
1732
|
* @returns A compiled LangGraph StateGraph
|
|
1631
1733
|
*
|
|
1632
1734
|
* @example
|
|
1735
|
+
* Basic usage:
|
|
1633
1736
|
* ```typescript
|
|
1634
1737
|
* import { createReflectionAgent } from '@agentforge/patterns';
|
|
1635
1738
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
@@ -1651,6 +1754,32 @@ declare function createFinisherNode(): (state: ReflectionStateType) => Promise<P
|
|
|
1651
1754
|
* input: 'Write an essay about AI safety'
|
|
1652
1755
|
* });
|
|
1653
1756
|
* ```
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1759
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
1760
|
+
* ```typescript
|
|
1761
|
+
* import { createReflectionAgent } from '@agentforge/patterns';
|
|
1762
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
1763
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
1764
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
1765
|
+
*
|
|
1766
|
+
* const checkpointer = new MemorySaver();
|
|
1767
|
+
* const model = new ChatOpenAI({ model: 'gpt-4' });
|
|
1768
|
+
*
|
|
1769
|
+
* const agent = createReflectionAgent({
|
|
1770
|
+
* generator: { model },
|
|
1771
|
+
* reflector: { model },
|
|
1772
|
+
* reviser: { model },
|
|
1773
|
+
* maxIterations: 3,
|
|
1774
|
+
* checkpointer // Required for askHuman tool
|
|
1775
|
+
* });
|
|
1776
|
+
*
|
|
1777
|
+
* // Invoke with thread_id for conversation continuity
|
|
1778
|
+
* const result = await agent.invoke(
|
|
1779
|
+
* { input: 'Write a report on this topic' },
|
|
1780
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
1781
|
+
* );
|
|
1782
|
+
* ```
|
|
1654
1783
|
*/
|
|
1655
1784
|
declare function createReflectionAgent(config: ReflectionAgentConfig): any;
|
|
1656
1785
|
|
|
@@ -2387,6 +2516,23 @@ interface MultiAgentSystemConfig {
|
|
|
2387
2516
|
* Whether to include verbose logging
|
|
2388
2517
|
*/
|
|
2389
2518
|
verbose?: boolean;
|
|
2519
|
+
/**
|
|
2520
|
+
* Optional checkpointer for state persistence
|
|
2521
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
2522
|
+
*
|
|
2523
|
+
* @example
|
|
2524
|
+
* ```typescript
|
|
2525
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
2526
|
+
*
|
|
2527
|
+
* const checkpointer = new MemorySaver();
|
|
2528
|
+
* const system = createMultiAgentSystem({
|
|
2529
|
+
* supervisor: { strategy: 'skill-based', model },
|
|
2530
|
+
* workers: [...],
|
|
2531
|
+
* checkpointer
|
|
2532
|
+
* });
|
|
2533
|
+
* ```
|
|
2534
|
+
*/
|
|
2535
|
+
checkpointer?: BaseCheckpointSaver;
|
|
2390
2536
|
}
|
|
2391
2537
|
/**
|
|
2392
2538
|
* Node type for multi-agent graph
|
|
@@ -2494,6 +2640,7 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
|
|
|
2494
2640
|
* @returns Compiled LangGraph workflow
|
|
2495
2641
|
*
|
|
2496
2642
|
* @example
|
|
2643
|
+
* Basic usage:
|
|
2497
2644
|
* ```typescript
|
|
2498
2645
|
* const system = createMultiAgentSystem({
|
|
2499
2646
|
* supervisor: {
|
|
@@ -2531,6 +2678,39 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
|
|
|
2531
2678
|
* input: 'Research AI trends and write a summary',
|
|
2532
2679
|
* });
|
|
2533
2680
|
* ```
|
|
2681
|
+
*
|
|
2682
|
+
* @example
|
|
2683
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
2684
|
+
* ```typescript
|
|
2685
|
+
* import { createMultiAgentSystem } from '@agentforge/patterns';
|
|
2686
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
2687
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
2688
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
2689
|
+
*
|
|
2690
|
+
* const checkpointer = new MemorySaver();
|
|
2691
|
+
* const askHuman = createAskHumanTool();
|
|
2692
|
+
* const model = new ChatOpenAI({ model: 'gpt-4' });
|
|
2693
|
+
*
|
|
2694
|
+
* const system = createMultiAgentSystem({
|
|
2695
|
+
* supervisor: { strategy: 'skill-based', model },
|
|
2696
|
+
* workers: [
|
|
2697
|
+
* {
|
|
2698
|
+
* id: 'hr',
|
|
2699
|
+
* capabilities: { skills: ['hr'], tools: ['askHuman'], available: true, currentWorkload: 0 },
|
|
2700
|
+
* tools: [askHuman],
|
|
2701
|
+
* model,
|
|
2702
|
+
* },
|
|
2703
|
+
* ],
|
|
2704
|
+
* aggregator: { model },
|
|
2705
|
+
* checkpointer // Required for askHuman tool
|
|
2706
|
+
* });
|
|
2707
|
+
*
|
|
2708
|
+
* // Invoke with thread_id for conversation continuity
|
|
2709
|
+
* const result = await system.invoke(
|
|
2710
|
+
* { input: 'Help me with HR policy question' },
|
|
2711
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
2712
|
+
* );
|
|
2713
|
+
* ```
|
|
2534
2714
|
*/
|
|
2535
2715
|
declare function createMultiAgentSystem(config: MultiAgentSystemConfig): CompiledStateGraph<{
|
|
2536
2716
|
[x: string]: unknown;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
3
|
-
import { CompiledStateGraph } from '@langchain/langgraph';
|
|
3
|
+
import { BaseCheckpointSaver, CompiledStateGraph } from '@langchain/langgraph';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
5
|
import { ToolRegistry, Tool } from '@agentforge/core';
|
|
6
6
|
|
|
@@ -164,6 +164,23 @@ interface ReActAgentConfig {
|
|
|
164
164
|
* Return true to stop the ReAct loop
|
|
165
165
|
*/
|
|
166
166
|
stopCondition?: (state: ReActStateType) => boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Optional checkpointer for state persistence
|
|
169
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
174
|
+
*
|
|
175
|
+
* const checkpointer = new MemorySaver();
|
|
176
|
+
* const agent = createReActAgent({
|
|
177
|
+
* model,
|
|
178
|
+
* tools,
|
|
179
|
+
* checkpointer
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
checkpointer?: BaseCheckpointSaver;
|
|
167
184
|
}
|
|
168
185
|
/**
|
|
169
186
|
* Options for the ReAct agent builder
|
|
@@ -221,6 +238,7 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
|
|
|
221
238
|
* @returns A compiled LangGraph StateGraph
|
|
222
239
|
*
|
|
223
240
|
* @example
|
|
241
|
+
* Basic usage:
|
|
224
242
|
* ```typescript
|
|
225
243
|
* import { createReActAgent } from '@agentforge/patterns';
|
|
226
244
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
@@ -236,6 +254,30 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
|
|
|
236
254
|
* messages: [{ role: 'user', content: 'What is the weather?' }]
|
|
237
255
|
* });
|
|
238
256
|
* ```
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
260
|
+
* ```typescript
|
|
261
|
+
* import { createReActAgent } from '@agentforge/patterns';
|
|
262
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
263
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
264
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
265
|
+
*
|
|
266
|
+
* const checkpointer = new MemorySaver();
|
|
267
|
+
* const askHuman = createAskHumanTool();
|
|
268
|
+
*
|
|
269
|
+
* const agent = createReActAgent({
|
|
270
|
+
* model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
271
|
+
* tools: [askHuman, ...otherTools],
|
|
272
|
+
* checkpointer // Required for askHuman tool
|
|
273
|
+
* });
|
|
274
|
+
*
|
|
275
|
+
* // Invoke with thread_id for conversation continuity
|
|
276
|
+
* const result = await agent.invoke(
|
|
277
|
+
* { messages: [{ role: 'user', content: 'Help me with this task' }] },
|
|
278
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
279
|
+
* );
|
|
280
|
+
* ```
|
|
239
281
|
*/
|
|
240
282
|
declare function createReActAgent(config: ReActAgentConfig, options?: ReActBuilderOptions): CompiledStateGraph<any, any>;
|
|
241
283
|
|
|
@@ -887,6 +929,23 @@ interface PlanExecuteAgentConfig {
|
|
|
887
929
|
* Verbose logging
|
|
888
930
|
*/
|
|
889
931
|
verbose?: boolean;
|
|
932
|
+
/**
|
|
933
|
+
* Optional checkpointer for state persistence
|
|
934
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* ```typescript
|
|
938
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
939
|
+
*
|
|
940
|
+
* const checkpointer = new MemorySaver();
|
|
941
|
+
* const agent = createPlanExecuteAgent({
|
|
942
|
+
* planner: { model },
|
|
943
|
+
* executor: { tools },
|
|
944
|
+
* checkpointer
|
|
945
|
+
* });
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
checkpointer?: BaseCheckpointSaver;
|
|
890
949
|
}
|
|
891
950
|
/**
|
|
892
951
|
* Node function type for Plan-Execute pattern
|
|
@@ -919,6 +978,7 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
919
978
|
* @returns A compiled LangGraph StateGraph
|
|
920
979
|
*
|
|
921
980
|
* @example
|
|
981
|
+
* Basic usage:
|
|
922
982
|
* ```typescript
|
|
923
983
|
* import { createPlanExecuteAgent } from '@agentforge/patterns';
|
|
924
984
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
@@ -942,6 +1002,30 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
942
1002
|
* input: 'Research the latest AI developments and summarize them'
|
|
943
1003
|
* });
|
|
944
1004
|
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
1008
|
+
* ```typescript
|
|
1009
|
+
* import { createPlanExecuteAgent } from '@agentforge/patterns';
|
|
1010
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
1011
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
1012
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
1013
|
+
*
|
|
1014
|
+
* const checkpointer = new MemorySaver();
|
|
1015
|
+
* const askHuman = createAskHumanTool();
|
|
1016
|
+
*
|
|
1017
|
+
* const agent = createPlanExecuteAgent({
|
|
1018
|
+
* planner: { model: new ChatOpenAI({ model: 'gpt-4' }), maxSteps: 5 },
|
|
1019
|
+
* executor: { tools: [askHuman, ...otherTools] },
|
|
1020
|
+
* checkpointer // Required for askHuman tool
|
|
1021
|
+
* });
|
|
1022
|
+
*
|
|
1023
|
+
* // Invoke with thread_id for conversation continuity
|
|
1024
|
+
* const result = await agent.invoke(
|
|
1025
|
+
* { input: 'Help me plan this project' },
|
|
1026
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
1027
|
+
* );
|
|
1028
|
+
* ```
|
|
945
1029
|
*/
|
|
946
1030
|
declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): any;
|
|
947
1031
|
|
|
@@ -1525,6 +1609,24 @@ interface ReflectionAgentConfig {
|
|
|
1525
1609
|
* Whether to include verbose logging
|
|
1526
1610
|
*/
|
|
1527
1611
|
verbose?: boolean;
|
|
1612
|
+
/**
|
|
1613
|
+
* Optional checkpointer for state persistence
|
|
1614
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
1615
|
+
*
|
|
1616
|
+
* @example
|
|
1617
|
+
* ```typescript
|
|
1618
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
1619
|
+
*
|
|
1620
|
+
* const checkpointer = new MemorySaver();
|
|
1621
|
+
* const agent = createReflectionAgent({
|
|
1622
|
+
* generator: { model },
|
|
1623
|
+
* reflector: { model },
|
|
1624
|
+
* reviser: { model },
|
|
1625
|
+
* checkpointer
|
|
1626
|
+
* });
|
|
1627
|
+
* ```
|
|
1628
|
+
*/
|
|
1629
|
+
checkpointer?: BaseCheckpointSaver;
|
|
1528
1630
|
}
|
|
1529
1631
|
/**
|
|
1530
1632
|
* Node function type for reflection pattern
|
|
@@ -1630,6 +1732,7 @@ declare function createFinisherNode(): (state: ReflectionStateType) => Promise<P
|
|
|
1630
1732
|
* @returns A compiled LangGraph StateGraph
|
|
1631
1733
|
*
|
|
1632
1734
|
* @example
|
|
1735
|
+
* Basic usage:
|
|
1633
1736
|
* ```typescript
|
|
1634
1737
|
* import { createReflectionAgent } from '@agentforge/patterns';
|
|
1635
1738
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
@@ -1651,6 +1754,32 @@ declare function createFinisherNode(): (state: ReflectionStateType) => Promise<P
|
|
|
1651
1754
|
* input: 'Write an essay about AI safety'
|
|
1652
1755
|
* });
|
|
1653
1756
|
* ```
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1759
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
1760
|
+
* ```typescript
|
|
1761
|
+
* import { createReflectionAgent } from '@agentforge/patterns';
|
|
1762
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
1763
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
1764
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
1765
|
+
*
|
|
1766
|
+
* const checkpointer = new MemorySaver();
|
|
1767
|
+
* const model = new ChatOpenAI({ model: 'gpt-4' });
|
|
1768
|
+
*
|
|
1769
|
+
* const agent = createReflectionAgent({
|
|
1770
|
+
* generator: { model },
|
|
1771
|
+
* reflector: { model },
|
|
1772
|
+
* reviser: { model },
|
|
1773
|
+
* maxIterations: 3,
|
|
1774
|
+
* checkpointer // Required for askHuman tool
|
|
1775
|
+
* });
|
|
1776
|
+
*
|
|
1777
|
+
* // Invoke with thread_id for conversation continuity
|
|
1778
|
+
* const result = await agent.invoke(
|
|
1779
|
+
* { input: 'Write a report on this topic' },
|
|
1780
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
1781
|
+
* );
|
|
1782
|
+
* ```
|
|
1654
1783
|
*/
|
|
1655
1784
|
declare function createReflectionAgent(config: ReflectionAgentConfig): any;
|
|
1656
1785
|
|
|
@@ -2387,6 +2516,23 @@ interface MultiAgentSystemConfig {
|
|
|
2387
2516
|
* Whether to include verbose logging
|
|
2388
2517
|
*/
|
|
2389
2518
|
verbose?: boolean;
|
|
2519
|
+
/**
|
|
2520
|
+
* Optional checkpointer for state persistence
|
|
2521
|
+
* Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
|
|
2522
|
+
*
|
|
2523
|
+
* @example
|
|
2524
|
+
* ```typescript
|
|
2525
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
2526
|
+
*
|
|
2527
|
+
* const checkpointer = new MemorySaver();
|
|
2528
|
+
* const system = createMultiAgentSystem({
|
|
2529
|
+
* supervisor: { strategy: 'skill-based', model },
|
|
2530
|
+
* workers: [...],
|
|
2531
|
+
* checkpointer
|
|
2532
|
+
* });
|
|
2533
|
+
* ```
|
|
2534
|
+
*/
|
|
2535
|
+
checkpointer?: BaseCheckpointSaver;
|
|
2390
2536
|
}
|
|
2391
2537
|
/**
|
|
2392
2538
|
* Node type for multi-agent graph
|
|
@@ -2494,6 +2640,7 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
|
|
|
2494
2640
|
* @returns Compiled LangGraph workflow
|
|
2495
2641
|
*
|
|
2496
2642
|
* @example
|
|
2643
|
+
* Basic usage:
|
|
2497
2644
|
* ```typescript
|
|
2498
2645
|
* const system = createMultiAgentSystem({
|
|
2499
2646
|
* supervisor: {
|
|
@@ -2531,6 +2678,39 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
|
|
|
2531
2678
|
* input: 'Research AI trends and write a summary',
|
|
2532
2679
|
* });
|
|
2533
2680
|
* ```
|
|
2681
|
+
*
|
|
2682
|
+
* @example
|
|
2683
|
+
* With checkpointer for human-in-the-loop workflows:
|
|
2684
|
+
* ```typescript
|
|
2685
|
+
* import { createMultiAgentSystem } from '@agentforge/patterns';
|
|
2686
|
+
* import { createAskHumanTool } from '@agentforge/tools';
|
|
2687
|
+
* import { MemorySaver } from '@langchain/langgraph';
|
|
2688
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
2689
|
+
*
|
|
2690
|
+
* const checkpointer = new MemorySaver();
|
|
2691
|
+
* const askHuman = createAskHumanTool();
|
|
2692
|
+
* const model = new ChatOpenAI({ model: 'gpt-4' });
|
|
2693
|
+
*
|
|
2694
|
+
* const system = createMultiAgentSystem({
|
|
2695
|
+
* supervisor: { strategy: 'skill-based', model },
|
|
2696
|
+
* workers: [
|
|
2697
|
+
* {
|
|
2698
|
+
* id: 'hr',
|
|
2699
|
+
* capabilities: { skills: ['hr'], tools: ['askHuman'], available: true, currentWorkload: 0 },
|
|
2700
|
+
* tools: [askHuman],
|
|
2701
|
+
* model,
|
|
2702
|
+
* },
|
|
2703
|
+
* ],
|
|
2704
|
+
* aggregator: { model },
|
|
2705
|
+
* checkpointer // Required for askHuman tool
|
|
2706
|
+
* });
|
|
2707
|
+
*
|
|
2708
|
+
* // Invoke with thread_id for conversation continuity
|
|
2709
|
+
* const result = await system.invoke(
|
|
2710
|
+
* { input: 'Help me with HR policy question' },
|
|
2711
|
+
* { configurable: { thread_id: 'conversation-123' } }
|
|
2712
|
+
* );
|
|
2713
|
+
* ```
|
|
2534
2714
|
*/
|
|
2535
2715
|
declare function createMultiAgentSystem(config: MultiAgentSystemConfig): CompiledStateGraph<{
|
|
2536
2716
|
[x: string]: unknown;
|
package/dist/index.js
CHANGED
|
@@ -295,7 +295,8 @@ function createReActAgent(config, options) {
|
|
|
295
295
|
systemPrompt = DEFAULT_REACT_SYSTEM_PROMPT,
|
|
296
296
|
maxIterations = 10,
|
|
297
297
|
returnIntermediateSteps = false,
|
|
298
|
-
stopCondition
|
|
298
|
+
stopCondition,
|
|
299
|
+
checkpointer
|
|
299
300
|
} = config;
|
|
300
301
|
const {
|
|
301
302
|
verbose = false,
|
|
@@ -330,7 +331,7 @@ function createReActAgent(config, options) {
|
|
|
330
331
|
return ACTION_NODE;
|
|
331
332
|
};
|
|
332
333
|
const workflow = new StateGraph(ReActState).addNode(REASONING_NODE, reasoningNode).addNode(ACTION_NODE, actionNode).addNode(OBSERVATION_NODE, observationNode).addEdge("__start__", REASONING_NODE).addConditionalEdges(REASONING_NODE, shouldContinue).addEdge(ACTION_NODE, OBSERVATION_NODE).addEdge(OBSERVATION_NODE, REASONING_NODE);
|
|
333
|
-
return workflow.compile();
|
|
334
|
+
return workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
334
335
|
}
|
|
335
336
|
|
|
336
337
|
// src/react/builder.ts
|
|
@@ -871,7 +872,8 @@ function createPlanExecuteAgent(config) {
|
|
|
871
872
|
executor,
|
|
872
873
|
replanner,
|
|
873
874
|
maxIterations = 5,
|
|
874
|
-
verbose = false
|
|
875
|
+
verbose = false,
|
|
876
|
+
checkpointer
|
|
875
877
|
} = config;
|
|
876
878
|
const plannerNode = createPlannerNode(planner);
|
|
877
879
|
const executorNode = createExecutorNode(executor);
|
|
@@ -931,7 +933,7 @@ function createPlanExecuteAgent(config) {
|
|
|
931
933
|
finish: END2
|
|
932
934
|
}
|
|
933
935
|
);
|
|
934
|
-
return workflow.compile();
|
|
936
|
+
return workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
935
937
|
}
|
|
936
938
|
|
|
937
939
|
// src/reflection/state.ts
|
|
@@ -1408,7 +1410,8 @@ function createReflectionAgent(config) {
|
|
|
1408
1410
|
reviser,
|
|
1409
1411
|
maxIterations = 3,
|
|
1410
1412
|
qualityCriteria,
|
|
1411
|
-
verbose = false
|
|
1413
|
+
verbose = false,
|
|
1414
|
+
checkpointer
|
|
1412
1415
|
} = config;
|
|
1413
1416
|
const generatorNode = createGeneratorNode({ ...generator, verbose });
|
|
1414
1417
|
const reflectorNode = createReflectorNode({ ...reflector, qualityCriteria, verbose });
|
|
@@ -1466,7 +1469,7 @@ function createReflectionAgent(config) {
|
|
|
1466
1469
|
error: END3
|
|
1467
1470
|
}
|
|
1468
1471
|
).addEdge("finisher", END3);
|
|
1469
|
-
return workflow.compile();
|
|
1472
|
+
return workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
1470
1473
|
}
|
|
1471
1474
|
|
|
1472
1475
|
// src/multi-agent/state.ts
|
|
@@ -2323,7 +2326,8 @@ function createMultiAgentSystem(config) {
|
|
|
2323
2326
|
workers,
|
|
2324
2327
|
aggregator,
|
|
2325
2328
|
maxIterations = 10,
|
|
2326
|
-
verbose = false
|
|
2329
|
+
verbose = false,
|
|
2330
|
+
checkpointer
|
|
2327
2331
|
} = config;
|
|
2328
2332
|
const workflow = new StateGraph4(MultiAgentState);
|
|
2329
2333
|
const supervisorNode = createSupervisorNode({
|
|
@@ -2376,7 +2380,7 @@ function createMultiAgentSystem(config) {
|
|
|
2376
2380
|
workflow.addConditionalEdges(workerId, workerRouter, ["supervisor"]);
|
|
2377
2381
|
}
|
|
2378
2382
|
workflow.addConditionalEdges("aggregator", aggregatorRouter, [END4]);
|
|
2379
|
-
const compiled = workflow.compile();
|
|
2383
|
+
const compiled = workflow.compile(checkpointer ? { checkpointer } : void 0);
|
|
2380
2384
|
const originalInvoke = compiled.invoke.bind(compiled);
|
|
2381
2385
|
compiled.invoke = async function(input, config2) {
|
|
2382
2386
|
const mergedInput = {
|