langchain 1.0.4 → 1.0.6

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 (108) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/agents/ReactAgent.cjs +56 -54
  3. package/dist/agents/ReactAgent.cjs.map +1 -1
  4. package/dist/agents/ReactAgent.d.cts +3 -3
  5. package/dist/agents/ReactAgent.d.cts.map +1 -1
  6. package/dist/agents/ReactAgent.d.ts +3 -3
  7. package/dist/agents/ReactAgent.d.ts.map +1 -1
  8. package/dist/agents/ReactAgent.js +58 -56
  9. package/dist/agents/ReactAgent.js.map +1 -1
  10. package/dist/agents/middleware/contextEditing.cjs +302 -33
  11. package/dist/agents/middleware/contextEditing.cjs.map +1 -1
  12. package/dist/agents/middleware/contextEditing.d.cts +125 -41
  13. package/dist/agents/middleware/contextEditing.d.cts.map +1 -1
  14. package/dist/agents/middleware/contextEditing.d.ts +125 -41
  15. package/dist/agents/middleware/contextEditing.d.ts.map +1 -1
  16. package/dist/agents/middleware/contextEditing.js +302 -33
  17. package/dist/agents/middleware/contextEditing.js.map +1 -1
  18. package/dist/agents/middleware/dynamicSystemPrompt.d.cts.map +1 -1
  19. package/dist/agents/middleware/dynamicSystemPrompt.d.ts.map +1 -1
  20. package/dist/agents/middleware/hitl.d.cts.map +1 -1
  21. package/dist/agents/middleware/hitl.d.ts.map +1 -1
  22. package/dist/agents/middleware/index.cjs +2 -0
  23. package/dist/agents/middleware/index.js +2 -0
  24. package/dist/agents/middleware/llmToolSelector.d.cts +4 -4
  25. package/dist/agents/middleware/llmToolSelector.d.cts.map +1 -1
  26. package/dist/agents/middleware/modelCallLimit.cjs +6 -2
  27. package/dist/agents/middleware/modelCallLimit.cjs.map +1 -1
  28. package/dist/agents/middleware/modelCallLimit.d.cts +8 -8
  29. package/dist/agents/middleware/modelCallLimit.d.cts.map +1 -1
  30. package/dist/agents/middleware/modelCallLimit.d.ts +8 -8
  31. package/dist/agents/middleware/modelCallLimit.d.ts.map +1 -1
  32. package/dist/agents/middleware/modelCallLimit.js +6 -2
  33. package/dist/agents/middleware/modelCallLimit.js.map +1 -1
  34. package/dist/agents/middleware/modelFallback.cjs +2 -2
  35. package/dist/agents/middleware/modelFallback.cjs.map +1 -1
  36. package/dist/agents/middleware/modelFallback.d.cts +2 -2
  37. package/dist/agents/middleware/modelFallback.d.cts.map +1 -1
  38. package/dist/agents/middleware/modelFallback.d.ts +2 -2
  39. package/dist/agents/middleware/modelFallback.d.ts.map +1 -1
  40. package/dist/agents/middleware/modelFallback.js +2 -2
  41. package/dist/agents/middleware/modelFallback.js.map +1 -1
  42. package/dist/agents/middleware/pii.cjs +445 -0
  43. package/dist/agents/middleware/pii.cjs.map +1 -0
  44. package/dist/agents/middleware/pii.d.cts +216 -0
  45. package/dist/agents/middleware/pii.d.cts.map +1 -0
  46. package/dist/agents/middleware/pii.d.ts +216 -0
  47. package/dist/agents/middleware/pii.d.ts.map +1 -0
  48. package/dist/agents/middleware/pii.js +436 -0
  49. package/dist/agents/middleware/pii.js.map +1 -0
  50. package/dist/agents/middleware/piiRedaction.cjs +2 -1
  51. package/dist/agents/middleware/piiRedaction.cjs.map +1 -1
  52. package/dist/agents/middleware/piiRedaction.d.cts +4 -1
  53. package/dist/agents/middleware/piiRedaction.d.cts.map +1 -1
  54. package/dist/agents/middleware/piiRedaction.d.ts +4 -1
  55. package/dist/agents/middleware/piiRedaction.d.ts.map +1 -1
  56. package/dist/agents/middleware/piiRedaction.js +2 -1
  57. package/dist/agents/middleware/piiRedaction.js.map +1 -1
  58. package/dist/agents/middleware/promptCaching.d.cts.map +1 -1
  59. package/dist/agents/middleware/promptCaching.d.ts.map +1 -1
  60. package/dist/agents/middleware/summarization.cjs +15 -24
  61. package/dist/agents/middleware/summarization.cjs.map +1 -1
  62. package/dist/agents/middleware/summarization.d.cts +72 -9
  63. package/dist/agents/middleware/summarization.d.cts.map +1 -1
  64. package/dist/agents/middleware/summarization.d.ts +65 -2
  65. package/dist/agents/middleware/summarization.d.ts.map +1 -1
  66. package/dist/agents/middleware/summarization.js +13 -25
  67. package/dist/agents/middleware/summarization.js.map +1 -1
  68. package/dist/agents/middleware/todoListMiddleware.d.cts.map +1 -1
  69. package/dist/agents/middleware/todoListMiddleware.d.ts.map +1 -1
  70. package/dist/agents/middleware/toolCallLimit.d.cts.map +1 -1
  71. package/dist/agents/middleware/toolCallLimit.d.ts.map +1 -1
  72. package/dist/agents/middleware/toolEmulator.cjs +118 -0
  73. package/dist/agents/middleware/toolEmulator.cjs.map +1 -0
  74. package/dist/agents/middleware/toolEmulator.d.cts +76 -0
  75. package/dist/agents/middleware/toolEmulator.d.cts.map +1 -0
  76. package/dist/agents/middleware/toolEmulator.d.ts +76 -0
  77. package/dist/agents/middleware/toolEmulator.d.ts.map +1 -0
  78. package/dist/agents/middleware/toolEmulator.js +117 -0
  79. package/dist/agents/middleware/toolEmulator.js.map +1 -0
  80. package/dist/agents/middleware/utils.cjs +4 -0
  81. package/dist/agents/middleware/utils.cjs.map +1 -1
  82. package/dist/agents/middleware/utils.d.cts.map +1 -1
  83. package/dist/agents/middleware/utils.d.ts.map +1 -1
  84. package/dist/agents/middleware/utils.js +4 -0
  85. package/dist/agents/middleware/utils.js.map +1 -1
  86. package/dist/agents/nodes/AgentNode.cjs +23 -7
  87. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  88. package/dist/agents/nodes/AgentNode.js +23 -8
  89. package/dist/agents/nodes/AgentNode.js.map +1 -1
  90. package/dist/agents/nodes/ToolNode.cjs +5 -0
  91. package/dist/agents/nodes/ToolNode.cjs.map +1 -1
  92. package/dist/agents/nodes/ToolNode.js +5 -1
  93. package/dist/agents/nodes/ToolNode.js.map +1 -1
  94. package/dist/agents/responses.cjs.map +1 -1
  95. package/dist/agents/responses.d.cts +2 -0
  96. package/dist/agents/responses.d.cts.map +1 -1
  97. package/dist/agents/responses.d.ts +2 -0
  98. package/dist/agents/responses.d.ts.map +1 -1
  99. package/dist/agents/responses.js.map +1 -1
  100. package/dist/agents/runtime.d.cts +5 -5
  101. package/dist/agents/runtime.d.cts.map +1 -1
  102. package/dist/agents/runtime.d.ts +5 -5
  103. package/dist/agents/runtime.d.ts.map +1 -1
  104. package/dist/index.cjs +22 -0
  105. package/dist/index.d.cts +5 -3
  106. package/dist/index.d.ts +5 -3
  107. package/dist/index.js +13 -1
  108. package/package.json +9 -8
@@ -6,7 +6,7 @@ import { Runnable, RunnableConfig } from "@langchain/core/runnables";
6
6
  import { IterableReadableStream } from "@langchain/core/utils/stream";
7
7
  import { StreamEvent } from "@langchain/core/tracers/log_stream";
8
8
  import { InteropZodObject } from "@langchain/core/utils/types";
9
- import { Command, CompiledStateGraph, GetStateOptions, LangGraphRunnableConfig } from "@langchain/langgraph";
9
+ import { Command, CompiledStateGraph, GetStateOptions, LangGraphRunnableConfig, StreamMode, StreamOutputMap } from "@langchain/langgraph";
10
10
  import { CheckpointListOptions } from "@langchain/langgraph-checkpoint";
11
11
 
12
12
  //#region src/agents/ReactAgent.d.ts
@@ -111,7 +111,7 @@ declare class ReactAgent<StructuredResponseFormat extends Record<string, any> |
111
111
  * }
112
112
  * ```
113
113
  */
114
- stream(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<IterableReadableStream<any>>;
114
+ stream<TStreamMode extends StreamMode | StreamMode[] | undefined, TEncoding extends "text/event-stream" | undefined>(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, TStreamMode, TEncoding>): Promise<IterableReadableStream<StreamOutputMap<TStreamMode, false, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, string, unknown, unknown, TEncoding>>>;
115
115
  /**
116
116
  * Visualize the graph as a PNG image.
117
117
  * @param params - Parameters for the drawMermaidPng method.
@@ -155,7 +155,7 @@ declare class ReactAgent<StructuredResponseFormat extends Record<string, any> |
155
155
  /**
156
156
  * @internal
157
157
  */
158
- streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> & {
158
+ streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, StreamMode | StreamMode[] | undefined, "text/event-stream" | undefined> & {
159
159
  version?: "v1" | "v2";
160
160
  }, streamOptions?: Parameters<Runnable["streamEvents"]>[2]): IterableReadableStream<StreamEvent>;
161
161
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ReactAgent.d.cts","names":["InteropZodObject","Command","CompiledStateGraph","GetStateOptions","LangGraphRunnableConfig","CheckpointListOptions","IterableReadableStream","Runnable","RunnableConfig","StreamEvent","CreateAgentParams","BuiltInState","UserInput","InvokeConfiguration","StreamConfiguration","AgentMiddleware","InferMiddlewareContextInputs","InferMiddlewareStates","InferMiddlewareInputStates","InferContextInput","AnyAnnotationRoot","InferSchemaInput","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StateSchema","StructuredResponseFormat","Omit","TMiddleware","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array","Parameters"],"sources":["../../src/agents/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type GetStateOptions, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport type { CheckpointListOptions } from \"@langchain/langgraph-checkpoint\";\nimport { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport type { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nimport type { StreamEvent } from \"@langchain/core/tracers/log_stream\";\nimport type { CreateAgentParams, BuiltInState, UserInput } from \"./types.js\";\nimport type { InvokeConfiguration, StreamConfiguration } from \"./runtime.js\";\nimport type { AgentMiddleware, InferMiddlewareContextInputs, InferMiddlewareStates, InferMiddlewareInputStates, InferContextInput, AnyAnnotationRoot, InferSchemaInput, ToAnnotationRoot } from \"./middleware/types.js\";\nimport { type ResponseFormatUndefined } from \"./responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware[]> = InferSchemaInput<StateSchema> & (StructuredResponseFormat extends ResponseFormatUndefined ? Omit<BuiltInState, \"jumpTo\"> : Omit<BuiltInState, \"jumpTo\"> & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddleware>;\ntype InvokeStateParameter<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, TMiddleware extends readonly AgentMiddleware[]> = (UserInput<StateSchema> & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;\ntype AgentGraph<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[]> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>);\n /**\n * Get the compiled {@link https://docs.langchain.com/oss/javascript/langgraph/use-graph-api | StateGraph}.\n */\n get graph(): AgentGraph<StateSchema, StructuredResponseFormat, ContextSchema, TMiddleware>;\n /**\n * Executes the agent with the given state and returns the final state after all processing.\n *\n * This method runs the agent's entire workflow synchronously, including:\n * - Processing the input messages through any configured middleware\n * - Calling the language model to generate responses\n * - Executing any tool calls made by the model\n * - Running all middleware hooks (beforeModel, afterModel, etc.)\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to the final agent state after execution completes.\n * The returned state includes:\n * - a `messages` property containing an array with all messages (input, AI responses, tool calls/results)\n * - a `structuredResponse` property containing the structured response (if configured)\n * - all state values defined in the middleware\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch],\n * responseFormat: z.object({\n * weather: z.string(),\n * }),\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"human\", content: \"What's the weather in Paris?\" }]\n * });\n *\n * console.log(result.structuredResponse.weather); // outputs: \"It's sunny and 75°F.\"\n * ```\n */\n invoke(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: InvokeConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>>;\n /**\n * Executes the agent with streaming, returning an async iterable of state updates as they occur.\n *\n * This method runs the agent's workflow similar to `invoke`, but instead of waiting for\n * completion, it streams high-level state updates in real-time. This allows you to:\n * - Display intermediate results to users as they're generated\n * - Monitor the agent's progress through each step\n * - React to state changes as nodes complete\n *\n * For more granular event-level streaming (like individual LLM tokens), use `streamEvents` instead.\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.streamMode - The streaming mode for the agent execution, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/streaming#supported-stream-modes | Supported stream modes}.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to an IterableReadableStream of state updates.\n * Each update contains the current state after a node completes.\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch]\n * });\n *\n * const stream = await agent.stream({\n * messages: [{ role: \"human\", content: \"What's 2+2 and the weather in NYC?\" }]\n * });\n *\n * for await (const chunk of stream) {\n * console.log(chunk); // State update from each node\n * }\n * ```\n */\n stream(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<IterableReadableStream<any>>;\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n /**\n * The following are internal methods to enable support for LangGraph Platform.\n * They are not part of the createAgent public API.\n *\n * Note: we intentionally return as `never` to avoid type errors due to type inference.\n */\n /**\n * @internal\n */\n streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> & {\n version?: \"v1\" | \"v2\";\n }, streamOptions?: Parameters<Runnable[\"streamEvents\"]>[2]): IterableReadableStream<StreamEvent>;\n /**\n * @internal\n */\n getGraphAsync(config?: RunnableConfig): never;\n /**\n * @internal\n */\n getState(config: RunnableConfig, options?: GetStateOptions): never;\n /**\n * @internal\n */\n getStateHistory(config: RunnableConfig, options?: CheckpointListOptions): never;\n /**\n * @internal\n */\n getSubgraphs(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n getSubgraphAsync(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n updateState(inputConfig: LangGraphRunnableConfig, values: Record<string, unknown> | unknown, asNode?: string): never;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;;;AAW8D;KAEzDwB,gBAAgB,CAAA,oBAAqBJ,iBAArB,GAAyCpB,gBAAzC,GAAA,SAAA,EAAA,iCAAwGyB,MAAxG,CAAA,MA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mB7B,CAAAA,CAAAA;EAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+GxP,MAAlBkC,CAAAA,KAAAA,EAjBUJ,oBAiBVI,CAjB+BR,WAiB/BQ,EAjB4CL,WAiB5CK,CAAAA,EAAAA,MAAAA,CAAAA,EAjBmEpB,mBAiBnEoB,CAjBuFf,iBAiBvFe,CAjByGF,aAiBzGE,CAAAA,GAjB0HlB,4BAiB1HkB,CAjBuJL,WAiBvJK,CAAAA,CAAAA,CAAAA,EAjBuKA,OAiBvKA,CAjB+K5B,sBAiB/K4B,CAAAA,GAAAA,CAAAA,CAAAA;EAAO;;;;;;;;;;EA2BqF,cAElE3B,CAAAA,MAQC,CARDA,EAAAA;IAAX8B,UAAAA,CAAAA,EAAAA,OAAAA;IAAiE5B,UAAAA,CAAAA,EAAAA,MAAAA;IAAvBH,UAAAA,CAAAA,EAhC5CmB,MAgC4CnB,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAItCE,eAAAA,CAAAA,EAAAA,MAAAA;IAINA,eAAAA,CAAAA,EAAAA,MAAAA;EAAc,CAAA,CAAA,EArC3B0B,OAqCuC/B,CArC/BiC,UAqC+BjC,CArCpBgC,WAqCoBhC,CAAAA,CAAAA;EAAe;;;;AAgBM;;;;;;;;;iBAvC/CsB;;;MAGbS;;;;;;;;;;sBAUgBJ,qBAAqBJ,aAAaG,uBAAuBf,oBAAoBK,kBAAkBa,iBAAiBhB,6BAA6Ba;;qBAE9IQ,WAAW9B,+BAA+BD,uBAAuBG;;;;yBAI7DD;;;;mBAINA,0BAA0BL;;;;0BAInBK,0BAA0BH;;;;;;;;;;;;2BAYzBD,iCAAiCqB"}
1
+ {"version":3,"file":"ReactAgent.d.cts","names":["InteropZodObject","Command","CompiledStateGraph","GetStateOptions","LangGraphRunnableConfig","StreamMode","StreamOutputMap","CheckpointListOptions","IterableReadableStream","Runnable","RunnableConfig","StreamEvent","CreateAgentParams","BuiltInState","UserInput","InvokeConfiguration","StreamConfiguration","AgentMiddleware","InferMiddlewareContextInputs","InferMiddlewareStates","InferMiddlewareInputStates","InferContextInput","AnyAnnotationRoot","InferSchemaInput","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StateSchema","StructuredResponseFormat","Omit","TMiddleware","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","TStreamMode","TEncoding","ArrayBuffer","Uint8Array","Parameters"],"sources":["../../src/agents/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type GetStateOptions, type LangGraphRunnableConfig, type StreamMode, type StreamOutputMap } from \"@langchain/langgraph\";\nimport type { CheckpointListOptions } from \"@langchain/langgraph-checkpoint\";\nimport { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport type { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nimport type { StreamEvent } from \"@langchain/core/tracers/log_stream\";\nimport type { CreateAgentParams, BuiltInState, UserInput } from \"./types.js\";\nimport type { InvokeConfiguration, StreamConfiguration } from \"./runtime.js\";\nimport type { AgentMiddleware, InferMiddlewareContextInputs, InferMiddlewareStates, InferMiddlewareInputStates, InferContextInput, AnyAnnotationRoot, InferSchemaInput, ToAnnotationRoot } from \"./middleware/types.js\";\nimport { type ResponseFormatUndefined } from \"./responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware[]> = InferSchemaInput<StateSchema> & (StructuredResponseFormat extends ResponseFormatUndefined ? Omit<BuiltInState, \"jumpTo\"> : Omit<BuiltInState, \"jumpTo\"> & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddleware>;\ntype InvokeStateParameter<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, TMiddleware extends readonly AgentMiddleware[]> = (UserInput<StateSchema> & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;\ntype AgentGraph<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[]> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>);\n /**\n * Get the compiled {@link https://docs.langchain.com/oss/javascript/langgraph/use-graph-api | StateGraph}.\n */\n get graph(): AgentGraph<StateSchema, StructuredResponseFormat, ContextSchema, TMiddleware>;\n /**\n * Executes the agent with the given state and returns the final state after all processing.\n *\n * This method runs the agent's entire workflow synchronously, including:\n * - Processing the input messages through any configured middleware\n * - Calling the language model to generate responses\n * - Executing any tool calls made by the model\n * - Running all middleware hooks (beforeModel, afterModel, etc.)\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to the final agent state after execution completes.\n * The returned state includes:\n * - a `messages` property containing an array with all messages (input, AI responses, tool calls/results)\n * - a `structuredResponse` property containing the structured response (if configured)\n * - all state values defined in the middleware\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch],\n * responseFormat: z.object({\n * weather: z.string(),\n * }),\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"human\", content: \"What's the weather in Paris?\" }]\n * });\n *\n * console.log(result.structuredResponse.weather); // outputs: \"It's sunny and 75°F.\"\n * ```\n */\n invoke(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: InvokeConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>>;\n /**\n * Executes the agent with streaming, returning an async iterable of state updates as they occur.\n *\n * This method runs the agent's workflow similar to `invoke`, but instead of waiting for\n * completion, it streams high-level state updates in real-time. This allows you to:\n * - Display intermediate results to users as they're generated\n * - Monitor the agent's progress through each step\n * - React to state changes as nodes complete\n *\n * For more granular event-level streaming (like individual LLM tokens), use `streamEvents` instead.\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.streamMode - The streaming mode for the agent execution, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/streaming#supported-stream-modes | Supported stream modes}.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to an IterableReadableStream of state updates.\n * Each update contains the current state after a node completes.\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch]\n * });\n *\n * const stream = await agent.stream({\n * messages: [{ role: \"human\", content: \"What's 2+2 and the weather in NYC?\" }]\n * });\n *\n * for await (const chunk of stream) {\n * console.log(chunk); // State update from each node\n * }\n * ```\n */\n stream<TStreamMode extends StreamMode | StreamMode[] | undefined, TEncoding extends \"text/event-stream\" | undefined>(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, TStreamMode, TEncoding>): Promise<IterableReadableStream<StreamOutputMap<TStreamMode, false, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, string, unknown, unknown, TEncoding>>>;\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n /**\n * The following are internal methods to enable support for LangGraph Platform.\n * They are not part of the createAgent public API.\n *\n * Note: we intentionally return as `never` to avoid type errors due to type inference.\n */\n /**\n * @internal\n */\n streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, StreamMode | StreamMode[] | undefined, \"text/event-stream\" | undefined> & {\n version?: \"v1\" | \"v2\";\n }, streamOptions?: Parameters<Runnable[\"streamEvents\"]>[2]): IterableReadableStream<StreamEvent>;\n /**\n * @internal\n */\n getGraphAsync(config?: RunnableConfig): never;\n /**\n * @internal\n */\n getState(config: RunnableConfig, options?: GetStateOptions): never;\n /**\n * @internal\n */\n getStateHistory(config: RunnableConfig, options?: CheckpointListOptions): never;\n /**\n * @internal\n */\n getSubgraphs(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n getSubgraphAsync(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n updateState(inputConfig: LangGraphRunnableConfig, values: Record<string, unknown> | unknown, asNode?: string): never;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;;;AAW8D;KAEzD0B,gBAAgB,CAAA,oBAAqBJ,iBAArB,GAAyCtB,gBAAzC,GAAA,SAAA,EAAA,iCAAwG2B,MAAxG,CAAA,MAAA,EAAA,GAAA,CAAA,GAA8HF,uBAA9H,EAAA,oBAAA,SAAoLR,eAApL,EAAA,CAAA,GAAyMM,gBAAzM,CAA0NK,WAA1N,CAAA,GAAA,CAA0OC,wBAA1O,SAA2QJ,uBAA3Q,GAAqSK,IAArS,CAA0SjB,YAA1S,EAAA,QAAA,CAAA,GAAoUiB,IAApU,CAAyUjB,YAAzU,EAAA,QAAA,CAAA,GAAA;EAAA,kBAAqBS,EAClBO,wBADkBP;CAAiB,CAAA,GAEtDH,qBAFyDnB,CAEnC+B,WAF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hB,6BAA6Ba,cAAc1B,aAAaA;;qBAEzKoC,WAAWhC,+BAA+BD,uBAAuBG;;;;yBAI7DD;;;;mBAINA,0BAA0BP;;;;0BAInBO,0BAA0BH;;;;;;;;;;;;2BAYzBH,iCAAiCuB"}
@@ -4,7 +4,7 @@ import { AgentMiddleware, AnyAnnotationRoot, InferContextInput, InferMiddlewareC
4
4
  import { BuiltInState, CreateAgentParams, UserInput } from "./types.js";
5
5
  import { Runnable, RunnableConfig } from "@langchain/core/runnables";
6
6
  import { IterableReadableStream } from "@langchain/core/utils/stream";
7
- import { Command, CompiledStateGraph, GetStateOptions, LangGraphRunnableConfig } from "@langchain/langgraph";
7
+ import { Command, CompiledStateGraph, GetStateOptions, LangGraphRunnableConfig, StreamMode, StreamOutputMap } from "@langchain/langgraph";
8
8
  import { InteropZodObject } from "@langchain/core/utils/types";
9
9
  import { CheckpointListOptions } from "@langchain/langgraph-checkpoint";
10
10
  import { StreamEvent } from "@langchain/core/tracers/log_stream";
@@ -111,7 +111,7 @@ declare class ReactAgent<StructuredResponseFormat extends Record<string, any> |
111
111
  * }
112
112
  * ```
113
113
  */
114
- stream(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<IterableReadableStream<any>>;
114
+ stream<TStreamMode extends StreamMode | StreamMode[] | undefined, TEncoding extends "text/event-stream" | undefined>(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, TStreamMode, TEncoding>): Promise<IterableReadableStream<StreamOutputMap<TStreamMode, false, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, string, unknown, unknown, TEncoding>>>;
115
115
  /**
116
116
  * Visualize the graph as a PNG image.
117
117
  * @param params - Parameters for the drawMermaidPng method.
@@ -155,7 +155,7 @@ declare class ReactAgent<StructuredResponseFormat extends Record<string, any> |
155
155
  /**
156
156
  * @internal
157
157
  */
158
- streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> & {
158
+ streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, StreamMode | StreamMode[] | undefined, "text/event-stream" | undefined> & {
159
159
  version?: "v1" | "v2";
160
160
  }, streamOptions?: Parameters<Runnable["streamEvents"]>[2]): IterableReadableStream<StreamEvent>;
161
161
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ReactAgent.d.ts","names":["InteropZodObject","Command","CompiledStateGraph","GetStateOptions","LangGraphRunnableConfig","CheckpointListOptions","IterableReadableStream","Runnable","RunnableConfig","StreamEvent","CreateAgentParams","BuiltInState","UserInput","InvokeConfiguration","StreamConfiguration","AgentMiddleware","InferMiddlewareContextInputs","InferMiddlewareStates","InferMiddlewareInputStates","InferContextInput","AnyAnnotationRoot","InferSchemaInput","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StateSchema","StructuredResponseFormat","Omit","TMiddleware","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array","Parameters"],"sources":["../../src/agents/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type GetStateOptions, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport type { CheckpointListOptions } from \"@langchain/langgraph-checkpoint\";\nimport { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport type { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nimport type { StreamEvent } from \"@langchain/core/tracers/log_stream\";\nimport type { CreateAgentParams, BuiltInState, UserInput } from \"./types.js\";\nimport type { InvokeConfiguration, StreamConfiguration } from \"./runtime.js\";\nimport type { AgentMiddleware, InferMiddlewareContextInputs, InferMiddlewareStates, InferMiddlewareInputStates, InferContextInput, AnyAnnotationRoot, InferSchemaInput, ToAnnotationRoot } from \"./middleware/types.js\";\nimport { type ResponseFormatUndefined } from \"./responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware[]> = InferSchemaInput<StateSchema> & (StructuredResponseFormat extends ResponseFormatUndefined ? Omit<BuiltInState, \"jumpTo\"> : Omit<BuiltInState, \"jumpTo\"> & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddleware>;\ntype InvokeStateParameter<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, TMiddleware extends readonly AgentMiddleware[]> = (UserInput<StateSchema> & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;\ntype AgentGraph<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[]> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>);\n /**\n * Get the compiled {@link https://docs.langchain.com/oss/javascript/langgraph/use-graph-api | StateGraph}.\n */\n get graph(): AgentGraph<StateSchema, StructuredResponseFormat, ContextSchema, TMiddleware>;\n /**\n * Executes the agent with the given state and returns the final state after all processing.\n *\n * This method runs the agent's entire workflow synchronously, including:\n * - Processing the input messages through any configured middleware\n * - Calling the language model to generate responses\n * - Executing any tool calls made by the model\n * - Running all middleware hooks (beforeModel, afterModel, etc.)\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to the final agent state after execution completes.\n * The returned state includes:\n * - a `messages` property containing an array with all messages (input, AI responses, tool calls/results)\n * - a `structuredResponse` property containing the structured response (if configured)\n * - all state values defined in the middleware\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch],\n * responseFormat: z.object({\n * weather: z.string(),\n * }),\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"human\", content: \"What's the weather in Paris?\" }]\n * });\n *\n * console.log(result.structuredResponse.weather); // outputs: \"It's sunny and 75°F.\"\n * ```\n */\n invoke(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: InvokeConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>>;\n /**\n * Executes the agent with streaming, returning an async iterable of state updates as they occur.\n *\n * This method runs the agent's workflow similar to `invoke`, but instead of waiting for\n * completion, it streams high-level state updates in real-time. This allows you to:\n * - Display intermediate results to users as they're generated\n * - Monitor the agent's progress through each step\n * - React to state changes as nodes complete\n *\n * For more granular event-level streaming (like individual LLM tokens), use `streamEvents` instead.\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.streamMode - The streaming mode for the agent execution, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/streaming#supported-stream-modes | Supported stream modes}.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to an IterableReadableStream of state updates.\n * Each update contains the current state after a node completes.\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch]\n * });\n *\n * const stream = await agent.stream({\n * messages: [{ role: \"human\", content: \"What's 2+2 and the weather in NYC?\" }]\n * });\n *\n * for await (const chunk of stream) {\n * console.log(chunk); // State update from each node\n * }\n * ```\n */\n stream(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<IterableReadableStream<any>>;\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n /**\n * The following are internal methods to enable support for LangGraph Platform.\n * They are not part of the createAgent public API.\n *\n * Note: we intentionally return as `never` to avoid type errors due to type inference.\n */\n /**\n * @internal\n */\n streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> & {\n version?: \"v1\" | \"v2\";\n }, streamOptions?: Parameters<Runnable[\"streamEvents\"]>[2]): IterableReadableStream<StreamEvent>;\n /**\n * @internal\n */\n getGraphAsync(config?: RunnableConfig): never;\n /**\n * @internal\n */\n getState(config: RunnableConfig, options?: GetStateOptions): never;\n /**\n * @internal\n */\n getStateHistory(config: RunnableConfig, options?: CheckpointListOptions): never;\n /**\n * @internal\n */\n getSubgraphs(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n getSubgraphAsync(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n updateState(inputConfig: LangGraphRunnableConfig, values: Record<string, unknown> | unknown, asNode?: string): never;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;;;AAW8D;KAEzDwB,gBAAgB,CAAA,oBAAqBJ,iBAArB,GAAyCpB,gBAAzC,GAAA,SAAA,EAAA,iCAAwGyB,MAAxG,CAAA,MAAA,EAAA,GAAA,CAAA,GAA8HF,uBAA9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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+GxP,MAAlBkC,CAAAA,KAAAA,EAjBUJ,oBAiBVI,CAjB+BR,WAiB/BQ,EAjB4CL,WAiB5CK,CAAAA,EAAAA,MAAAA,CAAAA,EAjBmEpB,mBAiBnEoB,CAjBuFf,iBAiBvFe,CAjByGF,aAiBzGE,CAAAA,GAjB0HlB,4BAiB1HkB,CAjBuJL,WAiBvJK,CAAAA,CAAAA,CAAAA,EAjBuKA,OAiBvKA,CAjB+K5B,sBAiB/K4B,CAAAA,GAAAA,CAAAA,CAAAA;EAAO;;;;;;;;;;EA2BqF,cAElE3B,CAAAA,MAQC,CARDA,EAAAA;IAAX8B,UAAAA,CAAAA,EAAAA,OAAAA;IAAiE5B,UAAAA,CAAAA,EAAAA,MAAAA;IAAvBH,UAAAA,CAAAA,EAhC5CmB,MAgC4CnB,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAItCE,eAAAA,CAAAA,EAAAA,MAAAA;IAINA,eAAAA,CAAAA,EAAAA,MAAAA;EAAc,CAAA,CAAA,EArC3B0B,OAqCuC/B,CArC/BiC,UAqC+BjC,CArCpBgC,WAqCoBhC,CAAAA,CAAAA;EAAe;;;;AAgBM;;;;;;;;;iBAvC/CsB;;;MAGbS;;;;;;;;;;sBAUgBJ,qBAAqBJ,aAAaG,uBAAuBf,oBAAoBK,kBAAkBa,iBAAiBhB,6BAA6Ba;;qBAE9IQ,WAAW9B,+BAA+BD,uBAAuBG;;;;yBAI7DD;;;;mBAINA,0BAA0BL;;;;0BAInBK,0BAA0BH;;;;;;;;;;;;2BAYzBD,iCAAiCqB"}
1
+ {"version":3,"file":"ReactAgent.d.ts","names":["InteropZodObject","Command","CompiledStateGraph","GetStateOptions","LangGraphRunnableConfig","StreamMode","StreamOutputMap","CheckpointListOptions","IterableReadableStream","Runnable","RunnableConfig","StreamEvent","CreateAgentParams","BuiltInState","UserInput","InvokeConfiguration","StreamConfiguration","AgentMiddleware","InferMiddlewareContextInputs","InferMiddlewareStates","InferMiddlewareInputStates","InferContextInput","AnyAnnotationRoot","InferSchemaInput","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StateSchema","StructuredResponseFormat","Omit","TMiddleware","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","TStreamMode","TEncoding","ArrayBuffer","Uint8Array","Parameters"],"sources":["../../src/agents/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type GetStateOptions, type LangGraphRunnableConfig, type StreamMode, type StreamOutputMap } from \"@langchain/langgraph\";\nimport type { CheckpointListOptions } from \"@langchain/langgraph-checkpoint\";\nimport { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport type { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nimport type { StreamEvent } from \"@langchain/core/tracers/log_stream\";\nimport type { CreateAgentParams, BuiltInState, UserInput } from \"./types.js\";\nimport type { InvokeConfiguration, StreamConfiguration } from \"./runtime.js\";\nimport type { AgentMiddleware, InferMiddlewareContextInputs, InferMiddlewareStates, InferMiddlewareInputStates, InferContextInput, AnyAnnotationRoot, InferSchemaInput, ToAnnotationRoot } from \"./middleware/types.js\";\nimport { type ResponseFormatUndefined } from \"./responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware[]> = InferSchemaInput<StateSchema> & (StructuredResponseFormat extends ResponseFormatUndefined ? Omit<BuiltInState, \"jumpTo\"> : Omit<BuiltInState, \"jumpTo\"> & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddleware>;\ntype InvokeStateParameter<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined, TMiddleware extends readonly AgentMiddleware[]> = (UserInput<StateSchema> & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;\ntype AgentGraph<StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, StateSchema extends AnyAnnotationRoot | InteropZodObject | undefined = undefined, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[]> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, StateSchema, ContextSchema>);\n /**\n * Get the compiled {@link https://docs.langchain.com/oss/javascript/langgraph/use-graph-api | StateGraph}.\n */\n get graph(): AgentGraph<StateSchema, StructuredResponseFormat, ContextSchema, TMiddleware>;\n /**\n * Executes the agent with the given state and returns the final state after all processing.\n *\n * This method runs the agent's entire workflow synchronously, including:\n * - Processing the input messages through any configured middleware\n * - Calling the language model to generate responses\n * - Executing any tool calls made by the model\n * - Running all middleware hooks (beforeModel, afterModel, etc.)\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to the final agent state after execution completes.\n * The returned state includes:\n * - a `messages` property containing an array with all messages (input, AI responses, tool calls/results)\n * - a `structuredResponse` property containing the structured response (if configured)\n * - all state values defined in the middleware\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch],\n * responseFormat: z.object({\n * weather: z.string(),\n * }),\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"human\", content: \"What's the weather in Paris?\" }]\n * });\n *\n * console.log(result.structuredResponse.weather); // outputs: \"It's sunny and 75°F.\"\n * ```\n */\n invoke(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: InvokeConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>>): Promise<MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>>;\n /**\n * Executes the agent with streaming, returning an async iterable of state updates as they occur.\n *\n * This method runs the agent's workflow similar to `invoke`, but instead of waiting for\n * completion, it streams high-level state updates in real-time. This allows you to:\n * - Display intermediate results to users as they're generated\n * - Monitor the agent's progress through each step\n * - React to state changes as nodes complete\n *\n * For more granular event-level streaming (like individual LLM tokens), use `streamEvents` instead.\n *\n * @param state - The initial state for the agent execution. Can be:\n * - An object containing `messages` array and any middleware-specific state properties\n * - A Command object for more advanced control flow\n *\n * @param config - Optional runtime configuration including:\n * @param config.context - The context for the agent execution.\n * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.\n * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.\n * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.\n * @param config.streamMode - The streaming mode for the agent execution, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/streaming#supported-stream-modes | Supported stream modes}.\n * @param config.recursionLimit - The recursion limit for the agent execution.\n *\n * @returns A Promise that resolves to an IterableReadableStream of state updates.\n * Each update contains the current state after a node completes.\n *\n * @example\n * ```typescript\n * const agent = new ReactAgent({\n * llm: myModel,\n * tools: [calculator, webSearch]\n * });\n *\n * const stream = await agent.stream({\n * messages: [{ role: \"human\", content: \"What's 2+2 and the weather in NYC?\" }]\n * });\n *\n * for await (const chunk of stream) {\n * console.log(chunk); // State update from each node\n * }\n * ```\n */\n stream<TStreamMode extends StreamMode | StreamMode[] | undefined, TEncoding extends \"text/event-stream\" | undefined>(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, TStreamMode, TEncoding>): Promise<IterableReadableStream<StreamOutputMap<TStreamMode, false, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, MergedAgentState<StateSchema, StructuredResponseFormat, TMiddleware>, string, unknown, unknown, TEncoding>>>;\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n /**\n * The following are internal methods to enable support for LangGraph Platform.\n * They are not part of the createAgent public API.\n *\n * Note: we intentionally return as `never` to avoid type errors due to type inference.\n */\n /**\n * @internal\n */\n streamEvents(state: InvokeStateParameter<StateSchema, TMiddleware>, config?: StreamConfiguration<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>, StreamMode | StreamMode[] | undefined, \"text/event-stream\" | undefined> & {\n version?: \"v1\" | \"v2\";\n }, streamOptions?: Parameters<Runnable[\"streamEvents\"]>[2]): IterableReadableStream<StreamEvent>;\n /**\n * @internal\n */\n getGraphAsync(config?: RunnableConfig): never;\n /**\n * @internal\n */\n getState(config: RunnableConfig, options?: GetStateOptions): never;\n /**\n * @internal\n */\n getStateHistory(config: RunnableConfig, options?: CheckpointListOptions): never;\n /**\n * @internal\n */\n getSubgraphs(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n getSubgraphAsync(namespace?: string, recurse?: boolean): never;\n /**\n * @internal\n */\n updateState(inputConfig: LangGraphRunnableConfig, values: Record<string, unknown> | unknown, asNode?: string): never;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;;;AAW8D;KAEzD0B,gBAAgB,CAAA,oBAAqBJ,iBAArB,GAAyCtB,gBAAzC,GAAA,SAAA,EAAA,iCAAwG2B,MAAxG,CAAA,MAAA,EAAA,GAAA,CAAA,GAA8HF,uBAA9H,EAAA,oBAAA,SAAoLR,eAApL,EAAA,CAAA,GAAyMM,gBAAzM,CAA0NK,WAA1N,CAAA,GAAA,CAA0OC,wBAA1O,SAA2QJ,uBAA3Q,GAAqSK,IAArS,CAA0SjB,YAA1S,EAAA,QAAA,CAAA,GAAoUiB,IAApU,CAAyUjB,YAAzU,EAAA,QAAA,CAAA,GAAA;EAAA,kBAAqBS,EAClBO,wBADkBP;CAAiB,CAAA,GAEtDH,qBAFyDnB,CAEnC+B,WAFmC/B,CAAAA;KAGzDgC,oBAHwHL,CAA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zKoC,WAAWhC,+BAA+BD,uBAAuBG;;;;yBAI7DD;;;;mBAINA,0BAA0BP;;;;0BAInBO,0BAA0BH;;;;;;;;;;;;2BAYzBH,iCAAiCuB"}
@@ -1,8 +1,8 @@
1
1
  import { createAgentAnnotationConditional } from "./annotation.js";
2
2
  import { isClientTool, validateLLMHasNoBoundTools, wrapToolCall } from "./utils.js";
3
3
  import { initializeMiddlewareStates, parseJumpToTarget } from "./nodes/utils.js";
4
- import { AgentNode } from "./nodes/AgentNode.js";
5
- import { ToolNode } from "./nodes/ToolNode.js";
4
+ import { AGENT_NODE_NAME, AgentNode } from "./nodes/AgentNode.js";
5
+ import { TOOLS_NODE_NAME, ToolNode } from "./nodes/ToolNode.js";
6
6
  import { getHookConstraint } from "./middleware/utils.js";
7
7
  import { BeforeAgentNode } from "./nodes/BeforeAgentNode.js";
8
8
  import { BeforeModelNode } from "./nodes/BeforeModelNode.js";
@@ -122,7 +122,7 @@ var ReactAgent = class {
122
122
  /**
123
123
  * Add Nodes
124
124
  */
125
- allNodeWorkflows.addNode("model_request", this.#agentNode);
125
+ allNodeWorkflows.addNode(AGENT_NODE_NAME, this.#agentNode);
126
126
  /**
127
127
  * add single tool node for all tools
128
128
  */
@@ -131,7 +131,7 @@ var ReactAgent = class {
131
131
  signal: this.options.signal,
132
132
  wrapToolCall: wrapToolCall(middleware)
133
133
  });
134
- allNodeWorkflows.addNode("tools", toolNode);
134
+ allNodeWorkflows.addNode(TOOLS_NODE_NAME, toolNode);
135
135
  }
136
136
  /**
137
137
  * Add Edges
@@ -139,93 +139,94 @@ var ReactAgent = class {
139
139
  let entryNode;
140
140
  if (beforeAgentNodes.length > 0) entryNode = beforeAgentNodes[0].name;
141
141
  else if (beforeModelNodes.length > 0) entryNode = beforeModelNodes[0].name;
142
- else entryNode = "model_request";
143
- const loopEntryNode = beforeModelNodes.length > 0 ? beforeModelNodes[0].name : "model_request";
142
+ else entryNode = AGENT_NODE_NAME;
143
+ const loopEntryNode = beforeModelNodes.length > 0 ? beforeModelNodes[0].name : AGENT_NODE_NAME;
144
144
  const exitNode = afterAgentNodes.length > 0 ? afterAgentNodes[afterAgentNodes.length - 1].name : END;
145
145
  allNodeWorkflows.addEdge(START, entryNode);
146
+ const clientTools = toolClasses.filter(isClientTool);
146
147
  for (let i = 0; i < beforeAgentNodes.length; i++) {
147
148
  const node = beforeAgentNodes[i];
148
149
  const current = node.name;
149
150
  const isLast = i === beforeAgentNodes.length - 1;
150
151
  const nextDefault = isLast ? loopEntryNode : beforeAgentNodes[i + 1].name;
151
152
  if (node.allowed && node.allowed.length > 0) {
152
- const hasTools = toolClasses.filter(isClientTool).length > 0;
153
- const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
153
+ const hasTools = clientTools.length > 0;
154
+ const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== TOOLS_NODE_NAME || hasTools);
154
155
  const destinations = Array.from(new Set([nextDefault, ...allowedMapped.map((dest) => dest === END ? exitNode : dest)]));
155
- allNodeWorkflows.addConditionalEdges(current, this.#createBeforeAgentRouter(toolClasses.filter(isClientTool), nextDefault, exitNode), destinations);
156
+ allNodeWorkflows.addConditionalEdges(current, this.#createBeforeAgentRouter(clientTools, nextDefault, exitNode), destinations);
156
157
  } else allNodeWorkflows.addEdge(current, nextDefault);
157
158
  }
158
159
  for (let i = 0; i < beforeModelNodes.length; i++) {
159
160
  const node = beforeModelNodes[i];
160
161
  const current = node.name;
161
162
  const isLast = i === beforeModelNodes.length - 1;
162
- const nextDefault = isLast ? "model_request" : beforeModelNodes[i + 1].name;
163
+ const nextDefault = isLast ? AGENT_NODE_NAME : beforeModelNodes[i + 1].name;
163
164
  if (node.allowed && node.allowed.length > 0) {
164
- const hasTools = toolClasses.filter(isClientTool).length > 0;
165
- const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
165
+ const hasTools = clientTools.length > 0;
166
+ const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== TOOLS_NODE_NAME || hasTools);
166
167
  const destinations = Array.from(new Set([nextDefault, ...allowedMapped]));
167
- allNodeWorkflows.addConditionalEdges(current, this.#createBeforeModelRouter(toolClasses.filter(isClientTool), nextDefault), destinations);
168
+ allNodeWorkflows.addConditionalEdges(current, this.#createBeforeModelRouter(clientTools, nextDefault), destinations);
168
169
  } else allNodeWorkflows.addEdge(current, nextDefault);
169
170
  }
170
171
  const lastAfterModelNode = afterModelNodes.at(-1);
171
- if (afterModelNodes.length > 0 && lastAfterModelNode) allNodeWorkflows.addEdge("model_request", lastAfterModelNode.name);
172
+ if (afterModelNodes.length > 0 && lastAfterModelNode) allNodeWorkflows.addEdge(AGENT_NODE_NAME, lastAfterModelNode.name);
172
173
  else {
173
- const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));
174
+ const modelPaths = this.#getModelPaths(clientTools);
174
175
  const destinations = modelPaths.map((p) => p === END ? exitNode : p);
175
- if (destinations.length === 1) allNodeWorkflows.addEdge("model_request", destinations[0]);
176
- else allNodeWorkflows.addConditionalEdges("model_request", this.#createModelRouter(exitNode), destinations);
176
+ if (destinations.length === 1) allNodeWorkflows.addEdge(AGENT_NODE_NAME, destinations[0]);
177
+ else allNodeWorkflows.addConditionalEdges(AGENT_NODE_NAME, this.#createModelRouter(exitNode), destinations);
177
178
  }
178
179
  for (let i = afterModelNodes.length - 1; i > 0; i--) {
179
180
  const node = afterModelNodes[i];
180
181
  const current = node.name;
181
182
  const nextDefault = afterModelNodes[i - 1].name;
182
183
  if (node.allowed && node.allowed.length > 0) {
183
- const hasTools = toolClasses.filter(isClientTool).length > 0;
184
- const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
184
+ const hasTools = clientTools.length > 0;
185
+ const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== TOOLS_NODE_NAME || hasTools);
185
186
  const destinations = Array.from(new Set([nextDefault, ...allowedMapped]));
186
- allNodeWorkflows.addConditionalEdges(current, this.#createAfterModelSequenceRouter(toolClasses.filter(isClientTool), node.allowed, nextDefault), destinations);
187
+ allNodeWorkflows.addConditionalEdges(current, this.#createAfterModelSequenceRouter(clientTools, node.allowed, nextDefault), destinations);
187
188
  } else allNodeWorkflows.addEdge(current, nextDefault);
188
189
  }
189
190
  if (afterModelNodes.length > 0) {
190
191
  const firstAfterModel = afterModelNodes[0];
191
192
  const firstAfterModelNode = firstAfterModel.name;
192
- const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool), true).filter((p) => p !== "tools" || toolClasses.filter(isClientTool).length > 0);
193
+ const modelPaths = this.#getModelPaths(clientTools, true).filter((p) => p !== TOOLS_NODE_NAME || toolClasses.filter(isClientTool).length > 0);
193
194
  const allowJump = Boolean(firstAfterModel.allowed && firstAfterModel.allowed.length > 0);
194
195
  const destinations = modelPaths.map((p) => p === END ? exitNode : p);
195
- allNodeWorkflows.addConditionalEdges(firstAfterModelNode, this.#createAfterModelRouter(toolClasses.filter(isClientTool), allowJump, exitNode), destinations);
196
+ allNodeWorkflows.addConditionalEdges(firstAfterModelNode, this.#createAfterModelRouter(clientTools, allowJump, exitNode), destinations);
196
197
  }
197
198
  for (let i = afterAgentNodes.length - 1; i > 0; i--) {
198
199
  const node = afterAgentNodes[i];
199
200
  const current = node.name;
200
201
  const nextDefault = afterAgentNodes[i - 1].name;
201
202
  if (node.allowed && node.allowed.length > 0) {
202
- const hasTools = toolClasses.filter(isClientTool).length > 0;
203
- const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
203
+ const hasTools = clientTools.length > 0;
204
+ const allowedMapped = node.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== TOOLS_NODE_NAME || hasTools);
204
205
  const destinations = Array.from(new Set([nextDefault, ...allowedMapped]));
205
- allNodeWorkflows.addConditionalEdges(current, this.#createAfterModelSequenceRouter(toolClasses.filter(isClientTool), node.allowed, nextDefault), destinations);
206
+ allNodeWorkflows.addConditionalEdges(current, this.#createAfterModelSequenceRouter(clientTools, node.allowed, nextDefault), destinations);
206
207
  } else allNodeWorkflows.addEdge(current, nextDefault);
207
208
  }
208
209
  if (afterAgentNodes.length > 0) {
209
210
  const firstAfterAgent = afterAgentNodes[0];
210
211
  const firstAfterAgentNode = firstAfterAgent.name;
211
212
  if (firstAfterAgent.allowed && firstAfterAgent.allowed.length > 0) {
212
- const hasTools = toolClasses.filter(isClientTool).length > 0;
213
- const allowedMapped = firstAfterAgent.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
213
+ const hasTools = clientTools.length > 0;
214
+ const allowedMapped = firstAfterAgent.allowed.map((t) => parseJumpToTarget(t)).filter((dest) => dest !== TOOLS_NODE_NAME || hasTools);
214
215
  /**
215
216
  * For after_agent, only use explicitly allowed destinations (don't add loopEntryNode)
216
217
  * The default destination (when no jump occurs) should be END
217
218
  */
218
219
  const destinations = Array.from(new Set([END, ...allowedMapped]));
219
- allNodeWorkflows.addConditionalEdges(firstAfterAgentNode, this.#createAfterModelSequenceRouter(toolClasses.filter(isClientTool), firstAfterAgent.allowed, END), destinations);
220
+ allNodeWorkflows.addConditionalEdges(firstAfterAgentNode, this.#createAfterModelSequenceRouter(clientTools, firstAfterAgent.allowed, END), destinations);
220
221
  } else allNodeWorkflows.addEdge(firstAfterAgentNode, END);
221
222
  }
222
223
  /**
223
224
  * add edges for tools node
224
225
  */
225
- if (toolClasses.filter(isClientTool).length > 0) {
226
+ if (clientTools.length > 0) {
226
227
  const toolReturnTarget = loopEntryNode;
227
- if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", this.#createToolsRouter(shouldReturnDirect, exitNode), [toolReturnTarget, exitNode]);
228
- else allNodeWorkflows.addEdge("tools", toolReturnTarget);
228
+ if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges(TOOLS_NODE_NAME, this.#createToolsRouter(shouldReturnDirect, exitNode), [toolReturnTarget, exitNode]);
229
+ else allNodeWorkflows.addEdge(TOOLS_NODE_NAME, toolReturnTarget);
229
230
  }
230
231
  /**
231
232
  * compile the graph
@@ -251,8 +252,8 @@ var ReactAgent = class {
251
252
  */
252
253
  #getModelPaths(toolClasses, includeModelRequest = false) {
253
254
  const paths = [];
254
- if (toolClasses.length > 0) paths.push("tools");
255
- if (includeModelRequest) paths.push("model_request");
255
+ if (toolClasses.length > 0) paths.push(TOOLS_NODE_NAME);
256
+ if (includeModelRequest) paths.push(AGENT_NODE_NAME);
256
257
  paths.push(END);
257
258
  return paths;
258
259
  }
@@ -260,14 +261,11 @@ var ReactAgent = class {
260
261
  * Create routing function for tools node conditional edges.
261
262
  */
262
263
  #createToolsRouter(shouldReturnDirect, exitNode) {
263
- /**
264
- * ToDo: fix type
265
- */
266
264
  return (state) => {
267
265
  const messages = state.messages;
268
266
  const lastMessage = messages[messages.length - 1];
269
- if (ToolMessage.isInstance(lastMessage) && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? "model_request" : exitNode;
270
- return "model_request";
267
+ if (ToolMessage.isInstance(lastMessage) && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? AGENT_NODE_NAME : exitNode;
268
+ return AGENT_NODE_NAME;
271
269
  };
272
270
  }
273
271
  /**
@@ -287,13 +285,13 @@ var ReactAgent = class {
287
285
  /**
288
286
  * The tool node processes a single message.
289
287
  */
290
- if (this.#toolBehaviorVersion === "v1") return "tools";
288
+ if (this.#toolBehaviorVersion === "v1") return TOOLS_NODE_NAME;
291
289
  /**
292
290
  * Route to tools node (filter out any structured response tool calls)
293
291
  */
294
292
  const regularToolCalls = lastMessage.tool_calls.filter((toolCall) => !toolCall.name.startsWith("extract-"));
295
293
  if (regularToolCalls.length === 0) return exitNode;
296
- return regularToolCalls.map((toolCall) => new Send("tools", {
294
+ return regularToolCalls.map((toolCall) => new Send(TOOLS_NODE_NAME, {
297
295
  ...state,
298
296
  lg_tool_call: toolCall
299
297
  }));
@@ -321,14 +319,14 @@ var ReactAgent = class {
321
319
  if (AIMessage.isInstance(lastMessage) && (!lastMessage.tool_calls || lastMessage.tool_calls.length === 0)) return exitNode;
322
320
  if (allowJump && state.jumpTo) {
323
321
  if (state.jumpTo === END) return exitNode;
324
- if (state.jumpTo === "tools") {
322
+ if (state.jumpTo === TOOLS_NODE_NAME) {
325
323
  if (toolClasses.length === 0) return exitNode;
326
- return new Send("tools", {
324
+ return new Send(TOOLS_NODE_NAME, {
327
325
  ...state,
328
326
  jumpTo: void 0
329
327
  });
330
328
  }
331
- return new Send("model_request", {
329
+ return new Send(AGENT_NODE_NAME, {
332
330
  ...state,
333
331
  jumpTo: void 0
334
332
  });
@@ -336,12 +334,12 @@ var ReactAgent = class {
336
334
  const toolMessages = messages.filter(ToolMessage.isInstance);
337
335
  const lastAiMessage = messages.filter(AIMessage.isInstance).at(-1);
338
336
  const pendingToolCalls = lastAiMessage?.tool_calls?.filter((call) => !toolMessages.some((m) => m.tool_call_id === call.id));
339
- if (pendingToolCalls && pendingToolCalls.length > 0) return pendingToolCalls.map((toolCall) => new Send("tools", {
337
+ if (pendingToolCalls && pendingToolCalls.length > 0) return pendingToolCalls.map((toolCall) => new Send(TOOLS_NODE_NAME, {
340
338
  ...state,
341
339
  lg_tool_call: toolCall
342
340
  }));
343
341
  const hasStructuredResponseCalls = lastAiMessage?.tool_calls?.some((toolCall) => toolCall.name.startsWith("extract-"));
344
- if (pendingToolCalls && pendingToolCalls.length === 0 && !hasStructuredResponseCalls && hasStructuredResponse) return "model_request";
342
+ if (pendingToolCalls && pendingToolCalls.length === 0 && !hasStructuredResponseCalls && hasStructuredResponse) return AGENT_NODE_NAME;
345
343
  if (!AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls || lastMessage.tool_calls.length === 0) return exitNode;
346
344
  const hasOnlyStructuredResponseCalls = lastMessage.tool_calls.every((toolCall) => toolCall.name.startsWith("extract-"));
347
345
  const hasRegularToolCalls = lastMessage.tool_calls.some((toolCall) => !toolCall.name.startsWith("extract-"));
@@ -350,7 +348,7 @@ var ReactAgent = class {
350
348
  * For routing from afterModel nodes, always use simple string paths
351
349
  * The Send API is handled at the model_request node level
352
350
  */
353
- return "tools";
351
+ return TOOLS_NODE_NAME;
354
352
  };
355
353
  }
356
354
  /**
@@ -363,14 +361,14 @@ var ReactAgent = class {
363
361
  if (state.jumpTo) {
364
362
  const dest = parseJumpToTarget(state.jumpTo);
365
363
  if (dest === END && allowedSet.has(END)) return END;
366
- if (dest === "tools" && allowedSet.has("tools")) {
364
+ if (dest === TOOLS_NODE_NAME && allowedSet.has(TOOLS_NODE_NAME)) {
367
365
  if (toolClasses.length === 0) return END;
368
- return new Send("tools", {
366
+ return new Send(TOOLS_NODE_NAME, {
369
367
  ...state,
370
368
  jumpTo: void 0
371
369
  });
372
370
  }
373
- if (dest === "model_request" && allowedSet.has("model_request")) return new Send("model_request", {
371
+ if (dest === AGENT_NODE_NAME && allowedSet.has(AGENT_NODE_NAME)) return new Send(AGENT_NODE_NAME, {
374
372
  ...state,
375
373
  jumpTo: void 0
376
374
  });
@@ -387,15 +385,19 @@ var ReactAgent = class {
387
385
  return (state) => {
388
386
  if (!state.jumpTo) return nextDefault;
389
387
  const destination = parseJumpToTarget(state.jumpTo);
390
- if (destination === END) return exitNode;
391
- if (destination === "tools") {
388
+ if (destination === END)
389
+ /**
390
+ * When beforeAgent jumps to END, route to exitNode (first afterAgent node)
391
+ */
392
+ return exitNode;
393
+ if (destination === TOOLS_NODE_NAME) {
392
394
  if (toolClasses.length === 0) return exitNode;
393
- return new Send("tools", {
395
+ return new Send(TOOLS_NODE_NAME, {
394
396
  ...state,
395
397
  jumpTo: void 0
396
398
  });
397
399
  }
398
- return new Send("model_request", {
400
+ return new Send(AGENT_NODE_NAME, {
399
401
  ...state,
400
402
  jumpTo: void 0
401
403
  });
@@ -410,14 +412,14 @@ var ReactAgent = class {
410
412
  if (!state.jumpTo) return nextDefault;
411
413
  const destination = parseJumpToTarget(state.jumpTo);
412
414
  if (destination === END) return END;
413
- if (destination === "tools") {
415
+ if (destination === TOOLS_NODE_NAME) {
414
416
  if (toolClasses.length === 0) return END;
415
- return new Send("tools", {
417
+ return new Send(TOOLS_NODE_NAME, {
416
418
  ...state,
417
419
  jumpTo: void 0
418
420
  });
419
421
  }
420
- return new Send("model_request", {
422
+ return new Send(AGENT_NODE_NAME, {
421
423
  ...state,
422
424
  jumpTo: void 0
423
425
  });