@agentforge/patterns 0.6.2 → 0.6.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.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 { ToolRegistry, Tool } from '@agentforge/core';
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
@@ -1860,40 +1874,70 @@ declare const RoutingStrategySchema: z.ZodEnum<["llm-based", "rule-based", "roun
1860
1874
  type RoutingStrategy = z.infer<typeof RoutingStrategySchema>;
1861
1875
  /**
1862
1876
  * Schema for routing decision
1877
+ *
1878
+ * Supports both single-agent and parallel multi-agent routing:
1879
+ * - Single: Use `targetAgent` field
1880
+ * - Parallel: Use `targetAgents` array field
1881
+ *
1882
+ * If both are provided, `targetAgents` takes precedence.
1883
+ *
1884
+ * Note: Uses .nullable() instead of .optional() for OpenAI structured output compatibility
1863
1885
  */
1864
- declare const RoutingDecisionSchema: z.ZodObject<{
1886
+ declare const RoutingDecisionSchema: z.ZodEffects<z.ZodObject<{
1887
+ /**
1888
+ * Target agent to route to (single agent routing)
1889
+ * @deprecated Use targetAgents for parallel routing support
1890
+ */
1891
+ targetAgent: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1865
1892
  /**
1866
- * Target agent to route to
1893
+ * Target agents to route to (parallel routing)
1894
+ * When multiple agents are specified, they execute in parallel
1867
1895
  */
1868
- targetAgent: z.ZodString;
1896
+ targetAgents: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
1869
1897
  /**
1870
1898
  * Reasoning for the routing decision
1871
1899
  */
1872
- reasoning: z.ZodOptional<z.ZodString>;
1900
+ reasoning: z.ZodDefault<z.ZodString>;
1873
1901
  /**
1874
1902
  * Confidence in the routing decision (0-1)
1875
1903
  */
1876
- confidence: z.ZodOptional<z.ZodNumber>;
1904
+ confidence: z.ZodDefault<z.ZodNumber>;
1877
1905
  /**
1878
1906
  * Strategy used for routing
1879
1907
  */
1880
- strategy: z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>;
1908
+ strategy: z.ZodDefault<z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>>;
1881
1909
  /**
1882
1910
  * Timestamp of the routing decision
1883
1911
  */
1884
- timestamp: z.ZodOptional<z.ZodNumber>;
1912
+ timestamp: z.ZodDefault<z.ZodNumber>;
1885
1913
  }, "strip", z.ZodTypeAny, {
1886
- targetAgent: string;
1914
+ timestamp: number;
1915
+ reasoning: string;
1916
+ confidence: number;
1917
+ targetAgent: string | null;
1918
+ targetAgents: string[] | null;
1887
1919
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
1920
+ }, {
1888
1921
  timestamp?: number | undefined;
1889
1922
  reasoning?: string | undefined;
1890
1923
  confidence?: number | undefined;
1891
- }, {
1892
- targetAgent: string;
1924
+ targetAgent?: string | null | undefined;
1925
+ targetAgents?: string[] | null | undefined;
1926
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
1927
+ }>, {
1928
+ timestamp: number;
1929
+ reasoning: string;
1930
+ confidence: number;
1931
+ targetAgent: string | null;
1932
+ targetAgents: string[] | null;
1893
1933
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
1934
+ }, {
1894
1935
  timestamp?: number | undefined;
1895
1936
  reasoning?: string | undefined;
1896
1937
  confidence?: number | undefined;
1938
+ targetAgent?: string | null | undefined;
1939
+ targetAgents?: string[] | null | undefined;
1940
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
1897
1941
  }>;
1898
1942
  type RoutingDecision = z.infer<typeof RoutingDecisionSchema>;
1899
1943
  /**
@@ -2166,31 +2210,49 @@ declare const MultiAgentStateConfig: {
2166
2210
  * Accumulates all routing decisions
2167
2211
  */
2168
2212
  routingHistory: {
2169
- schema: z.ZodArray<z.ZodObject<{
2170
- targetAgent: z.ZodString;
2171
- reasoning: z.ZodOptional<z.ZodString>;
2172
- confidence: z.ZodOptional<z.ZodNumber>;
2173
- strategy: z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>;
2174
- timestamp: z.ZodOptional<z.ZodNumber>;
2213
+ schema: z.ZodArray<z.ZodEffects<z.ZodObject<{
2214
+ targetAgent: z.ZodDefault<z.ZodNullable<z.ZodString>>;
2215
+ targetAgents: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
2216
+ reasoning: z.ZodDefault<z.ZodString>;
2217
+ confidence: z.ZodDefault<z.ZodNumber>;
2218
+ strategy: z.ZodDefault<z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>>;
2219
+ timestamp: z.ZodDefault<z.ZodNumber>;
2175
2220
  }, "strip", z.ZodTypeAny, {
2176
- targetAgent: string;
2221
+ timestamp: number;
2222
+ reasoning: string;
2223
+ confidence: number;
2224
+ targetAgent: string | null;
2225
+ targetAgents: string[] | null;
2177
2226
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
2227
+ }, {
2178
2228
  timestamp?: number | undefined;
2179
2229
  reasoning?: string | undefined;
2180
2230
  confidence?: number | undefined;
2181
- }, {
2182
- targetAgent: string;
2231
+ targetAgent?: string | null | undefined;
2232
+ targetAgents?: string[] | null | undefined;
2233
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
2234
+ }>, {
2235
+ timestamp: number;
2236
+ reasoning: string;
2237
+ confidence: number;
2238
+ targetAgent: string | null;
2239
+ targetAgents: string[] | null;
2183
2240
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
2241
+ }, {
2184
2242
  timestamp?: number | undefined;
2185
2243
  reasoning?: string | undefined;
2186
2244
  confidence?: number | undefined;
2245
+ targetAgent?: string | null | undefined;
2246
+ targetAgents?: string[] | null | undefined;
2247
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
2187
2248
  }>, "many">;
2188
2249
  reducer: (left: RoutingDecision[], right: RoutingDecision[]) => {
2189
- targetAgent: string;
2250
+ timestamp: number;
2251
+ reasoning: string;
2252
+ confidence: number;
2253
+ targetAgent: string | null;
2254
+ targetAgents: string[] | null;
2190
2255
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
2191
- timestamp?: number | undefined;
2192
- reasoning?: string | undefined;
2193
- confidence?: number | undefined;
2194
2256
  }[];
2195
2257
  default: () => never[];
2196
2258
  description: string;
@@ -2606,7 +2668,7 @@ interface RoutingStrategyImpl {
2606
2668
  /**
2607
2669
  * Default system prompt for LLM-based routing
2608
2670
  */
2609
- declare const DEFAULT_SUPERVISOR_SYSTEM_PROMPT = "You are a supervisor agent responsible for routing tasks to specialized worker agents.\n\nYour job is to:\n1. Analyze the current task and context\n2. Review available worker capabilities\n3. Select the most appropriate worker for the task\n4. Provide clear reasoning for your decision\n\nRespond with a JSON object containing:\n{\n \"targetAgent\": \"worker_id\",\n \"reasoning\": \"explanation of why this worker is best suited\",\n \"confidence\": 0.0-1.0,\n \"strategy\": \"llm-based\"\n}";
2671
+ declare const DEFAULT_SUPERVISOR_SYSTEM_PROMPT = "You are a supervisor agent responsible for routing tasks to specialized worker agents.\n\nYour job is to:\n1. Analyze the current task and context\n2. Review available worker capabilities\n3. Select the most appropriate worker(s) for the task\n4. Provide clear reasoning for your decision\n\n**IMPORTANT: You can route to MULTIPLE workers for parallel execution when:**\n- The task requires information from multiple domains (e.g., code + documentation)\n- Multiple workers have complementary expertise\n- Parallel execution would provide a more comprehensive answer\n\n**Response Format:**\n\nFor SINGLE worker routing:\n{\n \"targetAgent\": \"worker_id\",\n \"reasoning\": \"explanation of why this worker is best suited\",\n \"confidence\": 0.0-1.0,\n \"strategy\": \"llm-based\"\n}\n\nFor PARALLEL multi-worker routing:\n{\n \"targetAgents\": [\"worker_id_1\", \"worker_id_2\", ...],\n \"reasoning\": \"explanation of why these workers should work in parallel\",\n \"confidence\": 0.0-1.0,\n \"strategy\": \"llm-based\"\n}\n\nChoose parallel routing when the task benefits from multiple perspectives or data sources.";
2610
2672
  /**
2611
2673
  * LLM-based routing strategy
2612
2674
  * Uses an LLM to intelligently route tasks based on worker capabilities
@@ -2851,4 +2913,84 @@ declare function registerWorkers(system: MultiAgentSystemWithRegistry, workers:
2851
2913
  systemPrompt?: string;
2852
2914
  }>): void;
2853
2915
 
2854
- 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 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, createAggregatorNode, createExecutorNode, createFinisherNode$1 as createFinisherNode, createGeneratorNode, createMultiAgentSystem, createPlanExecuteAgent, createPlannerNode, createReActAgent, createReActAgentBuilder, createReflectionAgent, createFinisherNode as createReflectionFinisherNode, createReflectorNode, createReplannerNode, createReviserNode, createSupervisorNode, createWorkerNode, getRoutingStrategy, llmBasedRouting, loadBalancedRouting, registerWorkers, roundRobinRouting, ruleBasedRouting, skillBasedRouting };
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 { ToolRegistry, Tool } from '@agentforge/core';
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
@@ -1860,40 +1874,70 @@ declare const RoutingStrategySchema: z.ZodEnum<["llm-based", "rule-based", "roun
1860
1874
  type RoutingStrategy = z.infer<typeof RoutingStrategySchema>;
1861
1875
  /**
1862
1876
  * Schema for routing decision
1877
+ *
1878
+ * Supports both single-agent and parallel multi-agent routing:
1879
+ * - Single: Use `targetAgent` field
1880
+ * - Parallel: Use `targetAgents` array field
1881
+ *
1882
+ * If both are provided, `targetAgents` takes precedence.
1883
+ *
1884
+ * Note: Uses .nullable() instead of .optional() for OpenAI structured output compatibility
1863
1885
  */
1864
- declare const RoutingDecisionSchema: z.ZodObject<{
1886
+ declare const RoutingDecisionSchema: z.ZodEffects<z.ZodObject<{
1887
+ /**
1888
+ * Target agent to route to (single agent routing)
1889
+ * @deprecated Use targetAgents for parallel routing support
1890
+ */
1891
+ targetAgent: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1865
1892
  /**
1866
- * Target agent to route to
1893
+ * Target agents to route to (parallel routing)
1894
+ * When multiple agents are specified, they execute in parallel
1867
1895
  */
1868
- targetAgent: z.ZodString;
1896
+ targetAgents: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
1869
1897
  /**
1870
1898
  * Reasoning for the routing decision
1871
1899
  */
1872
- reasoning: z.ZodOptional<z.ZodString>;
1900
+ reasoning: z.ZodDefault<z.ZodString>;
1873
1901
  /**
1874
1902
  * Confidence in the routing decision (0-1)
1875
1903
  */
1876
- confidence: z.ZodOptional<z.ZodNumber>;
1904
+ confidence: z.ZodDefault<z.ZodNumber>;
1877
1905
  /**
1878
1906
  * Strategy used for routing
1879
1907
  */
1880
- strategy: z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>;
1908
+ strategy: z.ZodDefault<z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>>;
1881
1909
  /**
1882
1910
  * Timestamp of the routing decision
1883
1911
  */
1884
- timestamp: z.ZodOptional<z.ZodNumber>;
1912
+ timestamp: z.ZodDefault<z.ZodNumber>;
1885
1913
  }, "strip", z.ZodTypeAny, {
1886
- targetAgent: string;
1914
+ timestamp: number;
1915
+ reasoning: string;
1916
+ confidence: number;
1917
+ targetAgent: string | null;
1918
+ targetAgents: string[] | null;
1887
1919
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
1920
+ }, {
1888
1921
  timestamp?: number | undefined;
1889
1922
  reasoning?: string | undefined;
1890
1923
  confidence?: number | undefined;
1891
- }, {
1892
- targetAgent: string;
1924
+ targetAgent?: string | null | undefined;
1925
+ targetAgents?: string[] | null | undefined;
1926
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
1927
+ }>, {
1928
+ timestamp: number;
1929
+ reasoning: string;
1930
+ confidence: number;
1931
+ targetAgent: string | null;
1932
+ targetAgents: string[] | null;
1893
1933
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
1934
+ }, {
1894
1935
  timestamp?: number | undefined;
1895
1936
  reasoning?: string | undefined;
1896
1937
  confidence?: number | undefined;
1938
+ targetAgent?: string | null | undefined;
1939
+ targetAgents?: string[] | null | undefined;
1940
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
1897
1941
  }>;
1898
1942
  type RoutingDecision = z.infer<typeof RoutingDecisionSchema>;
1899
1943
  /**
@@ -2166,31 +2210,49 @@ declare const MultiAgentStateConfig: {
2166
2210
  * Accumulates all routing decisions
2167
2211
  */
2168
2212
  routingHistory: {
2169
- schema: z.ZodArray<z.ZodObject<{
2170
- targetAgent: z.ZodString;
2171
- reasoning: z.ZodOptional<z.ZodString>;
2172
- confidence: z.ZodOptional<z.ZodNumber>;
2173
- strategy: z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>;
2174
- timestamp: z.ZodOptional<z.ZodNumber>;
2213
+ schema: z.ZodArray<z.ZodEffects<z.ZodObject<{
2214
+ targetAgent: z.ZodDefault<z.ZodNullable<z.ZodString>>;
2215
+ targetAgents: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
2216
+ reasoning: z.ZodDefault<z.ZodString>;
2217
+ confidence: z.ZodDefault<z.ZodNumber>;
2218
+ strategy: z.ZodDefault<z.ZodEnum<["llm-based", "rule-based", "round-robin", "skill-based", "load-balanced"]>>;
2219
+ timestamp: z.ZodDefault<z.ZodNumber>;
2175
2220
  }, "strip", z.ZodTypeAny, {
2176
- targetAgent: string;
2221
+ timestamp: number;
2222
+ reasoning: string;
2223
+ confidence: number;
2224
+ targetAgent: string | null;
2225
+ targetAgents: string[] | null;
2177
2226
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
2227
+ }, {
2178
2228
  timestamp?: number | undefined;
2179
2229
  reasoning?: string | undefined;
2180
2230
  confidence?: number | undefined;
2181
- }, {
2182
- targetAgent: string;
2231
+ targetAgent?: string | null | undefined;
2232
+ targetAgents?: string[] | null | undefined;
2233
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
2234
+ }>, {
2235
+ timestamp: number;
2236
+ reasoning: string;
2237
+ confidence: number;
2238
+ targetAgent: string | null;
2239
+ targetAgents: string[] | null;
2183
2240
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
2241
+ }, {
2184
2242
  timestamp?: number | undefined;
2185
2243
  reasoning?: string | undefined;
2186
2244
  confidence?: number | undefined;
2245
+ targetAgent?: string | null | undefined;
2246
+ targetAgents?: string[] | null | undefined;
2247
+ strategy?: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced" | undefined;
2187
2248
  }>, "many">;
2188
2249
  reducer: (left: RoutingDecision[], right: RoutingDecision[]) => {
2189
- targetAgent: string;
2250
+ timestamp: number;
2251
+ reasoning: string;
2252
+ confidence: number;
2253
+ targetAgent: string | null;
2254
+ targetAgents: string[] | null;
2190
2255
  strategy: "llm-based" | "rule-based" | "round-robin" | "skill-based" | "load-balanced";
2191
- timestamp?: number | undefined;
2192
- reasoning?: string | undefined;
2193
- confidence?: number | undefined;
2194
2256
  }[];
2195
2257
  default: () => never[];
2196
2258
  description: string;
@@ -2606,7 +2668,7 @@ interface RoutingStrategyImpl {
2606
2668
  /**
2607
2669
  * Default system prompt for LLM-based routing
2608
2670
  */
2609
- declare const DEFAULT_SUPERVISOR_SYSTEM_PROMPT = "You are a supervisor agent responsible for routing tasks to specialized worker agents.\n\nYour job is to:\n1. Analyze the current task and context\n2. Review available worker capabilities\n3. Select the most appropriate worker for the task\n4. Provide clear reasoning for your decision\n\nRespond with a JSON object containing:\n{\n \"targetAgent\": \"worker_id\",\n \"reasoning\": \"explanation of why this worker is best suited\",\n \"confidence\": 0.0-1.0,\n \"strategy\": \"llm-based\"\n}";
2671
+ declare const DEFAULT_SUPERVISOR_SYSTEM_PROMPT = "You are a supervisor agent responsible for routing tasks to specialized worker agents.\n\nYour job is to:\n1. Analyze the current task and context\n2. Review available worker capabilities\n3. Select the most appropriate worker(s) for the task\n4. Provide clear reasoning for your decision\n\n**IMPORTANT: You can route to MULTIPLE workers for parallel execution when:**\n- The task requires information from multiple domains (e.g., code + documentation)\n- Multiple workers have complementary expertise\n- Parallel execution would provide a more comprehensive answer\n\n**Response Format:**\n\nFor SINGLE worker routing:\n{\n \"targetAgent\": \"worker_id\",\n \"reasoning\": \"explanation of why this worker is best suited\",\n \"confidence\": 0.0-1.0,\n \"strategy\": \"llm-based\"\n}\n\nFor PARALLEL multi-worker routing:\n{\n \"targetAgents\": [\"worker_id_1\", \"worker_id_2\", ...],\n \"reasoning\": \"explanation of why these workers should work in parallel\",\n \"confidence\": 0.0-1.0,\n \"strategy\": \"llm-based\"\n}\n\nChoose parallel routing when the task benefits from multiple perspectives or data sources.";
2610
2672
  /**
2611
2673
  * LLM-based routing strategy
2612
2674
  * Uses an LLM to intelligently route tasks based on worker capabilities
@@ -2851,4 +2913,84 @@ declare function registerWorkers(system: MultiAgentSystemWithRegistry, workers:
2851
2913
  systemPrompt?: string;
2852
2914
  }>): void;
2853
2915
 
2854
- 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 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, createAggregatorNode, createExecutorNode, createFinisherNode$1 as createFinisherNode, createGeneratorNode, createMultiAgentSystem, createPlanExecuteAgent, createPlannerNode, createReActAgent, createReActAgentBuilder, createReflectionAgent, createFinisherNode as createReflectionFinisherNode, createReflectorNode, createReplannerNode, createReviserNode, createSupervisorNode, createWorkerNode, getRoutingStrategy, llmBasedRouting, loadBalancedRouting, registerWorkers, roundRobinRouting, ruleBasedRouting, skillBasedRouting };
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 };