@agentforge/patterns 0.3.3 → 0.3.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 CHANGED
@@ -389,7 +389,7 @@ var import_langgraph = require("@langchain/langgraph");
389
389
  var import_core3 = require("@agentforge/core");
390
390
  function createReActAgent(config, options) {
391
391
  const {
392
- llm,
392
+ model,
393
393
  tools,
394
394
  systemPrompt = DEFAULT_REACT_SYSTEM_PROMPT,
395
395
  maxIterations = 10,
@@ -405,7 +405,7 @@ function createReActAgent(config, options) {
405
405
  const ACTION_NODE = nodeNames.action || "action";
406
406
  const OBSERVATION_NODE = nodeNames.observation || "observation";
407
407
  const reasoningNode = createReasoningNode(
408
- llm,
408
+ model,
409
409
  toolArray,
410
410
  systemPrompt,
411
411
  maxIterations,
@@ -439,12 +439,18 @@ var ReActAgentBuilder = class {
439
439
  /**
440
440
  * Set the language model (required)
441
441
  *
442
- * @param llm - LangChain chat model to use for reasoning
442
+ * @param model - LangChain chat model to use for reasoning
443
443
  */
444
- withLLM(llm) {
445
- this.config.llm = llm;
444
+ withModel(model) {
445
+ this.config.model = model;
446
446
  return this;
447
447
  }
448
+ /**
449
+ * @deprecated Use withModel() instead
450
+ */
451
+ withLLM(llm) {
452
+ return this.withModel(llm);
453
+ }
448
454
  /**
449
455
  * Set the tools (required)
450
456
  *
@@ -515,14 +521,14 @@ var ReActAgentBuilder = class {
515
521
  * @throws Error if required configuration is missing
516
522
  */
517
523
  build() {
518
- if (!this.config.llm) {
519
- throw new Error("ReActAgentBuilder: llm is required. Use withLLM() to set it.");
524
+ if (!this.config.model) {
525
+ throw new Error("ReActAgentBuilder: model is required. Use withModel() to set it.");
520
526
  }
521
527
  if (!this.config.tools) {
522
528
  throw new Error("ReActAgentBuilder: tools are required. Use withTools() to set them.");
523
529
  }
524
530
  const finalConfig = {
525
- llm: this.config.llm,
531
+ model: this.config.model,
526
532
  tools: this.config.tools,
527
533
  systemPrompt: this.config.systemPrompt || DEFAULT_REACT_SYSTEM_PROMPT,
528
534
  maxIterations: this.config.maxIterations ?? 10,
@@ -770,7 +776,7 @@ var REMAINING_STEP_TEMPLATE = `Step {stepNumber}: {description}
770
776
  // src/plan-execute/nodes.ts
771
777
  function createPlannerNode(config) {
772
778
  const {
773
- llm,
779
+ model,
774
780
  systemPrompt = DEFAULT_PLANNER_SYSTEM_PROMPT,
775
781
  maxSteps = 7,
776
782
  includeToolDescriptions = false
@@ -786,7 +792,7 @@ function createPlannerNode(config) {
786
792
  new import_messages2.SystemMessage(systemPrompt),
787
793
  new import_messages2.HumanMessage(userPrompt)
788
794
  ];
789
- const response = await llm.invoke(messages);
795
+ const response = await model.invoke(messages);
790
796
  const content = response.content.toString();
791
797
  let plan;
792
798
  try {
@@ -818,7 +824,7 @@ function createPlannerNode(config) {
818
824
  function createExecutorNode(config) {
819
825
  const {
820
826
  tools,
821
- llm,
827
+ model,
822
828
  parallel = false,
823
829
  stepTimeout = 3e4
824
830
  } = config;
@@ -888,7 +894,7 @@ function createExecutorNode(config) {
888
894
  }
889
895
  function createReplannerNode(config) {
890
896
  const {
891
- llm,
897
+ model,
892
898
  replanThreshold = 0.7,
893
899
  systemPrompt = DEFAULT_REPLANNER_SYSTEM_PROMPT
894
900
  } = config;
@@ -910,7 +916,7 @@ function createReplannerNode(config) {
910
916
  new import_messages2.SystemMessage(systemPrompt),
911
917
  new import_messages2.HumanMessage(userPrompt)
912
918
  ];
913
- const response = await llm.invoke(messages);
919
+ const response = await model.invoke(messages);
914
920
  const content = response.content.toString();
915
921
  let decision;
916
922
  try {
@@ -1308,7 +1314,7 @@ var REVISION_ENTRY_TEMPLATE = `Iteration {iteration}:
1308
1314
  var import_messages3 = require("@langchain/core/messages");
1309
1315
  function createGeneratorNode(config) {
1310
1316
  const {
1311
- llm,
1317
+ model,
1312
1318
  systemPrompt = DEFAULT_GENERATOR_SYSTEM_PROMPT,
1313
1319
  verbose = false
1314
1320
  } = config;
@@ -1329,7 +1335,7 @@ ${lastReflection.critique}`;
1329
1335
  new import_messages3.SystemMessage(systemPrompt),
1330
1336
  new import_messages3.HumanMessage(userPrompt)
1331
1337
  ];
1332
- const response = await llm.invoke(messages);
1338
+ const response = await model.invoke(messages);
1333
1339
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1334
1340
  if (verbose) {
1335
1341
  console.log("[Generator] Generated response:", content.substring(0, 100) + "...");
@@ -1350,7 +1356,7 @@ ${lastReflection.critique}`;
1350
1356
  }
1351
1357
  function createReflectorNode(config) {
1352
1358
  const {
1353
- llm,
1359
+ model,
1354
1360
  systemPrompt = DEFAULT_REFLECTOR_SYSTEM_PROMPT,
1355
1361
  qualityCriteria,
1356
1362
  verbose = false
@@ -1384,7 +1390,7 @@ function createReflectorNode(config) {
1384
1390
  new import_messages3.SystemMessage(systemPrompt),
1385
1391
  new import_messages3.HumanMessage(userPrompt)
1386
1392
  ];
1387
- const response = await llm.invoke(messages);
1393
+ const response = await model.invoke(messages);
1388
1394
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1389
1395
  let reflection;
1390
1396
  try {
@@ -1428,7 +1434,7 @@ function createReflectorNode(config) {
1428
1434
  }
1429
1435
  function createReviserNode(config) {
1430
1436
  const {
1431
- llm,
1437
+ model,
1432
1438
  systemPrompt = DEFAULT_REVISER_SYSTEM_PROMPT,
1433
1439
  verbose = false
1434
1440
  } = config;
@@ -1458,7 +1464,7 @@ ${revisionsText}`;
1458
1464
  new import_messages3.SystemMessage(systemPrompt),
1459
1465
  new import_messages3.HumanMessage(userPrompt)
1460
1466
  ];
1461
- const response = await llm.invoke(messages);
1467
+ const response = await model.invoke(messages);
1462
1468
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1463
1469
  if (verbose) {
1464
1470
  console.log("[Reviser] Created revision:", content.substring(0, 100) + "...");
@@ -1900,8 +1906,8 @@ Respond with a JSON object containing:
1900
1906
  var llmBasedRouting = {
1901
1907
  name: "llm-based",
1902
1908
  async route(state, config) {
1903
- if (!config.llm) {
1904
- throw new Error("LLM-based routing requires an LLM to be configured");
1909
+ if (!config.model) {
1910
+ throw new Error("LLM-based routing requires a model to be configured");
1905
1911
  }
1906
1912
  const systemPrompt = config.systemPrompt || DEFAULT_SUPERVISOR_SYSTEM_PROMPT;
1907
1913
  const workerInfo = Object.entries(state.workers).map(([id, caps]) => {
@@ -1922,7 +1928,7 @@ Select the best worker for this task and explain your reasoning.`;
1922
1928
  new import_messages4.SystemMessage(systemPrompt),
1923
1929
  new import_messages4.HumanMessage(userPrompt)
1924
1930
  ];
1925
- const response = await config.llm.invoke(messages);
1931
+ const response = await config.model.invoke(messages);
1926
1932
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1927
1933
  try {
1928
1934
  const decision = JSON.parse(content);
@@ -2129,7 +2135,7 @@ function createWorkerNode(config) {
2129
2135
  const {
2130
2136
  id,
2131
2137
  capabilities,
2132
- llm,
2138
+ model,
2133
2139
  tools = [],
2134
2140
  systemPrompt,
2135
2141
  verbose = false,
@@ -2155,8 +2161,8 @@ function createWorkerNode(config) {
2155
2161
  if (executeFn) {
2156
2162
  return await executeFn(state);
2157
2163
  }
2158
- if (!llm) {
2159
- throw new Error(`Worker ${id} requires either an LLM or custom execution function`);
2164
+ if (!model) {
2165
+ throw new Error(`Worker ${id} requires either a model or custom execution function`);
2160
2166
  }
2161
2167
  const defaultSystemPrompt = `You are a specialized worker agent with the following capabilities:
2162
2168
  Skills: ${capabilities.skills.join(", ")}
@@ -2167,12 +2173,12 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
2167
2173
  new import_messages5.SystemMessage(systemPrompt || defaultSystemPrompt),
2168
2174
  new import_messages5.HumanMessage(currentAssignment.task)
2169
2175
  ];
2170
- let llmToUse = llm;
2171
- if (tools.length > 0 && llm.bindTools) {
2176
+ let modelToUse = model;
2177
+ if (tools.length > 0 && model.bindTools) {
2172
2178
  const langchainTools = (0, import_core7.toLangChainTools)(tools);
2173
- llmToUse = llm.bindTools(langchainTools);
2179
+ modelToUse = model.bindTools(langchainTools);
2174
2180
  }
2175
- const response = await llmToUse.invoke(messages);
2181
+ const response = await modelToUse.invoke(messages);
2176
2182
  const result = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
2177
2183
  if (verbose) {
2178
2184
  console.log(`[Worker:${id}] Task completed:`, result.substring(0, 100) + "...");
@@ -2242,7 +2248,7 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
2242
2248
  }
2243
2249
  function createAggregatorNode(config = {}) {
2244
2250
  const {
2245
- llm,
2251
+ model,
2246
2252
  systemPrompt = DEFAULT_AGGREGATOR_SYSTEM_PROMPT,
2247
2253
  aggregateFn,
2248
2254
  verbose = false
@@ -2265,7 +2271,7 @@ function createAggregatorNode(config = {}) {
2265
2271
  status: "completed"
2266
2272
  };
2267
2273
  }
2268
- if (!llm) {
2274
+ if (!model) {
2269
2275
  const combinedResults = state.completedTasks.filter((task) => task.success).map((task) => task.result).join("\n\n");
2270
2276
  return {
2271
2277
  response: combinedResults || "No successful results to aggregate.",
@@ -2288,7 +2294,7 @@ Please synthesize these results into a comprehensive response that addresses the
2288
2294
  new import_messages5.SystemMessage(systemPrompt),
2289
2295
  new import_messages5.HumanMessage(userPrompt)
2290
2296
  ];
2291
- const response = await llm.invoke(messages);
2297
+ const response = await model.invoke(messages);
2292
2298
  const aggregatedResponse = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
2293
2299
  if (verbose) {
2294
2300
  console.log("[Aggregator] Aggregation complete");
@@ -2429,7 +2435,7 @@ var MultiAgentSystemBuilder = class {
2429
2435
  available: true,
2430
2436
  currentWorkload: 0
2431
2437
  },
2432
- llm: worker.llm || this.config.supervisor.llm,
2438
+ model: worker.model || this.config.supervisor.model,
2433
2439
  tools: worker.tools,
2434
2440
  systemPrompt: worker.systemPrompt
2435
2441
  });
package/dist/index.d.cts CHANGED
@@ -138,7 +138,7 @@ interface ReActAgentConfig {
138
138
  /**
139
139
  * Language model to use for reasoning
140
140
  */
141
- llm: BaseChatModel;
141
+ model: BaseChatModel;
142
142
  /**
143
143
  * Tools available to the agent
144
144
  * Can be a ToolRegistry or an array of Tools
@@ -226,7 +226,7 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
226
226
  * import { ChatOpenAI } from '@langchain/openai';
227
227
  *
228
228
  * const agent = createReActAgent({
229
- * llm: new ChatOpenAI({ model: 'gpt-4' }),
229
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
230
230
  * tools: toolRegistry,
231
231
  * systemPrompt: 'You are a helpful assistant.',
232
232
  * maxIterations: 10
@@ -268,7 +268,11 @@ declare class ReActAgentBuilder {
268
268
  /**
269
269
  * Set the language model (required)
270
270
  *
271
- * @param llm - LangChain chat model to use for reasoning
271
+ * @param model - LangChain chat model to use for reasoning
272
+ */
273
+ withModel(model: BaseChatModel): this;
274
+ /**
275
+ * @deprecated Use withModel() instead
272
276
  */
273
277
  withLLM(llm: BaseChatModel): this;
274
278
  /**
@@ -799,9 +803,9 @@ type PlanExecuteStateType = {
799
803
  */
800
804
  interface PlannerConfig {
801
805
  /**
802
- * LLM to use for planning
806
+ * Language model to use for planning
803
807
  */
804
- llm: BaseChatModel;
808
+ model: BaseChatModel;
805
809
  /**
806
810
  * System prompt for the planner
807
811
  */
@@ -824,9 +828,9 @@ interface ExecutorConfig {
824
828
  */
825
829
  tools: Tool[];
826
830
  /**
827
- * Optional LLM for sub-tasks
831
+ * Optional language model for sub-tasks
828
832
  */
829
- llm?: BaseChatModel;
833
+ model?: BaseChatModel;
830
834
  /**
831
835
  * Enable parallel execution of independent steps
832
836
  */
@@ -841,9 +845,9 @@ interface ExecutorConfig {
841
845
  */
842
846
  interface ReplannerConfig {
843
847
  /**
844
- * LLM to use for replanning decisions
848
+ * Language model to use for replanning decisions
845
849
  */
846
- llm: BaseChatModel;
850
+ model: BaseChatModel;
847
851
  /**
848
852
  * Confidence threshold for replanning (0-1)
849
853
  * If confidence is below this, trigger replanning
@@ -921,7 +925,7 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
921
925
  *
922
926
  * const agent = createPlanExecuteAgent({
923
927
  * planner: {
924
- * llm: new ChatOpenAI({ model: 'gpt-4' }),
928
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
925
929
  * maxSteps: 5
926
930
  * },
927
931
  * executor: {
@@ -929,7 +933,7 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
929
933
  * parallel: false
930
934
  * },
931
935
  * replanner: {
932
- * llm: new ChatOpenAI({ model: 'gpt-4' }),
936
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
933
937
  * replanThreshold: 0.7
934
938
  * }
935
939
  * });
@@ -1445,7 +1449,7 @@ interface GeneratorConfig {
1445
1449
  /**
1446
1450
  * Language model for generation
1447
1451
  */
1448
- llm: BaseChatModel;
1452
+ model: BaseChatModel;
1449
1453
  /**
1450
1454
  * System prompt for the generator
1451
1455
  */
@@ -1462,7 +1466,7 @@ interface ReflectorConfig {
1462
1466
  /**
1463
1467
  * Language model for reflection
1464
1468
  */
1465
- llm: BaseChatModel;
1469
+ model: BaseChatModel;
1466
1470
  /**
1467
1471
  * System prompt for the reflector
1468
1472
  */
@@ -1483,7 +1487,7 @@ interface ReviserConfig {
1483
1487
  /**
1484
1488
  * Language model for revision
1485
1489
  */
1486
- llm: BaseChatModel;
1490
+ model: BaseChatModel;
1487
1491
  /**
1488
1492
  * System prompt for the reviser
1489
1493
  */
@@ -1630,12 +1634,12 @@ declare function createFinisherNode(): (state: ReflectionStateType) => Promise<P
1630
1634
  * import { createReflectionAgent } from '@agentforge/patterns';
1631
1635
  * import { ChatOpenAI } from '@langchain/openai';
1632
1636
  *
1633
- * const llm = new ChatOpenAI({ model: 'gpt-4' });
1637
+ * const model = new ChatOpenAI({ model: 'gpt-4' });
1634
1638
  *
1635
1639
  * const agent = createReflectionAgent({
1636
- * generator: { llm },
1637
- * reflector: { llm },
1638
- * reviser: { llm },
1640
+ * generator: { model },
1641
+ * reflector: { model },
1642
+ * reviser: { model },
1639
1643
  * maxIterations: 3,
1640
1644
  * qualityCriteria: {
1641
1645
  * minScore: 8,
@@ -2257,7 +2261,7 @@ interface SupervisorConfig {
2257
2261
  /**
2258
2262
  * Language model for routing decisions (used for LLM-based routing)
2259
2263
  */
2260
- llm?: BaseChatModel;
2264
+ model?: BaseChatModel;
2261
2265
  /**
2262
2266
  * Routing strategy to use
2263
2267
  */
@@ -2294,7 +2298,7 @@ interface WorkerConfig {
2294
2298
  /**
2295
2299
  * Language model for the worker
2296
2300
  */
2297
- llm?: BaseChatModel;
2301
+ model?: BaseChatModel;
2298
2302
  /**
2299
2303
  * Available tools for this worker
2300
2304
  */
@@ -2319,7 +2323,7 @@ interface AggregatorConfig {
2319
2323
  /**
2320
2324
  * Language model for aggregation (optional)
2321
2325
  */
2322
- llm?: BaseChatModel;
2326
+ model?: BaseChatModel;
2323
2327
  /**
2324
2328
  * System prompt for aggregation
2325
2329
  */
@@ -2468,7 +2472,7 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
2468
2472
  * const system = createMultiAgentSystem({
2469
2473
  * supervisor: {
2470
2474
  * strategy: 'skill-based',
2471
- * llm: chatModel,
2475
+ * model: chatModel,
2472
2476
  * },
2473
2477
  * workers: [
2474
2478
  * {
@@ -2479,7 +2483,7 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
2479
2483
  * available: true,
2480
2484
  * currentWorkload: 0,
2481
2485
  * },
2482
- * llm: chatModel,
2486
+ * model: chatModel,
2483
2487
  * },
2484
2488
  * {
2485
2489
  * id: 'writer',
@@ -2489,11 +2493,11 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
2489
2493
  * available: true,
2490
2494
  * currentWorkload: 0,
2491
2495
  * },
2492
- * llm: chatModel,
2496
+ * model: chatModel,
2493
2497
  * },
2494
2498
  * ],
2495
2499
  * aggregator: {
2496
- * llm: chatModel,
2500
+ * model: chatModel,
2497
2501
  * },
2498
2502
  * });
2499
2503
  *
@@ -2550,7 +2554,7 @@ declare class MultiAgentSystemBuilder {
2550
2554
  capabilities: string[];
2551
2555
  tools?: any[];
2552
2556
  systemPrompt?: string;
2553
- llm?: any;
2557
+ model?: any;
2554
2558
  }>): this;
2555
2559
  /**
2556
2560
  * Build and compile the multi-agent system
package/dist/index.d.ts CHANGED
@@ -138,7 +138,7 @@ interface ReActAgentConfig {
138
138
  /**
139
139
  * Language model to use for reasoning
140
140
  */
141
- llm: BaseChatModel;
141
+ model: BaseChatModel;
142
142
  /**
143
143
  * Tools available to the agent
144
144
  * Can be a ToolRegistry or an array of Tools
@@ -226,7 +226,7 @@ declare const DEFAULT_REACT_SYSTEM_PROMPT = "You are a helpful assistant that us
226
226
  * import { ChatOpenAI } from '@langchain/openai';
227
227
  *
228
228
  * const agent = createReActAgent({
229
- * llm: new ChatOpenAI({ model: 'gpt-4' }),
229
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
230
230
  * tools: toolRegistry,
231
231
  * systemPrompt: 'You are a helpful assistant.',
232
232
  * maxIterations: 10
@@ -268,7 +268,11 @@ declare class ReActAgentBuilder {
268
268
  /**
269
269
  * Set the language model (required)
270
270
  *
271
- * @param llm - LangChain chat model to use for reasoning
271
+ * @param model - LangChain chat model to use for reasoning
272
+ */
273
+ withModel(model: BaseChatModel): this;
274
+ /**
275
+ * @deprecated Use withModel() instead
272
276
  */
273
277
  withLLM(llm: BaseChatModel): this;
274
278
  /**
@@ -799,9 +803,9 @@ type PlanExecuteStateType = {
799
803
  */
800
804
  interface PlannerConfig {
801
805
  /**
802
- * LLM to use for planning
806
+ * Language model to use for planning
803
807
  */
804
- llm: BaseChatModel;
808
+ model: BaseChatModel;
805
809
  /**
806
810
  * System prompt for the planner
807
811
  */
@@ -824,9 +828,9 @@ interface ExecutorConfig {
824
828
  */
825
829
  tools: Tool[];
826
830
  /**
827
- * Optional LLM for sub-tasks
831
+ * Optional language model for sub-tasks
828
832
  */
829
- llm?: BaseChatModel;
833
+ model?: BaseChatModel;
830
834
  /**
831
835
  * Enable parallel execution of independent steps
832
836
  */
@@ -841,9 +845,9 @@ interface ExecutorConfig {
841
845
  */
842
846
  interface ReplannerConfig {
843
847
  /**
844
- * LLM to use for replanning decisions
848
+ * Language model to use for replanning decisions
845
849
  */
846
- llm: BaseChatModel;
850
+ model: BaseChatModel;
847
851
  /**
848
852
  * Confidence threshold for replanning (0-1)
849
853
  * If confidence is below this, trigger replanning
@@ -921,7 +925,7 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
921
925
  *
922
926
  * const agent = createPlanExecuteAgent({
923
927
  * planner: {
924
- * llm: new ChatOpenAI({ model: 'gpt-4' }),
928
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
925
929
  * maxSteps: 5
926
930
  * },
927
931
  * executor: {
@@ -929,7 +933,7 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
929
933
  * parallel: false
930
934
  * },
931
935
  * replanner: {
932
- * llm: new ChatOpenAI({ model: 'gpt-4' }),
936
+ * model: new ChatOpenAI({ model: 'gpt-4' }),
933
937
  * replanThreshold: 0.7
934
938
  * }
935
939
  * });
@@ -1445,7 +1449,7 @@ interface GeneratorConfig {
1445
1449
  /**
1446
1450
  * Language model for generation
1447
1451
  */
1448
- llm: BaseChatModel;
1452
+ model: BaseChatModel;
1449
1453
  /**
1450
1454
  * System prompt for the generator
1451
1455
  */
@@ -1462,7 +1466,7 @@ interface ReflectorConfig {
1462
1466
  /**
1463
1467
  * Language model for reflection
1464
1468
  */
1465
- llm: BaseChatModel;
1469
+ model: BaseChatModel;
1466
1470
  /**
1467
1471
  * System prompt for the reflector
1468
1472
  */
@@ -1483,7 +1487,7 @@ interface ReviserConfig {
1483
1487
  /**
1484
1488
  * Language model for revision
1485
1489
  */
1486
- llm: BaseChatModel;
1490
+ model: BaseChatModel;
1487
1491
  /**
1488
1492
  * System prompt for the reviser
1489
1493
  */
@@ -1630,12 +1634,12 @@ declare function createFinisherNode(): (state: ReflectionStateType) => Promise<P
1630
1634
  * import { createReflectionAgent } from '@agentforge/patterns';
1631
1635
  * import { ChatOpenAI } from '@langchain/openai';
1632
1636
  *
1633
- * const llm = new ChatOpenAI({ model: 'gpt-4' });
1637
+ * const model = new ChatOpenAI({ model: 'gpt-4' });
1634
1638
  *
1635
1639
  * const agent = createReflectionAgent({
1636
- * generator: { llm },
1637
- * reflector: { llm },
1638
- * reviser: { llm },
1640
+ * generator: { model },
1641
+ * reflector: { model },
1642
+ * reviser: { model },
1639
1643
  * maxIterations: 3,
1640
1644
  * qualityCriteria: {
1641
1645
  * minScore: 8,
@@ -2257,7 +2261,7 @@ interface SupervisorConfig {
2257
2261
  /**
2258
2262
  * Language model for routing decisions (used for LLM-based routing)
2259
2263
  */
2260
- llm?: BaseChatModel;
2264
+ model?: BaseChatModel;
2261
2265
  /**
2262
2266
  * Routing strategy to use
2263
2267
  */
@@ -2294,7 +2298,7 @@ interface WorkerConfig {
2294
2298
  /**
2295
2299
  * Language model for the worker
2296
2300
  */
2297
- llm?: BaseChatModel;
2301
+ model?: BaseChatModel;
2298
2302
  /**
2299
2303
  * Available tools for this worker
2300
2304
  */
@@ -2319,7 +2323,7 @@ interface AggregatorConfig {
2319
2323
  /**
2320
2324
  * Language model for aggregation (optional)
2321
2325
  */
2322
- llm?: BaseChatModel;
2326
+ model?: BaseChatModel;
2323
2327
  /**
2324
2328
  * System prompt for aggregation
2325
2329
  */
@@ -2468,7 +2472,7 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
2468
2472
  * const system = createMultiAgentSystem({
2469
2473
  * supervisor: {
2470
2474
  * strategy: 'skill-based',
2471
- * llm: chatModel,
2475
+ * model: chatModel,
2472
2476
  * },
2473
2477
  * workers: [
2474
2478
  * {
@@ -2479,7 +2483,7 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
2479
2483
  * available: true,
2480
2484
  * currentWorkload: 0,
2481
2485
  * },
2482
- * llm: chatModel,
2486
+ * model: chatModel,
2483
2487
  * },
2484
2488
  * {
2485
2489
  * id: 'writer',
@@ -2489,11 +2493,11 @@ declare function createAggregatorNode(config?: AggregatorConfig): (state: MultiA
2489
2493
  * available: true,
2490
2494
  * currentWorkload: 0,
2491
2495
  * },
2492
- * llm: chatModel,
2496
+ * model: chatModel,
2493
2497
  * },
2494
2498
  * ],
2495
2499
  * aggregator: {
2496
- * llm: chatModel,
2500
+ * model: chatModel,
2497
2501
  * },
2498
2502
  * });
2499
2503
  *
@@ -2550,7 +2554,7 @@ declare class MultiAgentSystemBuilder {
2550
2554
  capabilities: string[];
2551
2555
  tools?: any[];
2552
2556
  systemPrompt?: string;
2553
- llm?: any;
2557
+ model?: any;
2554
2558
  }>): this;
2555
2559
  /**
2556
2560
  * Build and compile the multi-agent system
package/dist/index.js CHANGED
@@ -290,7 +290,7 @@ import { StateGraph, END } from "@langchain/langgraph";
290
290
  import { ToolRegistry } from "@agentforge/core";
291
291
  function createReActAgent(config, options) {
292
292
  const {
293
- llm,
293
+ model,
294
294
  tools,
295
295
  systemPrompt = DEFAULT_REACT_SYSTEM_PROMPT,
296
296
  maxIterations = 10,
@@ -306,7 +306,7 @@ function createReActAgent(config, options) {
306
306
  const ACTION_NODE = nodeNames.action || "action";
307
307
  const OBSERVATION_NODE = nodeNames.observation || "observation";
308
308
  const reasoningNode = createReasoningNode(
309
- llm,
309
+ model,
310
310
  toolArray,
311
311
  systemPrompt,
312
312
  maxIterations,
@@ -340,12 +340,18 @@ var ReActAgentBuilder = class {
340
340
  /**
341
341
  * Set the language model (required)
342
342
  *
343
- * @param llm - LangChain chat model to use for reasoning
343
+ * @param model - LangChain chat model to use for reasoning
344
344
  */
345
- withLLM(llm) {
346
- this.config.llm = llm;
345
+ withModel(model) {
346
+ this.config.model = model;
347
347
  return this;
348
348
  }
349
+ /**
350
+ * @deprecated Use withModel() instead
351
+ */
352
+ withLLM(llm) {
353
+ return this.withModel(llm);
354
+ }
349
355
  /**
350
356
  * Set the tools (required)
351
357
  *
@@ -416,14 +422,14 @@ var ReActAgentBuilder = class {
416
422
  * @throws Error if required configuration is missing
417
423
  */
418
424
  build() {
419
- if (!this.config.llm) {
420
- throw new Error("ReActAgentBuilder: llm is required. Use withLLM() to set it.");
425
+ if (!this.config.model) {
426
+ throw new Error("ReActAgentBuilder: model is required. Use withModel() to set it.");
421
427
  }
422
428
  if (!this.config.tools) {
423
429
  throw new Error("ReActAgentBuilder: tools are required. Use withTools() to set them.");
424
430
  }
425
431
  const finalConfig = {
426
- llm: this.config.llm,
432
+ model: this.config.model,
427
433
  tools: this.config.tools,
428
434
  systemPrompt: this.config.systemPrompt || DEFAULT_REACT_SYSTEM_PROMPT,
429
435
  maxIterations: this.config.maxIterations ?? 10,
@@ -671,7 +677,7 @@ var REMAINING_STEP_TEMPLATE = `Step {stepNumber}: {description}
671
677
  // src/plan-execute/nodes.ts
672
678
  function createPlannerNode(config) {
673
679
  const {
674
- llm,
680
+ model,
675
681
  systemPrompt = DEFAULT_PLANNER_SYSTEM_PROMPT,
676
682
  maxSteps = 7,
677
683
  includeToolDescriptions = false
@@ -687,7 +693,7 @@ function createPlannerNode(config) {
687
693
  new SystemMessage2(systemPrompt),
688
694
  new HumanMessage2(userPrompt)
689
695
  ];
690
- const response = await llm.invoke(messages);
696
+ const response = await model.invoke(messages);
691
697
  const content = response.content.toString();
692
698
  let plan;
693
699
  try {
@@ -719,7 +725,7 @@ function createPlannerNode(config) {
719
725
  function createExecutorNode(config) {
720
726
  const {
721
727
  tools,
722
- llm,
728
+ model,
723
729
  parallel = false,
724
730
  stepTimeout = 3e4
725
731
  } = config;
@@ -789,7 +795,7 @@ function createExecutorNode(config) {
789
795
  }
790
796
  function createReplannerNode(config) {
791
797
  const {
792
- llm,
798
+ model,
793
799
  replanThreshold = 0.7,
794
800
  systemPrompt = DEFAULT_REPLANNER_SYSTEM_PROMPT
795
801
  } = config;
@@ -811,7 +817,7 @@ function createReplannerNode(config) {
811
817
  new SystemMessage2(systemPrompt),
812
818
  new HumanMessage2(userPrompt)
813
819
  ];
814
- const response = await llm.invoke(messages);
820
+ const response = await model.invoke(messages);
815
821
  const content = response.content.toString();
816
822
  let decision;
817
823
  try {
@@ -1209,7 +1215,7 @@ var REVISION_ENTRY_TEMPLATE = `Iteration {iteration}:
1209
1215
  import { HumanMessage as HumanMessage3, SystemMessage as SystemMessage3 } from "@langchain/core/messages";
1210
1216
  function createGeneratorNode(config) {
1211
1217
  const {
1212
- llm,
1218
+ model,
1213
1219
  systemPrompt = DEFAULT_GENERATOR_SYSTEM_PROMPT,
1214
1220
  verbose = false
1215
1221
  } = config;
@@ -1230,7 +1236,7 @@ ${lastReflection.critique}`;
1230
1236
  new SystemMessage3(systemPrompt),
1231
1237
  new HumanMessage3(userPrompt)
1232
1238
  ];
1233
- const response = await llm.invoke(messages);
1239
+ const response = await model.invoke(messages);
1234
1240
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1235
1241
  if (verbose) {
1236
1242
  console.log("[Generator] Generated response:", content.substring(0, 100) + "...");
@@ -1251,7 +1257,7 @@ ${lastReflection.critique}`;
1251
1257
  }
1252
1258
  function createReflectorNode(config) {
1253
1259
  const {
1254
- llm,
1260
+ model,
1255
1261
  systemPrompt = DEFAULT_REFLECTOR_SYSTEM_PROMPT,
1256
1262
  qualityCriteria,
1257
1263
  verbose = false
@@ -1285,7 +1291,7 @@ function createReflectorNode(config) {
1285
1291
  new SystemMessage3(systemPrompt),
1286
1292
  new HumanMessage3(userPrompt)
1287
1293
  ];
1288
- const response = await llm.invoke(messages);
1294
+ const response = await model.invoke(messages);
1289
1295
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1290
1296
  let reflection;
1291
1297
  try {
@@ -1329,7 +1335,7 @@ function createReflectorNode(config) {
1329
1335
  }
1330
1336
  function createReviserNode(config) {
1331
1337
  const {
1332
- llm,
1338
+ model,
1333
1339
  systemPrompt = DEFAULT_REVISER_SYSTEM_PROMPT,
1334
1340
  verbose = false
1335
1341
  } = config;
@@ -1359,7 +1365,7 @@ ${revisionsText}`;
1359
1365
  new SystemMessage3(systemPrompt),
1360
1366
  new HumanMessage3(userPrompt)
1361
1367
  ];
1362
- const response = await llm.invoke(messages);
1368
+ const response = await model.invoke(messages);
1363
1369
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1364
1370
  if (verbose) {
1365
1371
  console.log("[Reviser] Created revision:", content.substring(0, 100) + "...");
@@ -1801,8 +1807,8 @@ Respond with a JSON object containing:
1801
1807
  var llmBasedRouting = {
1802
1808
  name: "llm-based",
1803
1809
  async route(state, config) {
1804
- if (!config.llm) {
1805
- throw new Error("LLM-based routing requires an LLM to be configured");
1810
+ if (!config.model) {
1811
+ throw new Error("LLM-based routing requires a model to be configured");
1806
1812
  }
1807
1813
  const systemPrompt = config.systemPrompt || DEFAULT_SUPERVISOR_SYSTEM_PROMPT;
1808
1814
  const workerInfo = Object.entries(state.workers).map(([id, caps]) => {
@@ -1823,7 +1829,7 @@ Select the best worker for this task and explain your reasoning.`;
1823
1829
  new SystemMessage4(systemPrompt),
1824
1830
  new HumanMessage4(userPrompt)
1825
1831
  ];
1826
- const response = await config.llm.invoke(messages);
1832
+ const response = await config.model.invoke(messages);
1827
1833
  const content = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
1828
1834
  try {
1829
1835
  const decision = JSON.parse(content);
@@ -2030,7 +2036,7 @@ function createWorkerNode(config) {
2030
2036
  const {
2031
2037
  id,
2032
2038
  capabilities,
2033
- llm,
2039
+ model,
2034
2040
  tools = [],
2035
2041
  systemPrompt,
2036
2042
  verbose = false,
@@ -2056,8 +2062,8 @@ function createWorkerNode(config) {
2056
2062
  if (executeFn) {
2057
2063
  return await executeFn(state);
2058
2064
  }
2059
- if (!llm) {
2060
- throw new Error(`Worker ${id} requires either an LLM or custom execution function`);
2065
+ if (!model) {
2066
+ throw new Error(`Worker ${id} requires either a model or custom execution function`);
2061
2067
  }
2062
2068
  const defaultSystemPrompt = `You are a specialized worker agent with the following capabilities:
2063
2069
  Skills: ${capabilities.skills.join(", ")}
@@ -2068,12 +2074,12 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
2068
2074
  new SystemMessage5(systemPrompt || defaultSystemPrompt),
2069
2075
  new HumanMessage5(currentAssignment.task)
2070
2076
  ];
2071
- let llmToUse = llm;
2072
- if (tools.length > 0 && llm.bindTools) {
2077
+ let modelToUse = model;
2078
+ if (tools.length > 0 && model.bindTools) {
2073
2079
  const langchainTools = toLangChainTools2(tools);
2074
- llmToUse = llm.bindTools(langchainTools);
2080
+ modelToUse = model.bindTools(langchainTools);
2075
2081
  }
2076
- const response = await llmToUse.invoke(messages);
2082
+ const response = await modelToUse.invoke(messages);
2077
2083
  const result = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
2078
2084
  if (verbose) {
2079
2085
  console.log(`[Worker:${id}] Task completed:`, result.substring(0, 100) + "...");
@@ -2143,7 +2149,7 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
2143
2149
  }
2144
2150
  function createAggregatorNode(config = {}) {
2145
2151
  const {
2146
- llm,
2152
+ model,
2147
2153
  systemPrompt = DEFAULT_AGGREGATOR_SYSTEM_PROMPT,
2148
2154
  aggregateFn,
2149
2155
  verbose = false
@@ -2166,7 +2172,7 @@ function createAggregatorNode(config = {}) {
2166
2172
  status: "completed"
2167
2173
  };
2168
2174
  }
2169
- if (!llm) {
2175
+ if (!model) {
2170
2176
  const combinedResults = state.completedTasks.filter((task) => task.success).map((task) => task.result).join("\n\n");
2171
2177
  return {
2172
2178
  response: combinedResults || "No successful results to aggregate.",
@@ -2189,7 +2195,7 @@ Please synthesize these results into a comprehensive response that addresses the
2189
2195
  new SystemMessage5(systemPrompt),
2190
2196
  new HumanMessage5(userPrompt)
2191
2197
  ];
2192
- const response = await llm.invoke(messages);
2198
+ const response = await model.invoke(messages);
2193
2199
  const aggregatedResponse = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
2194
2200
  if (verbose) {
2195
2201
  console.log("[Aggregator] Aggregation complete");
@@ -2330,7 +2336,7 @@ var MultiAgentSystemBuilder = class {
2330
2336
  available: true,
2331
2337
  currentWorkload: 0
2332
2338
  },
2333
- llm: worker.llm || this.config.supervisor.llm,
2339
+ model: worker.model || this.config.supervisor.model,
2334
2340
  tools: worker.tools,
2335
2341
  systemPrompt: worker.systemPrompt
2336
2342
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/patterns",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Agent patterns (ReAct, Planner-Executor) for AgentForge framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",