@ellyco/agentic 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +88 -126
  2. package/dist/graphs/graph.d.ts.map +1 -1
  3. package/dist/graphs/graph.js +72 -47
  4. package/dist/graphs/graph.js.map +1 -1
  5. package/dist/graphs/index.d.ts +0 -1
  6. package/dist/graphs/index.d.ts.map +1 -1
  7. package/dist/graphs/index.js +0 -1
  8. package/dist/graphs/index.js.map +1 -1
  9. package/dist/graphs/iterator.d.ts +25 -21
  10. package/dist/graphs/iterator.d.ts.map +1 -1
  11. package/dist/graphs/iterator.js +30 -25
  12. package/dist/graphs/iterator.js.map +1 -1
  13. package/dist/graphs/types.d.ts +2 -3
  14. package/dist/graphs/types.d.ts.map +1 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/models/BaseModel.d.ts +3 -1
  20. package/dist/models/BaseModel.d.ts.map +1 -1
  21. package/dist/models/BaseModel.js +5 -0
  22. package/dist/models/BaseModel.js.map +1 -1
  23. package/dist/models/react-agent.d.ts +12 -0
  24. package/dist/models/react-agent.d.ts.map +1 -0
  25. package/dist/models/react-agent.js +48 -0
  26. package/dist/models/react-agent.js.map +1 -0
  27. package/dist/nodes/index.d.ts +1 -0
  28. package/dist/nodes/index.d.ts.map +1 -1
  29. package/dist/nodes/index.js +1 -0
  30. package/dist/nodes/index.js.map +1 -1
  31. package/dist/nodes/model-node.d.ts +207 -25
  32. package/dist/nodes/model-node.d.ts.map +1 -1
  33. package/dist/nodes/model-node.js +124 -24
  34. package/dist/nodes/model-node.js.map +1 -1
  35. package/dist/nodes/state-transform.d.ts +108 -0
  36. package/dist/nodes/state-transform.d.ts.map +1 -0
  37. package/dist/nodes/state-transform.js +141 -0
  38. package/dist/nodes/state-transform.js.map +1 -0
  39. package/dist/tools.d.ts +10 -9
  40. package/dist/tools.d.ts.map +1 -1
  41. package/dist/tools.js +3 -2
  42. package/dist/tools.js.map +1 -1
  43. package/dist/util/clone-aware.d.ts +2 -0
  44. package/dist/util/clone-aware.d.ts.map +1 -0
  45. package/dist/util/clone-aware.js +29 -0
  46. package/dist/util/clone-aware.js.map +1 -0
  47. package/dist/util/index.d.ts +4 -0
  48. package/dist/util/index.d.ts.map +1 -0
  49. package/dist/util/index.js +20 -0
  50. package/dist/util/index.js.map +1 -0
  51. package/dist/util/merge-state.d.ts +50 -0
  52. package/dist/util/merge-state.d.ts.map +1 -0
  53. package/dist/util/merge-state.js +88 -0
  54. package/dist/util/merge-state.js.map +1 -0
  55. package/dist/util/serializer.d.ts +15 -0
  56. package/dist/util/serializer.d.ts.map +1 -0
  57. package/dist/util/serializer.js +73 -0
  58. package/dist/util/serializer.js.map +1 -0
  59. package/package.json +5 -1
  60. package/dist/graphs/merge-state.d.ts +0 -22
  61. package/dist/graphs/merge-state.d.ts.map +0 -1
  62. package/dist/graphs/merge-state.js +0 -56
  63. package/dist/graphs/merge-state.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Iterator = void 0;
4
4
  const nodes_1 = require("../nodes");
5
+ const util_1 = require("../util");
5
6
  const graph_1 = require("./graph");
6
7
  const zod_1 = require("zod");
7
8
  /**
@@ -24,44 +25,48 @@ const INCREMENT_INDEX_NODE = "increment-index";
24
25
  * @template S - The inferred state type from T
25
26
  * @template NS - The node state type including index and item
26
27
  *
27
- * @example
28
- * ```typescript
29
- * const schema = z.object({
30
- * items: z.array(z.object({ name: z.string(), value: z.number() }))
31
- * });
32
- *
33
- * const iterator = new Iterator(schema, "item", "items");
34
- * const looped = new NodeSequence(iterator.getNodeSchema());
35
- * looped.next(new FunctionNode((state) => ({
36
- * itemValue: state.itemItem.value * 2
37
- * })));
38
- *
39
- * iterator.setLoopedNode(looped);
40
- *
41
- * const result = await iterator.invoke({
42
- * items: [{ name: "a", value: 1 }, { name: "b", value: 2 }]
43
- * });
44
- * ```
28
+ * @example
29
+ * ```typescript
30
+ * const schema = z.object({
31
+ * items: z.array(z.object({ name: z.string(), value: z.number() }))
32
+ * });
33
+ *
34
+ * // With explicit prefix
35
+ * const iterator = new Iterator(schema, "items", "item");
36
+ * // Or without prefix (uses iteratorKey as prefix)
37
+ * const iterator2 = new Iterator(schema, "items");
38
+ *
39
+ * const looped = new NodeSequence(iterator.getNodeSchema());
40
+ * looped.next(new FunctionNode((state) => ({
41
+ * itemValue: state.itemItem.value * 2
42
+ * })));
43
+ *
44
+ * iterator.setLoopedNode(looped);
45
+ *
46
+ * const result = await iterator.invoke({
47
+ * items: [{ name: "a", value: 1 }, { name: "b", value: 2 }]
48
+ * });
49
+ * ```
45
50
  */
46
51
  class Iterator extends graph_1.Graph {
47
52
  schema;
48
- prefix;
49
53
  iteratorKey;
54
+ prefix;
50
55
  /**
51
56
  * Creates an iterator graph.
52
57
  *
53
58
  * @param {T} schema - The base state schema
54
- * @param {Prefix} prefix - Prefix for index and item keys
55
59
  * @param {ArrayKeys<z.infer<T>>} iteratorKey - The state key containing the array to iterate
60
+ * @param {Prefix} [prefix] - Optional prefix for index and item keys. If not provided, uses iteratorKey
56
61
  */
57
- constructor(schema, prefix,
62
+ constructor(schema,
58
63
  // Disabled for now, until I can figure out a better approach for this
59
64
  // private readonly iteratorSelector: (state: S | NS) => Item[],
60
- iteratorKey) {
65
+ iteratorKey, prefix = iteratorKey) {
61
66
  super(schema);
62
67
  this.schema = schema;
63
- this.prefix = prefix;
64
68
  this.iteratorKey = iteratorKey;
69
+ this.prefix = prefix;
65
70
  this.nodes[INCREMENT_INDEX_NODE] = new nodes_1.FunctionNode((_, context) => {
66
71
  const indexContext = context.custom.indexCtx;
67
72
  indexContext.currentNode = (Number(indexContext.currentNode) + 1).toString();
@@ -160,7 +165,7 @@ class Iterator extends graph_1.Graph {
160
165
  * @returns {Promise<Partial<S>>} Final state with updated array
161
166
  */
162
167
  async run(input, contextOrRuntime) {
163
- let state = structuredClone(input);
168
+ let state = (0, util_1.cloneAware)(input);
164
169
  if (this.nodes[ITERATOR_LOOP_NODE] === undefined) {
165
170
  throw new Error(`Looped node is not set`);
166
171
  }
@@ -177,7 +182,7 @@ class Iterator extends graph_1.Graph {
177
182
  const result = await this.runInternal(state, context);
178
183
  context.done();
179
184
  indexContext.done();
180
- return { ...result, [this.iteratorKey]: structuredClone(context.custom.arr) };
185
+ return { ...result, [this.iteratorKey]: (0, util_1.cloneAware)(context.custom.arr) };
181
186
  }
182
187
  }
183
188
  exports.Iterator = Iterator;
@@ -1 +1 @@
1
- {"version":3,"file":"iterator.js","sourceRoot":"","sources":["../../src/graphs/iterator.ts"],"names":[],"mappings":";;;AACA,oCAAkD;AAElD,mCAA4C;AAC5C,6BAAwB;AAmDxB;;GAEG;AACH,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,QAMX,SAAQ,aAAe;IASE;IACF;IAGA;IAZrB;;;;;;OAMG;IACH,YACuB,MAAS,EACX,MAAc;IAC/B,sEAAsE;IACtE,gEAAgE;IAC/C,WAAkC;QAEnD,KAAK,CAAC,MAAM,CAAC,CAAC;QANK,WAAM,GAAN,MAAM,CAAG;QACX,WAAM,GAAN,MAAM,CAAQ;QAGd,gBAAW,GAAX,WAAW,CAAuB;QAGnD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,IAAI,oBAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;YAC/D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,QAAwB,CAAC;YAC7D,YAAY,CAAC,WAAW,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,WAAY,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CA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CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IAC7E,CAAC;CACJ;AA5JD,4BA4JC"}
@@ -1,9 +1,9 @@
1
- interface EndResult<S> {
1
+ export interface EndResult<S> {
2
2
  runId: string;
3
3
  state: S;
4
4
  exitReason: "end";
5
5
  }
6
- interface InterruptResult<S> {
6
+ export interface InterruptResult<S> {
7
7
  runId: string;
8
8
  state: S;
9
9
  exitReason: "interrupt";
@@ -11,5 +11,4 @@ interface InterruptResult<S> {
11
11
  cursor: string;
12
12
  }
13
13
  export type GraphResult<S> = EndResult<S> | InterruptResult<S>;
14
- export {};
15
14
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graphs/types.ts"],"names":[],"mappings":"AAAA,UAAU,SAAS,CAAC,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,KAAK,CAAC;CACrB;AAED,UAAU,eAAe,CAAC,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graphs/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,KAAK,CAAC;CACrB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from "./messages";
3
3
  export * from "./models";
4
4
  export * from "./nodes";
5
5
  export * from "./tools";
6
+ export * from "./util";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -19,4 +19,5 @@ __exportStar(require("./messages"), exports);
19
19
  __exportStar(require("./models"), exports);
20
20
  __exportStar(require("./nodes"), exports);
21
21
  __exportStar(require("./tools"), exports);
22
+ __exportStar(require("./util"), exports);
22
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB;AACxB,yCAAuB"}
@@ -1,6 +1,7 @@
1
1
  import * as z from "zod";
2
2
  import { AgentMessage, MessageContent, ModelMessages, SystemMessage, ToolRequest } from "../messages";
3
- import { ToolDefinition } from "../tools";
3
+ import { ToolDefinition, ToolImplementation } from "../tools";
4
+ import { ReActAgent } from "./react-agent";
4
5
  /**
5
6
  * Configuration options for model initialization.
6
7
  *
@@ -167,6 +168,7 @@ export declare abstract class BaseModel {
167
168
  * ```
168
169
  */
169
170
  invoke(messages: ModelMessages[], properties?: Record<string, any>): Promise<InvokeResponse>;
171
+ makeReActAgent(tools: ToolImplementation<any, any, any>[]): ReActAgent;
170
172
  }
171
173
  /**
172
174
  * Error thrown when response is not structured output as expected.
@@ -1 +1 @@
1
- {"version":3,"file":"BaseModel.d.ts","sourceRoot":"","sources":["../../src/models/BaseModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EACH,YAAY,EAEZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,WAAW,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,oBAAY,wBAAwB;IAChC,OAAO,YAAY;IACnB,aAAa,kBAAkB;IAC/B,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACxB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,CAAC,YAAY,GAAG,WAAW,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AAC,EAAE,GAAG,UAAU;CAIzE;AAED;;;;;GAKG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;IACvD;;OAEG;;CAKN;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,uBAAuB,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;IAO1C,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAa,OAAO,CAAC,QAAQ,CAAC,MAAM;IANtE;;;;;OAKG;gBAC0B,KAAK,EAAE,SAAS,EAAmB,MAAM,EAAE,CAAC;IAEzE;;;;;OAKG;IACH,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc,GAAG,IAAI;IAKhE;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CACR,QAAQ,EAAE,aAAa,EAAE,EACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAWzB"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StructuredOutputWrapper = exports.ResponseNotStructuredOutputError = exports.BaseModel = exports.InvokeResponseStopReason = void 0;
4
4
  const messages_1 = require("../messages");
5
+ const react_agent_1 = require("./react-agent");
5
6
  /**
6
7
  * Enum representing the reason why model generation stopped.
7
8
  *
@@ -160,6 +161,10 @@ class BaseModel {
160
161
  return message;
161
162
  }));
162
163
  }
164
+ makeReActAgent(tools) {
165
+ this.tools = [];
166
+ return new react_agent_1.ReActAgent(this, tools);
167
+ }
163
168
  }
164
169
  exports.BaseModel = BaseModel;
165
170
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"BaseModel.js","sourceRoot":"","sources":["../../src/models/BaseModel.ts"],"names":[],"mappings":";;;AACA,0CAOqB;AA6BrB;;;;;;;;;GASG;AACH,IAAY,wBAMX;AAND,WAAY,wBAAwB;IAChC,+CAAmB,CAAA;IACnB,2DAA+B,CAAA;IAC/B,qDAAyB,C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;QAEhC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC/D,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,gCAAgC,EAAE,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,sBAAW,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,gCAAgC,EAAE,CAAC;QACjD,CAAC;QACD,MAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAgB,CAAC;QACxD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;CACJ;AAlDD,0DAkDC"}
@@ -0,0 +1,12 @@
1
+ import { ModelMessages } from "../messages";
2
+ import { ToolImplementation } from "../tools";
3
+ import { BaseModel } from "./BaseModel";
4
+ export declare class ReActAgent {
5
+ private readonly model;
6
+ private readonly tools;
7
+ invokeLoopLimit: number;
8
+ private readonly toolMap;
9
+ constructor(model: BaseModel, tools: ToolImplementation<any, any, any>[]);
10
+ invoke(messages: ModelMessages[], additionalArgs?: Record<string, any>): Promise<import("./BaseModel").InvokeResponse>;
11
+ }
12
+ //# sourceMappingURL=react-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-agent.d.ts","sourceRoot":"","sources":["../../src/models/react-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,UAAU;IAIP,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAa,OAAO,CAAC,QAAQ,CAAC,KAAK;IAHrE,eAAe,SAAM;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwD;gBAEnD,KAAK,EAAE,SAAS,EAAmB,KAAK,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE;IAOpG,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CA2B/E"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReActAgent = void 0;
4
+ const messages_1 = require("../messages");
5
+ const util_1 = require("../util");
6
+ class ReActAgent {
7
+ model;
8
+ tools;
9
+ invokeLoopLimit = 10;
10
+ toolMap = new Map();
11
+ constructor(model, tools) {
12
+ this.model = model;
13
+ this.tools = tools;
14
+ for (const tool of tools) {
15
+ this.toolMap.set(tool.name, tool);
16
+ }
17
+ }
18
+ // starts from the provided messages, and keeps running the agent until the response doesn't include tool calls
19
+ async invoke(messages, additionalArgs) {
20
+ let allMessage = (0, util_1.cloneAware)(messages);
21
+ this.model.withTools(this.tools.map(tool => ({
22
+ name: tool.name,
23
+ description: tool.description,
24
+ schema: tool.schema,
25
+ })));
26
+ let loopCount = 0;
27
+ while (loopCount < this.invokeLoopLimit) {
28
+ ++loopCount;
29
+ const response = await this.model.invoke(allMessage, additionalArgs);
30
+ const toolRequests = response.messages.filter(message => message instanceof messages_1.ToolRequest);
31
+ if (toolRequests.length === 0) {
32
+ return response;
33
+ }
34
+ allMessage = [...allMessage, ...response.messages];
35
+ for (const toolRequest of toolRequests) {
36
+ const tool = this.toolMap.get(toolRequest.toolName);
37
+ if (!tool) {
38
+ throw new Error(`Tool ${toolRequest.toolName} not found. This should not happen as all tools would be specified`);
39
+ }
40
+ const toolResponse = await tool.func(toolRequest.input, additionalArgs);
41
+ allMessage.push(new messages_1.ToolResponse(toolRequest.toolUseId, toolRequest.toolName, toolResponse));
42
+ }
43
+ }
44
+ throw new Error("ReActAgent loop limit reached without agent resolution.");
45
+ }
46
+ }
47
+ exports.ReActAgent = ReActAgent;
48
+ //# sourceMappingURL=react-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-agent.js","sourceRoot":"","sources":["../../src/models/react-agent.ts"],"names":[],"mappings":";;;AAAA,0CAAuE;AAEvE,kCAAqC;AAGrC,MAAa,UAAU;IAIU;IAAmC;IAHhE,eAAe,GAAG,EAAE,CAAC;IACJ,OAAO,GAAG,IAAI,GAAG,EAA6C,CAAC;IAEhF,YAA6B,KAAgB,EAAmB,KAA0C;QAA7E,UAAK,GAAL,KAAK,CAAW;QAAmB,UAAK,GAAL,KAAK,CAAqC;QACtG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC;IACL,CAAC;IAED,+GAA+G;IAC/G,KAAK,CAAC,MAAM,CAAC,QAAyB,EAAE,cAAoC;QACxE,IAAI,UAAU,GAAoB,IAAA,iBAAU,EAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC,CAAC,CAAC,CAAC;QACL,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,OAAO,SAAS,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACtC,EAAE,SAAS,CAAC;YACZ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;YACrE,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,YAAY,sBAAW,CAAC,CAAC;YACzF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC5B,OAAO,QAAQ,CAAC;YACpB,CAAC;YACD,UAAU,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAoB,CAAC;YACtE,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;gBACrC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,EAAE,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,QAAQ,WAAW,CAAC,QAAQ,oEAAoE,CAAC,CAAC;gBACtH,CAAC;gBACD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;gBACxE,UAAU,CAAC,IAAI,CAAC,IAAI,uBAAY,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;YACjG,CAAC;QACL,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC/E,CAAC;CACJ;AAtCD,gCAsCC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./function-node";
2
2
  export * from "./interrupt-node";
3
3
  export * from "./model-node";
4
+ export * from "./state-transform";
4
5
  export * from "./types";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./function-node"), exports);
18
18
  __exportStar(require("./interrupt-node"), exports);
19
19
  __exportStar(require("./model-node"), exports);
20
+ __exportStar(require("./state-transform"), exports);
20
21
  __exportStar(require("./types"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,+CAA6B;AAC7B,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,+CAA6B;AAC7B,oDAAkC;AAClC,0CAAwB"}
@@ -1,70 +1,252 @@
1
- import { ModelMessages } from "../messages";
2
- import { BaseModel, StructuredOutputWrapper } from "../models/BaseModel";
1
+ import { AgentMessage, ModelMessages, SystemMessage, ToolRequest } from "../messages";
2
+ import { BaseModel, InvokeResponse, StructuredOutputWrapper } from "../models/BaseModel";
3
3
  import { NodeLike } from "./types";
4
4
  import { ContextLayer } from "../graphs/runtime-context";
5
5
  import { TypedKeys } from "../types";
6
+ import { ToolDefinition } from "../tools";
6
7
  /**
7
8
  * Helper type to extract keys from an object that have ModelMessages[] values.
9
+ *
10
+ * @private
11
+ */
12
+ type InputMessagesKeys<T> = TypedKeys<T, ModelMessages[]>;
13
+ /**
14
+ * Helper type to extract keys from an object that have (AgentMessage | ToolRequest)[] values.
15
+ *
16
+ * @private
17
+ */
18
+ type OutputMessagesKeys<T> = TypedKeys<T, (AgentMessage | ToolRequest)[]>;
19
+ /**
20
+ * Configuration for selecting messages from state by key.
21
+ *
22
+ * @interface MessageSelected
23
+ * @template T - The state type
8
24
  */
9
- type MessagesKeys<T> = TypedKeys<T, ModelMessages[]>;
25
+ interface MessageSelected<T> {
26
+ /** Key in state containing the messages array */
27
+ messages: InputMessagesKeys<T>;
28
+ }
10
29
  /**
11
- * Configuration for messages provided through a function.
30
+ * Configuration for constructing messages dynamically from state and context.
31
+ *
32
+ * @interface MessageConstructed
33
+ * @template T - The state type
12
34
  */
13
- interface ConstructedMessages<T extends Record<string, unknown>> {
35
+ interface MessageConstructed<T> {
36
+ /** Function that generates messages from current state and context */
14
37
  messages: (state: T, context: ContextLayer) => ModelMessages[];
15
38
  }
16
39
  /**
17
- * Configuration for messages provided through a state path.
40
+ * Union type for message configuration - either selected from state or constructed dynamically.
41
+ *
42
+ * @typedef {MessageSelected<T> | MessageConstructed<T>} MessageConfig
43
+ * @template T - The state type
44
+ */
45
+ type MessageConfig<T> = MessageSelected<T> | MessageConstructed<T>;
46
+ /**
47
+ * Configuration for selecting output location from state by key.
48
+ *
49
+ * @interface OutputSelected
50
+ * @template T - The state type
51
+ * @template M - The model type (BaseModel or StructuredOutputWrapper)
18
52
  */
19
- interface MessagesPath<T> {
20
- messages: MessagesKeys<T>;
53
+ interface OutputSelected<T, M extends BaseModel | StructuredOutputWrapper<any>> {
54
+ /**
55
+ * Key in state where output should be stored.
56
+ * For StructuredOutputWrapper: any key in state.
57
+ * For BaseModel: key that contains (AgentMessage | ToolRequest)[] array.
58
+ */
59
+ output: M extends StructuredOutputWrapper<any> ? keyof T : OutputMessagesKeys<T>;
21
60
  }
22
61
  /**
23
- * Settings for a ModelNode specifying where to get messages and where to store output.
62
+ * Configuration for constructing output dynamically from model response.
63
+ *
64
+ * @interface OutputConstructed
65
+ * @template T - The state type
66
+ * @template M - The model type (BaseModel or StructuredOutputWrapper)
67
+ */
68
+ interface OutputConstructed<T, M extends BaseModel | StructuredOutputWrapper<any>> {
69
+ /**
70
+ * Function that transforms model response into partial state update.
71
+ * For StructuredOutputWrapper: receives the structured output directly.
72
+ * For BaseModel: receives InvokeResponse with messages array.
73
+ */
74
+ output: (response: M extends StructuredOutputWrapper<any> ? any : InvokeResponse, state: T, context: ContextLayer) => Partial<T>;
75
+ }
76
+ /**
77
+ * Union type for output configuration - either selected key or constructed dynamically.
78
+ *
79
+ * @typedef {OutputSelected<T, M> | OutputConstructed<T, M>} OutputConfig
80
+ * @template T - The state type
81
+ * @template M - The model type (BaseModel or StructuredOutputWrapper)
24
82
  */
25
- type ModelNodeSettings<T extends Record<string, unknown>> = {
26
- output: keyof T;
27
- } & (ConstructedMessages<T> | MessagesPath<T>);
83
+ type OutputConfig<T, M extends BaseModel | StructuredOutputWrapper<any>> = OutputSelected<T, M> | OutputConstructed<T, M>;
84
+ /**
85
+ * Configuration for a static system message.
86
+ *
87
+ * @interface SystemMessageStatic
88
+ */
89
+ interface SystemMessageStatic {
90
+ /** Static system message to use for all invocations */
91
+ systemMessage: SystemMessage;
92
+ }
93
+ /**
94
+ * Configuration for a dynamically generated system message.
95
+ *
96
+ * @interface SystemMessageDynamic
97
+ * @template T - The state type
98
+ */
99
+ interface SystemMessageDynamic<T> {
100
+ /** Function that generates system message from current state and context */
101
+ systemMessage: (state: T, context: ContextLayer) => SystemMessage;
102
+ }
103
+ /**
104
+ * Union type for system message configuration - either static or dynamic.
105
+ *
106
+ * @typedef {SystemMessageStatic | SystemMessageDynamic<T>} SystemMessageConfig
107
+ * @template T - The state type
108
+ */
109
+ type SystemMessageConfig<T> = SystemMessageStatic | SystemMessageDynamic<T>;
110
+ /**
111
+ * Configuration for static tool definitions.
112
+ *
113
+ * @interface ToolsStatic
114
+ */
115
+ interface ToolsStatic {
116
+ /** Array of tool definitions to use for all invocations */
117
+ tools: ToolDefinition[];
118
+ }
119
+ /**
120
+ * Configuration for dynamically generated tool definitions.
121
+ *
122
+ * @interface ToolsDynamic
123
+ * @template T - The state type
124
+ */
125
+ interface ToolsDynamic<T> {
126
+ /** Function that generates tool definitions from current state and context */
127
+ tools: (state: T, context: ContextLayer) => ToolDefinition[];
128
+ }
129
+ /**
130
+ * Union type for tools configuration - either static or dynamic.
131
+ *
132
+ * @typedef {ToolsStatic | ToolsDynamic<T>} ToolsConfig
133
+ * @template T - The state type
134
+ */
135
+ type ToolsConfig<T> = ToolsStatic | ToolsDynamic<T>;
136
+ /**
137
+ * Configuration object for ModelNode.
138
+ *
139
+ * @typedef {Object} ModelNodeConfig
140
+ * @template T - The state type
141
+ * @template M - The model type (BaseModel or StructuredOutputWrapper)
142
+ *
143
+ * @property {MessageConfig<T>} messages - Configuration for message source (key or function)
144
+ * @property {OutputConfig<T, M>} output - Configuration for output destination (key or function)
145
+ * @property {SystemMessageConfig<T>} [systemMessage] - Optional system message (static or dynamic)
146
+ * @property {ToolsConfig<T>} [tools] - Optional tool definitions (static or dynamic). Ignored when using StructuredOutputWrapper.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Static configuration
151
+ * const config: ModelNodeConfig<MyState, BaseModel> = {
152
+ * messages: "conversationHistory",
153
+ * output: "modelResponse",
154
+ * systemMessage: new SystemMessage("You are helpful"),
155
+ * tools: [searchTool, calculatorTool]
156
+ * };
157
+ *
158
+ * // Dynamic configuration
159
+ * const dynamicConfig: ModelNodeConfig<MyState, BaseModel> = {
160
+ * messages: (state, context) => state.messages.filter(m => m.role === "user"),
161
+ * output: (response, state, context) => ({
162
+ * modelResponse: response.messages,
163
+ * tokenUsage: response.usage
164
+ * }),
165
+ * systemMessage: (state, context) => new SystemMessage(`Context: ${state.context}`),
166
+ * tools: (state, context) => state.availableTools
167
+ * };
168
+ * ```
169
+ */
170
+ export type ModelNodeConfig<T extends Record<string, unknown>, M extends BaseModel | StructuredOutputWrapper<any>> = OutputConfig<T, M> & MessageConfig<T> & Partial<SystemMessageConfig<T> & ToolsConfig<T>>;
28
171
  /**
29
172
  * A node that invokes an AI model and stores the response in the state.
30
- * Can be configured to either construct messages dynamically or read from state.
173
+ *
174
+ * ModelNode provides flexible configuration for:
175
+ * - Message sources: read from state or construct dynamically
176
+ * - Output handling: store in state key or transform via function
177
+ * - System messages: static or dynamic based on state/context
178
+ * - Tool definitions: static or dynamic (ignored for StructuredOutputWrapper)
179
+ *
180
+ * Supports both regular BaseModel instances (returns messages) and StructuredOutputWrapper
181
+ * instances (returns structured data matching a Zod schema).
31
182
  *
32
183
  * @class ModelNode
33
184
  * @template T - The state type
34
- * @implements {NodeLike<T, Partial<T>>}
185
+ * @template M - The model type (BaseModel or StructuredOutputWrapper), defaults to BaseModel
186
+ * @implements {NodeLike<T>}
35
187
  *
36
188
  * @example
37
189
  * ```typescript
38
- * // With messages from a function
190
+ * // Basic usage with messages from state
39
191
  * const node = new ModelNode(model, {
40
- * messages: (state, context) => [new UserMessage(state.input)],
192
+ * messages: "conversationMessages",
41
193
  * output: "modelResponse"
42
194
  * });
43
195
  *
44
- * // With messages from state
196
+ * // Dynamic message construction
45
197
  * const node = new ModelNode(model, {
46
- * messages: "conversationMessages",
198
+ * messages: (state, context) => [new UserMessage(state.input)],
47
199
  * output: "modelResponse"
48
200
  * });
201
+ *
202
+ * // With structured output
203
+ * const structuredModel = model.withStructuredOutput(z.object({
204
+ * name: z.string(),
205
+ * age: z.number()
206
+ * }));
207
+ * const node = new ModelNode(structuredModel, {
208
+ * messages: "userInput",
209
+ * output: "extractedData"
210
+ * });
211
+ *
212
+ * // Dynamic output transformation
213
+ * const node = new ModelNode(model, {
214
+ * messages: "messages",
215
+ * output: (response, state, context) => ({
216
+ * modelResponse: response.messages,
217
+ * tokenUsage: response.usage,
218
+ * timestamp: Date.now()
219
+ * })
220
+ * });
49
221
  * ```
50
222
  */
51
- export declare class ModelNode<T extends Record<string, unknown>> implements NodeLike<T> {
223
+ export declare class ModelNode<T extends Record<string, unknown>, M extends BaseModel | StructuredOutputWrapper<any> = BaseModel> implements NodeLike<T> {
52
224
  private readonly model;
53
- private readonly settings;
225
+ private readonly config;
54
226
  /**
55
227
  * Creates a new model node.
56
228
  *
57
- * @param {BaseModel | StructuredOutputWrapper<any>} model - The model to invoke
58
- * @param {ModelNodeSettings<T>} settings - Configuration for message source and output location
229
+ * @param {M} model - The model to invoke (BaseModel or StructuredOutputWrapper)
230
+ * @param {ModelNodeConfig<T, M>} config - Configuration for messages, output, system message, and tools
59
231
  */
60
- constructor(model: BaseModel | StructuredOutputWrapper<any>, settings: ModelNodeSettings<T>);
232
+ constructor(model: M, config: ModelNodeConfig<T, M>);
61
233
  /**
62
234
  * Runs the model with configured messages and stores the response in state.
63
235
  *
236
+ * Execution flow:
237
+ * 1. Resolves messages from config (state key or function)
238
+ * 2. Applies system message if configured (static or dynamic)
239
+ * 3. Applies tools if configured and model is not StructuredOutputWrapper (static or dynamic)
240
+ * 4. Invokes the model with resolved messages
241
+ * 5. Transforms response based on output config (state key or function)
242
+ *
243
+ * For StructuredOutputWrapper: the response is the structured data directly.
244
+ * For BaseModel: the response contains messages array and usage information.
245
+ *
64
246
  * @param {T} state - The current state
65
247
  * @param {ContextLayer} context - The execution context
66
- * @returns {Promise<Partial<T>>} Partial state containing the model's response
67
- * @throws {Error} If messages path is specified but not found in state
248
+ * @returns {Promise<Partial<T>>} Partial state update containing the model's response
249
+ * @throws {Error} If messages key is specified but not found in state, or if the value is not an array
68
250
  */
69
251
  run(state: T, context: ContextLayer): Promise<Partial<T>>;
70
252
  }
@@ -1 +1 @@
1
- {"version":3,"file":"model-node.d.ts","sourceRoot":"","sources":["../../src/nodes/model-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAcrC;;GAEG;AACH,KAAK,YAAY,CAAC,CAAC,IAAI,SAAS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