@agentforge/patterns 0.6.3 → 0.7.0
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 +867 -332
- package/dist/index.d.cts +96 -2
- package/dist/index.d.ts +96 -2
- package/dist/index.js +852 -321
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
3
3
|
import { BaseCheckpointSaver, CompiledStateGraph } from '@langchain/langgraph';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
|
-
import
|
|
5
|
+
import * as _agentforge_core from '@agentforge/core';
|
|
6
|
+
import { ToolRegistry, Tool, LogLevel } from '@agentforge/core';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Zod schemas for ReAct pattern state
|
|
@@ -78,16 +79,19 @@ declare const ToolResultSchema: z.ZodObject<{
|
|
|
78
79
|
result: z.ZodAny;
|
|
79
80
|
error: z.ZodOptional<z.ZodString>;
|
|
80
81
|
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
isDuplicate: z.ZodOptional<z.ZodBoolean>;
|
|
81
83
|
}, "strip", z.ZodTypeAny, {
|
|
82
84
|
toolCallId: string;
|
|
83
85
|
timestamp?: number | undefined;
|
|
84
86
|
result?: any;
|
|
85
87
|
error?: string | undefined;
|
|
88
|
+
isDuplicate?: boolean | undefined;
|
|
86
89
|
}, {
|
|
87
90
|
toolCallId: string;
|
|
88
91
|
timestamp?: number | undefined;
|
|
89
92
|
result?: any;
|
|
90
93
|
error?: string | undefined;
|
|
94
|
+
isDuplicate?: boolean | undefined;
|
|
91
95
|
}>;
|
|
92
96
|
type ToolResult = z.infer<typeof ToolResultSchema>;
|
|
93
97
|
/**
|
|
@@ -181,6 +185,11 @@ interface ReActAgentConfig {
|
|
|
181
185
|
* ```
|
|
182
186
|
*/
|
|
183
187
|
checkpointer?: BaseCheckpointSaver;
|
|
188
|
+
/**
|
|
189
|
+
* Enable tool call deduplication to prevent calling the same tool with identical parameters multiple times
|
|
190
|
+
* @default true
|
|
191
|
+
*/
|
|
192
|
+
enableDeduplication?: boolean;
|
|
184
193
|
}
|
|
185
194
|
/**
|
|
186
195
|
* Options for the ReAct agent builder
|
|
@@ -881,6 +890,11 @@ interface ExecutorConfig {
|
|
|
881
890
|
* Timeout for each step execution (ms)
|
|
882
891
|
*/
|
|
883
892
|
stepTimeout?: number;
|
|
893
|
+
/**
|
|
894
|
+
* Enable tool call deduplication to prevent executing the same tool with identical parameters multiple times
|
|
895
|
+
* @default true
|
|
896
|
+
*/
|
|
897
|
+
enableDeduplication?: boolean;
|
|
884
898
|
}
|
|
885
899
|
/**
|
|
886
900
|
* Configuration for the replanner node
|
|
@@ -2899,4 +2913,84 @@ declare function registerWorkers(system: MultiAgentSystemWithRegistry, workers:
|
|
|
2899
2913
|
systemPrompt?: string;
|
|
2900
2914
|
}>): void;
|
|
2901
2915
|
|
|
2902
|
-
|
|
2916
|
+
/**
|
|
2917
|
+
* Generate a cache key for a tool call based on tool name and arguments
|
|
2918
|
+
*
|
|
2919
|
+
* The cache key is generated by:
|
|
2920
|
+
* 1. Sorting the argument object keys alphabetically for consistency
|
|
2921
|
+
* 2. JSON stringifying the sorted arguments
|
|
2922
|
+
* 3. Combining tool name and stringified arguments with a colon separator
|
|
2923
|
+
*
|
|
2924
|
+
* This ensures that tool calls with the same arguments in different order
|
|
2925
|
+
* produce the same cache key.
|
|
2926
|
+
*
|
|
2927
|
+
* @param toolName - Name of the tool
|
|
2928
|
+
* @param args - Tool arguments (will be sorted for consistent hashing)
|
|
2929
|
+
* @returns Cache key string in format "toolName:sortedArgs"
|
|
2930
|
+
*
|
|
2931
|
+
* @example
|
|
2932
|
+
* ```typescript
|
|
2933
|
+
* const key1 = generateToolCallCacheKey('search', { query: 'test', limit: 10 });
|
|
2934
|
+
* const key2 = generateToolCallCacheKey('search', { limit: 10, query: 'test' });
|
|
2935
|
+
* // key1 === key2 (argument order doesn't matter)
|
|
2936
|
+
* ```
|
|
2937
|
+
*/
|
|
2938
|
+
declare function generateToolCallCacheKey(toolName: string, args: any): string;
|
|
2939
|
+
/**
|
|
2940
|
+
* Create a logger for a pattern with consistent configuration
|
|
2941
|
+
*
|
|
2942
|
+
* @param name - Logger name (e.g., 'agentforge:react')
|
|
2943
|
+
* @param defaultLevel - Default log level if LOG_LEVEL env var is not set
|
|
2944
|
+
* @returns Configured logger instance
|
|
2945
|
+
*
|
|
2946
|
+
* @example
|
|
2947
|
+
* ```typescript
|
|
2948
|
+
* const logger = createPatternLogger('agentforge:react');
|
|
2949
|
+
* logger.info('Action node complete', { iteration: 1 });
|
|
2950
|
+
* ```
|
|
2951
|
+
*/
|
|
2952
|
+
declare function createPatternLogger(name: string, defaultLevel?: LogLevel): _agentforge_core.Logger;
|
|
2953
|
+
/**
|
|
2954
|
+
* Deduplication metrics for tracking performance
|
|
2955
|
+
*/
|
|
2956
|
+
interface DeduplicationMetrics {
|
|
2957
|
+
/** Number of tools executed (not from cache) */
|
|
2958
|
+
toolsExecuted: number;
|
|
2959
|
+
/** Number of duplicate calls skipped (from cache) */
|
|
2960
|
+
duplicatesSkipped: number;
|
|
2961
|
+
/** Total number of observations/results */
|
|
2962
|
+
totalObservations: number;
|
|
2963
|
+
/** Percentage of calls that were deduplicated */
|
|
2964
|
+
deduplicationSavings: string;
|
|
2965
|
+
}
|
|
2966
|
+
/**
|
|
2967
|
+
* Calculate deduplication savings percentage
|
|
2968
|
+
*
|
|
2969
|
+
* @param duplicatesSkipped - Number of duplicate calls prevented
|
|
2970
|
+
* @param toolsExecuted - Number of tools actually executed
|
|
2971
|
+
* @returns Percentage string (e.g., "75%") or "0%" if no duplicates
|
|
2972
|
+
*
|
|
2973
|
+
* @example
|
|
2974
|
+
* ```typescript
|
|
2975
|
+
* const savings = calculateDeduplicationSavings(3, 1);
|
|
2976
|
+
* // savings === "75%" (3 out of 4 total calls were duplicates)
|
|
2977
|
+
* ```
|
|
2978
|
+
*/
|
|
2979
|
+
declare function calculateDeduplicationSavings(duplicatesSkipped: number, toolsExecuted: number): string;
|
|
2980
|
+
/**
|
|
2981
|
+
* Build deduplication metrics object
|
|
2982
|
+
*
|
|
2983
|
+
* @param toolsExecuted - Number of tools executed
|
|
2984
|
+
* @param duplicatesSkipped - Number of duplicates skipped
|
|
2985
|
+
* @param totalObservations - Total observations count
|
|
2986
|
+
* @returns Metrics object with calculated savings
|
|
2987
|
+
*
|
|
2988
|
+
* @example
|
|
2989
|
+
* ```typescript
|
|
2990
|
+
* const metrics = buildDeduplicationMetrics(1, 3, 4);
|
|
2991
|
+
* // metrics.deduplicationSavings === "75%"
|
|
2992
|
+
* ```
|
|
2993
|
+
*/
|
|
2994
|
+
declare function buildDeduplicationMetrics(toolsExecuted: number, duplicatesSkipped: number, totalObservations: number): DeduplicationMetrics;
|
|
2995
|
+
|
|
2996
|
+
export { type AgentMessage, AgentMessageSchema, type AgentRole, AgentRoleSchema, type AggregatorConfig, type CompletedStep, CompletedStepSchema, DEFAULT_AGGREGATOR_SYSTEM_PROMPT, DEFAULT_GENERATOR_SYSTEM_PROMPT, DEFAULT_PLANNER_SYSTEM_PROMPT, DEFAULT_REACT_SYSTEM_PROMPT, DEFAULT_REFLECTOR_SYSTEM_PROMPT, DEFAULT_REPLANNER_SYSTEM_PROMPT, DEFAULT_REVISER_SYSTEM_PROMPT, DEFAULT_SUPERVISOR_SYSTEM_PROMPT, type DeduplicationMetrics, type ExecutionStatus, ExecutionStatusSchema, type ExecutorConfig, GENERATION_PROMPT_TEMPLATE, type GeneratorConfig, type HandoffRequest, HandoffRequestSchema, type Message, MessageSchema, type MessageType, MessageTypeSchema, type MultiAgentNode, type MultiAgentRoute, type MultiAgentRouter, MultiAgentState, MultiAgentStateConfig, type MultiAgentStateType, type MultiAgentStatus, MultiAgentStatusSchema, MultiAgentSystemBuilder, type MultiAgentSystemConfig, PLANNING_PROMPT_TEMPLATE, type Plan, type PlanExecuteAgentConfig, type PlanExecuteNode, type PlanExecuteRoute, type PlanExecuteRouter, PlanExecuteState, PlanExecuteStateConfig, type PlanExecuteStateType, PlanSchema, type PlanStep, PlanStepSchema, type PlannerConfig, QUALITY_CRITERIA_TEMPLATE, type QualityCriteria, QualityCriteriaSchema, REFLECTION_ENTRY_TEMPLATE, REFLECTION_HISTORY_TEMPLATE, REFLECTION_PROMPT_TEMPLATE, REPLANNING_PROMPT_TEMPLATE, REVISION_ENTRY_TEMPLATE, REVISION_PROMPT_TEMPLATE, ReActAgentBuilder, type ReActAgentConfig, type ReActAgentOptions, type ReActBuilderOptions, ReActState, type ReActStateType, type Reflection, type ReflectionAgentConfig, type ReflectionConfig, ReflectionConfigSchema, type ReflectionNode, type ReflectionRoute, type ReflectionRouter, ReflectionSchema, ReflectionState, ReflectionStateConfig, type ReflectionStateType, type ReflectionStatus, ReflectionStatusSchema, type ReflectorConfig, type ReplanDecision, ReplanDecisionSchema, type ReplannerConfig, type ReviserConfig, type Revision, RevisionSchema, type RoutingDecision, RoutingDecisionSchema, type RoutingStrategy, type RoutingStrategyImpl, RoutingStrategySchema, type ScratchpadEntry, ScratchpadEntrySchema, type StopConditionFn, type SupervisorConfig, type TaskAssignment, TaskAssignmentSchema, type TaskResult, TaskResultSchema, type Thought, ThoughtSchema, type ToolCall, ToolCallSchema, type ToolResult, ToolResultSchema, type WorkerCapabilities, WorkerCapabilitiesSchema, type WorkerConfig, buildDeduplicationMetrics, calculateDeduplicationSavings, createAggregatorNode, createExecutorNode, createFinisherNode$1 as createFinisherNode, createGeneratorNode, createMultiAgentSystem, createPatternLogger, createPlanExecuteAgent, createPlannerNode, createReActAgent, createReActAgentBuilder, createReflectionAgent, createFinisherNode as createReflectionFinisherNode, createReflectorNode, createReplannerNode, createReviserNode, createSupervisorNode, createWorkerNode, generateToolCallCacheKey, getRoutingStrategy, llmBasedRouting, loadBalancedRouting, registerWorkers, roundRobinRouting, ruleBasedRouting, skillBasedRouting };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
3
3
|
import { BaseCheckpointSaver, CompiledStateGraph } from '@langchain/langgraph';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
|
-
import
|
|
5
|
+
import * as _agentforge_core from '@agentforge/core';
|
|
6
|
+
import { ToolRegistry, Tool, LogLevel } from '@agentforge/core';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Zod schemas for ReAct pattern state
|
|
@@ -78,16 +79,19 @@ declare const ToolResultSchema: z.ZodObject<{
|
|
|
78
79
|
result: z.ZodAny;
|
|
79
80
|
error: z.ZodOptional<z.ZodString>;
|
|
80
81
|
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
isDuplicate: z.ZodOptional<z.ZodBoolean>;
|
|
81
83
|
}, "strip", z.ZodTypeAny, {
|
|
82
84
|
toolCallId: string;
|
|
83
85
|
timestamp?: number | undefined;
|
|
84
86
|
result?: any;
|
|
85
87
|
error?: string | undefined;
|
|
88
|
+
isDuplicate?: boolean | undefined;
|
|
86
89
|
}, {
|
|
87
90
|
toolCallId: string;
|
|
88
91
|
timestamp?: number | undefined;
|
|
89
92
|
result?: any;
|
|
90
93
|
error?: string | undefined;
|
|
94
|
+
isDuplicate?: boolean | undefined;
|
|
91
95
|
}>;
|
|
92
96
|
type ToolResult = z.infer<typeof ToolResultSchema>;
|
|
93
97
|
/**
|
|
@@ -181,6 +185,11 @@ interface ReActAgentConfig {
|
|
|
181
185
|
* ```
|
|
182
186
|
*/
|
|
183
187
|
checkpointer?: BaseCheckpointSaver;
|
|
188
|
+
/**
|
|
189
|
+
* Enable tool call deduplication to prevent calling the same tool with identical parameters multiple times
|
|
190
|
+
* @default true
|
|
191
|
+
*/
|
|
192
|
+
enableDeduplication?: boolean;
|
|
184
193
|
}
|
|
185
194
|
/**
|
|
186
195
|
* Options for the ReAct agent builder
|
|
@@ -881,6 +890,11 @@ interface ExecutorConfig {
|
|
|
881
890
|
* Timeout for each step execution (ms)
|
|
882
891
|
*/
|
|
883
892
|
stepTimeout?: number;
|
|
893
|
+
/**
|
|
894
|
+
* Enable tool call deduplication to prevent executing the same tool with identical parameters multiple times
|
|
895
|
+
* @default true
|
|
896
|
+
*/
|
|
897
|
+
enableDeduplication?: boolean;
|
|
884
898
|
}
|
|
885
899
|
/**
|
|
886
900
|
* Configuration for the replanner node
|
|
@@ -2899,4 +2913,84 @@ declare function registerWorkers(system: MultiAgentSystemWithRegistry, workers:
|
|
|
2899
2913
|
systemPrompt?: string;
|
|
2900
2914
|
}>): void;
|
|
2901
2915
|
|
|
2902
|
-
|
|
2916
|
+
/**
|
|
2917
|
+
* Generate a cache key for a tool call based on tool name and arguments
|
|
2918
|
+
*
|
|
2919
|
+
* The cache key is generated by:
|
|
2920
|
+
* 1. Sorting the argument object keys alphabetically for consistency
|
|
2921
|
+
* 2. JSON stringifying the sorted arguments
|
|
2922
|
+
* 3. Combining tool name and stringified arguments with a colon separator
|
|
2923
|
+
*
|
|
2924
|
+
* This ensures that tool calls with the same arguments in different order
|
|
2925
|
+
* produce the same cache key.
|
|
2926
|
+
*
|
|
2927
|
+
* @param toolName - Name of the tool
|
|
2928
|
+
* @param args - Tool arguments (will be sorted for consistent hashing)
|
|
2929
|
+
* @returns Cache key string in format "toolName:sortedArgs"
|
|
2930
|
+
*
|
|
2931
|
+
* @example
|
|
2932
|
+
* ```typescript
|
|
2933
|
+
* const key1 = generateToolCallCacheKey('search', { query: 'test', limit: 10 });
|
|
2934
|
+
* const key2 = generateToolCallCacheKey('search', { limit: 10, query: 'test' });
|
|
2935
|
+
* // key1 === key2 (argument order doesn't matter)
|
|
2936
|
+
* ```
|
|
2937
|
+
*/
|
|
2938
|
+
declare function generateToolCallCacheKey(toolName: string, args: any): string;
|
|
2939
|
+
/**
|
|
2940
|
+
* Create a logger for a pattern with consistent configuration
|
|
2941
|
+
*
|
|
2942
|
+
* @param name - Logger name (e.g., 'agentforge:react')
|
|
2943
|
+
* @param defaultLevel - Default log level if LOG_LEVEL env var is not set
|
|
2944
|
+
* @returns Configured logger instance
|
|
2945
|
+
*
|
|
2946
|
+
* @example
|
|
2947
|
+
* ```typescript
|
|
2948
|
+
* const logger = createPatternLogger('agentforge:react');
|
|
2949
|
+
* logger.info('Action node complete', { iteration: 1 });
|
|
2950
|
+
* ```
|
|
2951
|
+
*/
|
|
2952
|
+
declare function createPatternLogger(name: string, defaultLevel?: LogLevel): _agentforge_core.Logger;
|
|
2953
|
+
/**
|
|
2954
|
+
* Deduplication metrics for tracking performance
|
|
2955
|
+
*/
|
|
2956
|
+
interface DeduplicationMetrics {
|
|
2957
|
+
/** Number of tools executed (not from cache) */
|
|
2958
|
+
toolsExecuted: number;
|
|
2959
|
+
/** Number of duplicate calls skipped (from cache) */
|
|
2960
|
+
duplicatesSkipped: number;
|
|
2961
|
+
/** Total number of observations/results */
|
|
2962
|
+
totalObservations: number;
|
|
2963
|
+
/** Percentage of calls that were deduplicated */
|
|
2964
|
+
deduplicationSavings: string;
|
|
2965
|
+
}
|
|
2966
|
+
/**
|
|
2967
|
+
* Calculate deduplication savings percentage
|
|
2968
|
+
*
|
|
2969
|
+
* @param duplicatesSkipped - Number of duplicate calls prevented
|
|
2970
|
+
* @param toolsExecuted - Number of tools actually executed
|
|
2971
|
+
* @returns Percentage string (e.g., "75%") or "0%" if no duplicates
|
|
2972
|
+
*
|
|
2973
|
+
* @example
|
|
2974
|
+
* ```typescript
|
|
2975
|
+
* const savings = calculateDeduplicationSavings(3, 1);
|
|
2976
|
+
* // savings === "75%" (3 out of 4 total calls were duplicates)
|
|
2977
|
+
* ```
|
|
2978
|
+
*/
|
|
2979
|
+
declare function calculateDeduplicationSavings(duplicatesSkipped: number, toolsExecuted: number): string;
|
|
2980
|
+
/**
|
|
2981
|
+
* Build deduplication metrics object
|
|
2982
|
+
*
|
|
2983
|
+
* @param toolsExecuted - Number of tools executed
|
|
2984
|
+
* @param duplicatesSkipped - Number of duplicates skipped
|
|
2985
|
+
* @param totalObservations - Total observations count
|
|
2986
|
+
* @returns Metrics object with calculated savings
|
|
2987
|
+
*
|
|
2988
|
+
* @example
|
|
2989
|
+
* ```typescript
|
|
2990
|
+
* const metrics = buildDeduplicationMetrics(1, 3, 4);
|
|
2991
|
+
* // metrics.deduplicationSavings === "75%"
|
|
2992
|
+
* ```
|
|
2993
|
+
*/
|
|
2994
|
+
declare function buildDeduplicationMetrics(toolsExecuted: number, duplicatesSkipped: number, totalObservations: number): DeduplicationMetrics;
|
|
2995
|
+
|
|
2996
|
+
export { type AgentMessage, AgentMessageSchema, type AgentRole, AgentRoleSchema, type AggregatorConfig, type CompletedStep, CompletedStepSchema, DEFAULT_AGGREGATOR_SYSTEM_PROMPT, DEFAULT_GENERATOR_SYSTEM_PROMPT, DEFAULT_PLANNER_SYSTEM_PROMPT, DEFAULT_REACT_SYSTEM_PROMPT, DEFAULT_REFLECTOR_SYSTEM_PROMPT, DEFAULT_REPLANNER_SYSTEM_PROMPT, DEFAULT_REVISER_SYSTEM_PROMPT, DEFAULT_SUPERVISOR_SYSTEM_PROMPT, type DeduplicationMetrics, type ExecutionStatus, ExecutionStatusSchema, type ExecutorConfig, GENERATION_PROMPT_TEMPLATE, type GeneratorConfig, type HandoffRequest, HandoffRequestSchema, type Message, MessageSchema, type MessageType, MessageTypeSchema, type MultiAgentNode, type MultiAgentRoute, type MultiAgentRouter, MultiAgentState, MultiAgentStateConfig, type MultiAgentStateType, type MultiAgentStatus, MultiAgentStatusSchema, MultiAgentSystemBuilder, type MultiAgentSystemConfig, PLANNING_PROMPT_TEMPLATE, type Plan, type PlanExecuteAgentConfig, type PlanExecuteNode, type PlanExecuteRoute, type PlanExecuteRouter, PlanExecuteState, PlanExecuteStateConfig, type PlanExecuteStateType, PlanSchema, type PlanStep, PlanStepSchema, type PlannerConfig, QUALITY_CRITERIA_TEMPLATE, type QualityCriteria, QualityCriteriaSchema, REFLECTION_ENTRY_TEMPLATE, REFLECTION_HISTORY_TEMPLATE, REFLECTION_PROMPT_TEMPLATE, REPLANNING_PROMPT_TEMPLATE, REVISION_ENTRY_TEMPLATE, REVISION_PROMPT_TEMPLATE, ReActAgentBuilder, type ReActAgentConfig, type ReActAgentOptions, type ReActBuilderOptions, ReActState, type ReActStateType, type Reflection, type ReflectionAgentConfig, type ReflectionConfig, ReflectionConfigSchema, type ReflectionNode, type ReflectionRoute, type ReflectionRouter, ReflectionSchema, ReflectionState, ReflectionStateConfig, type ReflectionStateType, type ReflectionStatus, ReflectionStatusSchema, type ReflectorConfig, type ReplanDecision, ReplanDecisionSchema, type ReplannerConfig, type ReviserConfig, type Revision, RevisionSchema, type RoutingDecision, RoutingDecisionSchema, type RoutingStrategy, type RoutingStrategyImpl, RoutingStrategySchema, type ScratchpadEntry, ScratchpadEntrySchema, type StopConditionFn, type SupervisorConfig, type TaskAssignment, TaskAssignmentSchema, type TaskResult, TaskResultSchema, type Thought, ThoughtSchema, type ToolCall, ToolCallSchema, type ToolResult, ToolResultSchema, type WorkerCapabilities, WorkerCapabilitiesSchema, type WorkerConfig, buildDeduplicationMetrics, calculateDeduplicationSavings, createAggregatorNode, createExecutorNode, createFinisherNode$1 as createFinisherNode, createGeneratorNode, createMultiAgentSystem, createPatternLogger, createPlanExecuteAgent, createPlannerNode, createReActAgent, createReActAgentBuilder, createReflectionAgent, createFinisherNode as createReflectionFinisherNode, createReflectorNode, createReplannerNode, createReviserNode, createSupervisorNode, createWorkerNode, generateToolCallCacheKey, getRoutingStrategy, llmBasedRouting, loadBalancedRouting, registerWorkers, roundRobinRouting, ruleBasedRouting, skillBasedRouting };
|