@agentforge/patterns 0.7.0 → 0.8.1

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.d.cts CHANGED
@@ -172,7 +172,12 @@ interface ReActAgentConfig {
172
172
  * Optional checkpointer for state persistence
173
173
  * Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
174
174
  *
175
+ * Can be:
176
+ * - A BaseCheckpointSaver instance (e.g., MemorySaver) for standalone agents
177
+ * - `true` to use the parent graph's checkpointer with a separate namespace (for nested graphs)
178
+ *
175
179
  * @example
180
+ * Standalone agent with its own checkpointer:
176
181
  * ```typescript
177
182
  * import { MemorySaver } from '@langchain/langgraph';
178
183
  *
@@ -183,8 +188,18 @@ interface ReActAgentConfig {
183
188
  * checkpointer
184
189
  * });
185
190
  * ```
191
+ *
192
+ * @example
193
+ * Nested agent using parent's checkpointer (for multi-agent systems):
194
+ * ```typescript
195
+ * const agent = createReActAgent({
196
+ * model,
197
+ * tools,
198
+ * checkpointer: true // Use parent's checkpointer with separate namespace
199
+ * });
200
+ * ```
186
201
  */
187
- checkpointer?: BaseCheckpointSaver;
202
+ checkpointer?: BaseCheckpointSaver | true;
188
203
  /**
189
204
  * Enable tool call deduplication to prevent calling the same tool with identical parameters multiple times
190
205
  * @default true
@@ -287,6 +302,31 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
287
302
  * { configurable: { thread_id: 'conversation-123' } }
288
303
  * );
289
304
  * ```
305
+ *
306
+ * @example
307
+ * As a nested agent in a multi-agent system:
308
+ * ```typescript
309
+ * import { createReActAgent, createMultiAgentSystem } from '@agentforge/patterns';
310
+ * import { createAskHumanTool } from '@agentforge/tools';
311
+ * import { MemorySaver } from '@langchain/langgraph';
312
+ * import { ChatOpenAI } from '@langchain/openai';
313
+ *
314
+ * // Create worker agent with checkpointer: true to use parent's checkpointer
315
+ * const hrAgent = createReActAgent({
316
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
317
+ * tools: [createAskHumanTool(), ...hrTools],
318
+ * checkpointer: true // Use parent's checkpointer with separate namespace
319
+ * });
320
+ *
321
+ * // Create multi-agent system with its own checkpointer
322
+ * const system = createMultiAgentSystem({
323
+ * workers: { hr: hrAgent },
324
+ * checkpointer: new MemorySaver() // Parent checkpointer
325
+ * });
326
+ *
327
+ * // When hrAgent calls askHuman, it will use a separate checkpoint namespace
328
+ * // Format: {parent_thread_id}:worker:hr
329
+ * ```
290
330
  */
291
331
  declare function createReActAgent(config: ReActAgentConfig, options?: ReActBuilderOptions): CompiledStateGraph<any, any>;
292
332
 
@@ -372,6 +412,40 @@ declare class ReActAgentBuilder {
372
412
  action?: string;
373
413
  observation?: string;
374
414
  }): this;
415
+ /**
416
+ * Set the checkpointer for state persistence (optional)
417
+ *
418
+ * Can be:
419
+ * - A BaseCheckpointSaver instance (e.g., MemorySaver) for standalone agents
420
+ * - `true` to use the parent graph's checkpointer with a separate namespace (for nested graphs)
421
+ *
422
+ * Required for human-in-the-loop workflows (askHuman tool) and conversation continuity.
423
+ *
424
+ * @param checkpointer - Checkpointer instance or `true` for nested graphs
425
+ *
426
+ * @example
427
+ * Standalone agent with its own checkpointer:
428
+ * ```typescript
429
+ * import { MemorySaver } from '@langchain/langgraph';
430
+ *
431
+ * const agent = new ReActAgentBuilder()
432
+ * .withModel(model)
433
+ * .withTools(tools)
434
+ * .withCheckpointer(new MemorySaver())
435
+ * .build();
436
+ * ```
437
+ *
438
+ * @example
439
+ * Nested agent using parent's checkpointer (for multi-agent systems):
440
+ * ```typescript
441
+ * const agent = new ReActAgentBuilder()
442
+ * .withModel(model)
443
+ * .withTools(tools)
444
+ * .withCheckpointer(true) // Use parent's checkpointer with separate namespace
445
+ * .build();
446
+ * ```
447
+ */
448
+ withCheckpointer(checkpointer: any): this;
375
449
  /**
376
450
  * Build the ReAct agent
377
451
  *
@@ -2473,29 +2547,6 @@ interface SupervisorConfig {
2473
2547
  * Maximum number of routing iterations
2474
2548
  */
2475
2549
  maxIterations?: number;
2476
- /**
2477
- * Optional tools the supervisor can use during routing
2478
- *
2479
- * Enables the supervisor to gather additional information before making routing decisions.
2480
- * Common use case: askHuman tool for clarifying ambiguous queries.
2481
- *
2482
- * Note: Only works with LLM-based routing strategy.
2483
- *
2484
- * @example
2485
- * ```typescript
2486
- * import { createAskHumanTool } from '@agentforge/tools';
2487
- *
2488
- * const system = createMultiAgentSystem({
2489
- * supervisor: {
2490
- * strategy: 'llm-based',
2491
- * model: chatModel,
2492
- * tools: [createAskHumanTool()],
2493
- * },
2494
- * // ...
2495
- * });
2496
- * ```
2497
- */
2498
- tools?: Tool<any, any>[];
2499
2550
  /**
2500
2551
  * Maximum number of tool call retries before requiring routing decision
2501
2552
  *
@@ -2616,7 +2667,20 @@ interface MultiAgentSystemConfig {
2616
2667
  * Optional checkpointer for state persistence
2617
2668
  * Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
2618
2669
  *
2670
+ * **Worker Checkpoint Namespaces:**
2671
+ * When worker agents are configured with `checkpointer: true`, they automatically use
2672
+ * separate checkpoint namespaces to enable proper handling of nested graph interrupts.
2673
+ *
2674
+ * The namespace format is: `{parent_thread_id}:worker:{workerId}`
2675
+ *
2676
+ * For example, if the parent thread ID is `thread_abc123` and the worker ID is `hr`,
2677
+ * the worker's checkpoint namespace will be `thread_abc123:worker:hr`.
2678
+ *
2679
+ * This allows worker agents to use the `askHuman` tool without causing infinite loops,
2680
+ * as each worker's state is saved and resumed independently.
2681
+ *
2619
2682
  * @example
2683
+ * Basic usage with checkpointer:
2620
2684
  * ```typescript
2621
2685
  * import { MemorySaver } from '@langchain/langgraph';
2622
2686
  *
@@ -2627,6 +2691,35 @@ interface MultiAgentSystemConfig {
2627
2691
  * checkpointer
2628
2692
  * });
2629
2693
  * ```
2694
+ *
2695
+ * @example
2696
+ * Worker agents with nested graph interrupts:
2697
+ * ```typescript
2698
+ * import { MemorySaver } from '@langchain/langgraph';
2699
+ * import { createReActAgent } from '@agentforge/patterns';
2700
+ * import { createAskHumanTool } from '@agentforge/tools';
2701
+ *
2702
+ * // Create worker agent with checkpointer: true
2703
+ * const hrAgent = createReActAgent({
2704
+ * model,
2705
+ * tools: [createAskHumanTool(), ...hrTools],
2706
+ * checkpointer: true // Use parent's checkpointer with separate namespace
2707
+ * });
2708
+ *
2709
+ * // Create multi-agent system with checkpointer
2710
+ * const system = createMultiAgentSystem({
2711
+ * supervisor: { strategy: 'skill-based', model },
2712
+ * workers: [{
2713
+ * id: 'hr',
2714
+ * capabilities: { skills: ['hr'], ... },
2715
+ * agent: hrAgent
2716
+ * }],
2717
+ * checkpointer: new MemorySaver()
2718
+ * });
2719
+ *
2720
+ * // When hrAgent calls askHuman, it will use checkpoint namespace:
2721
+ * // thread_abc123:worker:hr
2722
+ * ```
2630
2723
  */
2631
2724
  checkpointer?: BaseCheckpointSaver;
2632
2725
  }
@@ -2672,8 +2765,6 @@ declare const DEFAULT_SUPERVISOR_SYSTEM_PROMPT = "You are a supervisor agent res
2672
2765
  /**
2673
2766
  * LLM-based routing strategy
2674
2767
  * Uses an LLM to intelligently route tasks based on worker capabilities
2675
- *
2676
- * Supports tool calls (e.g., askHuman) for gathering additional information before routing.
2677
2768
  */
2678
2769
  declare const llmBasedRouting: RoutingStrategyImpl;
2679
2770
  /**
package/dist/index.d.ts CHANGED
@@ -172,7 +172,12 @@ interface ReActAgentConfig {
172
172
  * Optional checkpointer for state persistence
173
173
  * Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
174
174
  *
175
+ * Can be:
176
+ * - A BaseCheckpointSaver instance (e.g., MemorySaver) for standalone agents
177
+ * - `true` to use the parent graph's checkpointer with a separate namespace (for nested graphs)
178
+ *
175
179
  * @example
180
+ * Standalone agent with its own checkpointer:
176
181
  * ```typescript
177
182
  * import { MemorySaver } from '@langchain/langgraph';
178
183
  *
@@ -183,8 +188,18 @@ interface ReActAgentConfig {
183
188
  * checkpointer
184
189
  * });
185
190
  * ```
191
+ *
192
+ * @example
193
+ * Nested agent using parent's checkpointer (for multi-agent systems):
194
+ * ```typescript
195
+ * const agent = createReActAgent({
196
+ * model,
197
+ * tools,
198
+ * checkpointer: true // Use parent's checkpointer with separate namespace
199
+ * });
200
+ * ```
186
201
  */
187
- checkpointer?: BaseCheckpointSaver;
202
+ checkpointer?: BaseCheckpointSaver | true;
188
203
  /**
189
204
  * Enable tool call deduplication to prevent calling the same tool with identical parameters multiple times
190
205
  * @default true
@@ -287,6 +302,31 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
287
302
  * { configurable: { thread_id: 'conversation-123' } }
288
303
  * );
289
304
  * ```
305
+ *
306
+ * @example
307
+ * As a nested agent in a multi-agent system:
308
+ * ```typescript
309
+ * import { createReActAgent, createMultiAgentSystem } from '@agentforge/patterns';
310
+ * import { createAskHumanTool } from '@agentforge/tools';
311
+ * import { MemorySaver } from '@langchain/langgraph';
312
+ * import { ChatOpenAI } from '@langchain/openai';
313
+ *
314
+ * // Create worker agent with checkpointer: true to use parent's checkpointer
315
+ * const hrAgent = createReActAgent({
316
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
317
+ * tools: [createAskHumanTool(), ...hrTools],
318
+ * checkpointer: true // Use parent's checkpointer with separate namespace
319
+ * });
320
+ *
321
+ * // Create multi-agent system with its own checkpointer
322
+ * const system = createMultiAgentSystem({
323
+ * workers: { hr: hrAgent },
324
+ * checkpointer: new MemorySaver() // Parent checkpointer
325
+ * });
326
+ *
327
+ * // When hrAgent calls askHuman, it will use a separate checkpoint namespace
328
+ * // Format: {parent_thread_id}:worker:hr
329
+ * ```
290
330
  */
291
331
  declare function createReActAgent(config: ReActAgentConfig, options?: ReActBuilderOptions): CompiledStateGraph<any, any>;
292
332
 
@@ -372,6 +412,40 @@ declare class ReActAgentBuilder {
372
412
  action?: string;
373
413
  observation?: string;
374
414
  }): this;
415
+ /**
416
+ * Set the checkpointer for state persistence (optional)
417
+ *
418
+ * Can be:
419
+ * - A BaseCheckpointSaver instance (e.g., MemorySaver) for standalone agents
420
+ * - `true` to use the parent graph's checkpointer with a separate namespace (for nested graphs)
421
+ *
422
+ * Required for human-in-the-loop workflows (askHuman tool) and conversation continuity.
423
+ *
424
+ * @param checkpointer - Checkpointer instance or `true` for nested graphs
425
+ *
426
+ * @example
427
+ * Standalone agent with its own checkpointer:
428
+ * ```typescript
429
+ * import { MemorySaver } from '@langchain/langgraph';
430
+ *
431
+ * const agent = new ReActAgentBuilder()
432
+ * .withModel(model)
433
+ * .withTools(tools)
434
+ * .withCheckpointer(new MemorySaver())
435
+ * .build();
436
+ * ```
437
+ *
438
+ * @example
439
+ * Nested agent using parent's checkpointer (for multi-agent systems):
440
+ * ```typescript
441
+ * const agent = new ReActAgentBuilder()
442
+ * .withModel(model)
443
+ * .withTools(tools)
444
+ * .withCheckpointer(true) // Use parent's checkpointer with separate namespace
445
+ * .build();
446
+ * ```
447
+ */
448
+ withCheckpointer(checkpointer: any): this;
375
449
  /**
376
450
  * Build the ReAct agent
377
451
  *
@@ -2473,29 +2547,6 @@ interface SupervisorConfig {
2473
2547
  * Maximum number of routing iterations
2474
2548
  */
2475
2549
  maxIterations?: number;
2476
- /**
2477
- * Optional tools the supervisor can use during routing
2478
- *
2479
- * Enables the supervisor to gather additional information before making routing decisions.
2480
- * Common use case: askHuman tool for clarifying ambiguous queries.
2481
- *
2482
- * Note: Only works with LLM-based routing strategy.
2483
- *
2484
- * @example
2485
- * ```typescript
2486
- * import { createAskHumanTool } from '@agentforge/tools';
2487
- *
2488
- * const system = createMultiAgentSystem({
2489
- * supervisor: {
2490
- * strategy: 'llm-based',
2491
- * model: chatModel,
2492
- * tools: [createAskHumanTool()],
2493
- * },
2494
- * // ...
2495
- * });
2496
- * ```
2497
- */
2498
- tools?: Tool<any, any>[];
2499
2550
  /**
2500
2551
  * Maximum number of tool call retries before requiring routing decision
2501
2552
  *
@@ -2616,7 +2667,20 @@ interface MultiAgentSystemConfig {
2616
2667
  * Optional checkpointer for state persistence
2617
2668
  * Required for human-in-the-loop workflows (askHuman tool), interrupts, and conversation continuity
2618
2669
  *
2670
+ * **Worker Checkpoint Namespaces:**
2671
+ * When worker agents are configured with `checkpointer: true`, they automatically use
2672
+ * separate checkpoint namespaces to enable proper handling of nested graph interrupts.
2673
+ *
2674
+ * The namespace format is: `{parent_thread_id}:worker:{workerId}`
2675
+ *
2676
+ * For example, if the parent thread ID is `thread_abc123` and the worker ID is `hr`,
2677
+ * the worker's checkpoint namespace will be `thread_abc123:worker:hr`.
2678
+ *
2679
+ * This allows worker agents to use the `askHuman` tool without causing infinite loops,
2680
+ * as each worker's state is saved and resumed independently.
2681
+ *
2619
2682
  * @example
2683
+ * Basic usage with checkpointer:
2620
2684
  * ```typescript
2621
2685
  * import { MemorySaver } from '@langchain/langgraph';
2622
2686
  *
@@ -2627,6 +2691,35 @@ interface MultiAgentSystemConfig {
2627
2691
  * checkpointer
2628
2692
  * });
2629
2693
  * ```
2694
+ *
2695
+ * @example
2696
+ * Worker agents with nested graph interrupts:
2697
+ * ```typescript
2698
+ * import { MemorySaver } from '@langchain/langgraph';
2699
+ * import { createReActAgent } from '@agentforge/patterns';
2700
+ * import { createAskHumanTool } from '@agentforge/tools';
2701
+ *
2702
+ * // Create worker agent with checkpointer: true
2703
+ * const hrAgent = createReActAgent({
2704
+ * model,
2705
+ * tools: [createAskHumanTool(), ...hrTools],
2706
+ * checkpointer: true // Use parent's checkpointer with separate namespace
2707
+ * });
2708
+ *
2709
+ * // Create multi-agent system with checkpointer
2710
+ * const system = createMultiAgentSystem({
2711
+ * supervisor: { strategy: 'skill-based', model },
2712
+ * workers: [{
2713
+ * id: 'hr',
2714
+ * capabilities: { skills: ['hr'], ... },
2715
+ * agent: hrAgent
2716
+ * }],
2717
+ * checkpointer: new MemorySaver()
2718
+ * });
2719
+ *
2720
+ * // When hrAgent calls askHuman, it will use checkpoint namespace:
2721
+ * // thread_abc123:worker:hr
2722
+ * ```
2630
2723
  */
2631
2724
  checkpointer?: BaseCheckpointSaver;
2632
2725
  }
@@ -2672,8 +2765,6 @@ declare const DEFAULT_SUPERVISOR_SYSTEM_PROMPT = "You are a supervisor agent res
2672
2765
  /**
2673
2766
  * LLM-based routing strategy
2674
2767
  * Uses an LLM to intelligently route tasks based on worker capabilities
2675
- *
2676
- * Supports tool calls (e.g., askHuman) for gathering additional information before routing.
2677
2768
  */
2678
2769
  declare const llmBasedRouting: RoutingStrategyImpl;
2679
2770
  /**