langchain 1.5.11-rc.0 → 1.5.11

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 (40) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/agents/index.cjs +0 -7
  3. package/dist/agents/index.cjs.map +1 -1
  4. package/dist/agents/index.d.cts +2 -2
  5. package/dist/agents/index.d.ts +2 -2
  6. package/dist/agents/index.js +1 -2
  7. package/dist/agents/index.js.map +1 -1
  8. package/dist/agents/middleware/types.cjs.map +1 -1
  9. package/dist/agents/middleware/types.d.cts +1 -19
  10. package/dist/agents/middleware/types.d.cts.map +1 -1
  11. package/dist/agents/middleware/types.d.ts +1 -19
  12. package/dist/agents/middleware/types.d.ts.map +1 -1
  13. package/dist/agents/middleware/types.js.map +1 -1
  14. package/dist/agents/middleware.cjs +1 -2
  15. package/dist/agents/middleware.cjs.map +1 -1
  16. package/dist/agents/middleware.d.cts +1 -8
  17. package/dist/agents/middleware.d.cts.map +1 -1
  18. package/dist/agents/middleware.d.ts +1 -8
  19. package/dist/agents/middleware.d.ts.map +1 -1
  20. package/dist/agents/middleware.js +1 -2
  21. package/dist/agents/middleware.js.map +1 -1
  22. package/dist/agents/nodes/middleware.cjs +1 -4
  23. package/dist/agents/nodes/middleware.cjs.map +1 -1
  24. package/dist/agents/nodes/middleware.js +1 -4
  25. package/dist/agents/nodes/middleware.js.map +1 -1
  26. package/dist/agents/responses.cjs +1 -1
  27. package/dist/agents/responses.cjs.map +1 -1
  28. package/dist/agents/responses.d.cts.map +1 -1
  29. package/dist/agents/responses.d.ts.map +1 -1
  30. package/dist/agents/responses.js +1 -1
  31. package/dist/agents/responses.js.map +1 -1
  32. package/dist/browser.cjs +0 -8
  33. package/dist/browser.d.cts +2 -2
  34. package/dist/browser.d.ts +2 -2
  35. package/dist/browser.js +2 -3
  36. package/dist/index.cjs +0 -8
  37. package/dist/index.d.cts +2 -2
  38. package/dist/index.d.ts +2 -2
  39. package/dist/index.js +2 -3
  40. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # langchain
2
2
 
3
+ ## 1.5.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#11436](https://github.com/langchain-ai/langchainjs/pull/11436) [`702be70`](https://github.com/langchain-ai/langchainjs/commit/702be70bcaadbfe9a47a3fcccbb75bdea17cae04) Thanks [@chiliec](https://github.com/chiliec)! - fix(agents): ignore thought/reasoning text blocks when parsing structured output in `ProviderStrategy`
8
+
3
9
  ## 1.5.11-rc.0
4
10
 
5
11
  ### Patch Changes
@@ -7,7 +7,6 @@ const require_ReactAgent = require("./ReactAgent.cjs");
7
7
  const require_types = require("./middleware/types.cjs");
8
8
  const require_middleware = require("./middleware.cjs");
9
9
  const require_utils = require("./tests/utils.cjs");
10
- let _langchain_langgraph = require("@langchain/langgraph");
11
10
  //#region src/agents/index.ts
12
11
  function createAgent(params) {
13
12
  return new require_ReactAgent.ReactAgent(params);
@@ -26,12 +25,6 @@ exports.createAgent = createAgent;
26
25
  exports.createMiddleware = require_middleware.createMiddleware;
27
26
  exports.createSubagentTransformer = require_subagent.createSubagentTransformer;
28
27
  exports.createToolCallTransformer = require_tool_call.createToolCallTransformer;
29
- Object.defineProperty(exports, "omitPayload", {
30
- enumerable: true,
31
- get: function() {
32
- return _langchain_langgraph.omitPayload;
33
- }
34
- });
35
28
  exports.providerStrategy = require_responses.providerStrategy;
36
29
  exports.toolStrategy = require_responses.toolStrategy;
37
30
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["ReactAgent"],"sources":["../../src/agents/index.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type {\n StateDefinitionInit,\n StreamTransformer,\n} from \"@langchain/langgraph\";\n\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nimport type {\n CreateAgentParams,\n AgentTypeConfig,\n CombineTools,\n CombineStreamTransformers,\n} from \"./types.js\";\nimport type {\n AnyAgentMiddleware,\n AnyAnnotationRoot,\n} from \"./middleware/types.js\";\nimport type { ExtractZodArrayTypes } from \"./types.js\";\nimport type { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools\n * and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively\n * work towards solutions.\n *\n * The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively\n * work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state\n * across interactions, and provide auditable decision processes.\n *\n * ## Core Components\n *\n * ### Model\n * The reasoning engine can be specified as:\n * - **String identifier**: `\"openai:gpt-4o\"` for simple setup\n * - **Model instance**: Configured model object for full control\n * - **Dynamic function**: Select models at runtime based on state\n *\n * ### Tools\n * Tools give agents the ability to take actions:\n * - Pass an array of tools created with the `tool` function\n * - Or provide a configured `ToolNode` for custom error handling\n *\n * ### Prompt\n * Shape how your agent approaches tasks:\n * - String for simple instructions\n * - SystemMessage for structured prompts\n * - Function for dynamic prompts based on state\n *\n * ### Middleware\n * Middleware allows you to extend the agent's behavior:\n * - Add pre/post-model processing for context injection or validation\n * - Add dynamic control flows, e.g. terminate invocation or retries\n * - Add human-in-the-loop capabilities\n * - Add tool calls to the agent\n * - Add tool results to the agent\n *\n * ## Advanced Features\n *\n * - **Structured Output**: Use `responseFormat` with a Zod schema to get typed responses\n * - **Memory**: Extend the state schema to remember information across interactions\n * - **Streaming**: Get real-time updates as the agent processes\n *\n * @param options - Configuration options for the agent\n * @param options.llm - The language model as an instance of a chat model\n * @param options.model - The language model as a string identifier, see more in {@link https://docs.langchain.com/oss/javascript/langchain/models#basic-usage | Models}.\n * @param options.tools - Array of tools or configured ToolNode\n * @param options.prompt - System instructions (string, SystemMessage, or function)\n * @param options.responseFormat - Zod schema for structured output\n * @param options.stateSchema - Custom state schema for memory\n * @param options.middleware - Array of middleware for extending agent behavior, see more in {@link https://docs.langchain.com/oss/javascript/langchain/middleware | Middleware}.\n *\n * @returns A ReactAgent instance with `invoke` and `stream` methods\n *\n * @example Basic agent with tools\n * ```ts\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const search = tool(\n * ({ query }) => `Results for: ${query}`,\n * {\n * name: \"search\",\n * description: \"Search for information\",\n * schema: z.object({\n * query: z.string().describe(\"The search query\"),\n * })\n * }\n * );\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [search],\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"user\", content: \"Search for ReAct agents\" }],\n * });\n * ```\n *\n * @example Structured output\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const ContactInfo = z.object({\n * name: z.string(),\n * email: z.string(),\n * phone: z.string(),\n * });\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [],\n * responseFormat: ContactInfo,\n * });\n *\n * const result = await agent.invoke({\n * messages: [{\n * role: \"user\",\n * content: \"Extract: John Doe, john@example.com, (555) 123-4567\"\n * }],\n * });\n *\n * console.log(result.structuredResponse);\n * // { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }\n * ```\n *\n * @example Streaming responses\n * ```ts\n * const stream = await agent.stream(\n * { messages: [{ role: \"user\", content: \"What's the weather?\" }] },\n * { streamMode: \"values\" }\n * );\n *\n * for await (const chunk of stream) {\n * // ...\n * }\n * ```\n *\n * @example With StateSchema\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { StateSchema, ReducedValue } from \"@langchain/langgraph\";\n * import { z } from \"zod\";\n *\n * const AgentState = new StateSchema({\n * userId: z.string(),\n * count: z.number().default(0),\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * { inputSchema: z.string(), reducer: (c, n) => [...c, n] }\n * ),\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [searchTool],\n * stateSchema: AgentState,\n * });\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n InteropZodType<StructuredResponseFormat>\n > & {\n responseFormat: InteropZodType<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n StructuredResponseFormat extends readonly InteropZodType<any>[],\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n StructuredResponseFormat\n > & {\n responseFormat: StructuredResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 6: With responseFormat as single SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema\n > & {\n responseFormat: SerializableSchema;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 7: With responseFormat as array of SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema[]\n > & {\n responseFormat: SerializableSchema[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 8: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TypedToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: TypedToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 9: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 10: With responseFormat as ProviderStrategy\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ProviderStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ProviderStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 11: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 12: With responseFormat explicitly undefined\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 13: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n TStateSchema extends StateDefinitionInit,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n any\n >\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n> {\n return new ReactAgent(params);\n}\n\n// Re-export types and utilities\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport * from \"./nodes/types.js\";\nexport type { JumpToTarget } from \"./constants.js\";\nexport type { Runtime } from \"./runtime.js\";\nexport {\n toolStrategy,\n providerStrategy,\n ToolStrategy,\n ProviderStrategy,\n type TypedToolStrategy,\n type ResponseFormat,\n type ResponseFormatUndefined,\n} from \"./responses.js\";\nexport { createMiddleware } from \"./middleware.js\";\nexport { omitPayload, type TracePolicy } from \"@langchain/langgraph\";\nexport { MIDDLEWARE_BRAND } from \"./middleware/types.js\";\nexport type * from \"./middleware/types.js\";\nexport { FakeToolCallingModel } from \"./tests/utils.js\";\nexport type { ReactAgent } from \"./ReactAgent.js\";\nexport {\n createToolCallTransformer,\n createSubagentTransformer,\n type AgentRunStream,\n type ToolCallStreamUnion,\n type SubagentRunStream,\n} from \"./transformers/index.js\";\n"],"mappings":";;;;;;;;;;;AA+pBA,SAAgB,YAad,QAeA;CACA,OAAO,IAAIA,mBAAAA,WAAW,MAAM;AAC9B"}
1
+ {"version":3,"file":"index.cjs","names":["ReactAgent"],"sources":["../../src/agents/index.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type {\n StateDefinitionInit,\n StreamTransformer,\n} from \"@langchain/langgraph\";\n\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nimport type {\n CreateAgentParams,\n AgentTypeConfig,\n CombineTools,\n CombineStreamTransformers,\n} from \"./types.js\";\nimport type {\n AnyAgentMiddleware,\n AnyAnnotationRoot,\n} from \"./middleware/types.js\";\nimport type { ExtractZodArrayTypes } from \"./types.js\";\nimport type { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools\n * and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively\n * work towards solutions.\n *\n * The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively\n * work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state\n * across interactions, and provide auditable decision processes.\n *\n * ## Core Components\n *\n * ### Model\n * The reasoning engine can be specified as:\n * - **String identifier**: `\"openai:gpt-4o\"` for simple setup\n * - **Model instance**: Configured model object for full control\n * - **Dynamic function**: Select models at runtime based on state\n *\n * ### Tools\n * Tools give agents the ability to take actions:\n * - Pass an array of tools created with the `tool` function\n * - Or provide a configured `ToolNode` for custom error handling\n *\n * ### Prompt\n * Shape how your agent approaches tasks:\n * - String for simple instructions\n * - SystemMessage for structured prompts\n * - Function for dynamic prompts based on state\n *\n * ### Middleware\n * Middleware allows you to extend the agent's behavior:\n * - Add pre/post-model processing for context injection or validation\n * - Add dynamic control flows, e.g. terminate invocation or retries\n * - Add human-in-the-loop capabilities\n * - Add tool calls to the agent\n * - Add tool results to the agent\n *\n * ## Advanced Features\n *\n * - **Structured Output**: Use `responseFormat` with a Zod schema to get typed responses\n * - **Memory**: Extend the state schema to remember information across interactions\n * - **Streaming**: Get real-time updates as the agent processes\n *\n * @param options - Configuration options for the agent\n * @param options.llm - The language model as an instance of a chat model\n * @param options.model - The language model as a string identifier, see more in {@link https://docs.langchain.com/oss/javascript/langchain/models#basic-usage | Models}.\n * @param options.tools - Array of tools or configured ToolNode\n * @param options.prompt - System instructions (string, SystemMessage, or function)\n * @param options.responseFormat - Zod schema for structured output\n * @param options.stateSchema - Custom state schema for memory\n * @param options.middleware - Array of middleware for extending agent behavior, see more in {@link https://docs.langchain.com/oss/javascript/langchain/middleware | Middleware}.\n *\n * @returns A ReactAgent instance with `invoke` and `stream` methods\n *\n * @example Basic agent with tools\n * ```ts\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const search = tool(\n * ({ query }) => `Results for: ${query}`,\n * {\n * name: \"search\",\n * description: \"Search for information\",\n * schema: z.object({\n * query: z.string().describe(\"The search query\"),\n * })\n * }\n * );\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [search],\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"user\", content: \"Search for ReAct agents\" }],\n * });\n * ```\n *\n * @example Structured output\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const ContactInfo = z.object({\n * name: z.string(),\n * email: z.string(),\n * phone: z.string(),\n * });\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [],\n * responseFormat: ContactInfo,\n * });\n *\n * const result = await agent.invoke({\n * messages: [{\n * role: \"user\",\n * content: \"Extract: John Doe, john@example.com, (555) 123-4567\"\n * }],\n * });\n *\n * console.log(result.structuredResponse);\n * // { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }\n * ```\n *\n * @example Streaming responses\n * ```ts\n * const stream = await agent.stream(\n * { messages: [{ role: \"user\", content: \"What's the weather?\" }] },\n * { streamMode: \"values\" }\n * );\n *\n * for await (const chunk of stream) {\n * // ...\n * }\n * ```\n *\n * @example With StateSchema\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { StateSchema, ReducedValue } from \"@langchain/langgraph\";\n * import { z } from \"zod\";\n *\n * const AgentState = new StateSchema({\n * userId: z.string(),\n * count: z.number().default(0),\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * { inputSchema: z.string(), reducer: (c, n) => [...c, n] }\n * ),\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [searchTool],\n * stateSchema: AgentState,\n * });\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n InteropZodType<StructuredResponseFormat>\n > & {\n responseFormat: InteropZodType<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n StructuredResponseFormat extends readonly InteropZodType<any>[],\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n StructuredResponseFormat\n > & {\n responseFormat: StructuredResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 6: With responseFormat as single SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema\n > & {\n responseFormat: SerializableSchema;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 7: With responseFormat as array of SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema[]\n > & {\n responseFormat: SerializableSchema[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 8: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TypedToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: TypedToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 9: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 10: With responseFormat as ProviderStrategy\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ProviderStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ProviderStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 11: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 12: With responseFormat explicitly undefined\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 13: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n TStateSchema extends StateDefinitionInit,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n any\n >\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n> {\n return new ReactAgent(params);\n}\n\n// Re-export types and utilities\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport * from \"./nodes/types.js\";\nexport type { JumpToTarget } from \"./constants.js\";\nexport type { Runtime } from \"./runtime.js\";\nexport {\n toolStrategy,\n providerStrategy,\n ToolStrategy,\n ProviderStrategy,\n type TypedToolStrategy,\n type ResponseFormat,\n type ResponseFormatUndefined,\n} from \"./responses.js\";\nexport { createMiddleware } from \"./middleware.js\";\nexport { MIDDLEWARE_BRAND } from \"./middleware/types.js\";\nexport type * from \"./middleware/types.js\";\nexport { FakeToolCallingModel } from \"./tests/utils.js\";\nexport type { ReactAgent } from \"./ReactAgent.js\";\nexport {\n createToolCallTransformer,\n createSubagentTransformer,\n type AgentRunStream,\n type ToolCallStreamUnion,\n type SubagentRunStream,\n} from \"./transformers/index.js\";\n"],"mappings":";;;;;;;;;;AA+pBA,SAAgB,YAad,QAeA;CACA,OAAO,IAAIA,mBAAAA,WAAW,MAAM;AAC9B"}
@@ -14,7 +14,7 @@ import { createMiddleware } from "./middleware.cjs";
14
14
  import { FakeToolCallingModel } from "./tests/utils.cjs";
15
15
  import { ClientTool, ServerTool } from "@langchain/core/tools";
16
16
  import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
17
- import { StateDefinitionInit, StreamTransformer, TracePolicy as TracePolicy$1, omitPayload } from "@langchain/langgraph";
17
+ import { StateDefinitionInit, StreamTransformer } from "@langchain/langgraph";
18
18
  import { SerializableSchema } from "@langchain/core/utils/standard_schema";
19
19
  //#region src/agents/index.d.ts
20
20
  /**
@@ -236,5 +236,5 @@ declare function createAgent<StructuredResponseFormat extends Record<string, any
236
236
  streamTransformers?: TStreamTransformers;
237
237
  }): ReactAgent<AgentTypeConfig<StructuredResponseFormat, TStateSchema, ContextSchema, TMiddleware, CombineTools<TTools, TMiddleware>, CombineStreamTransformers<TStreamTransformers, TMiddleware>>>;
238
238
  //#endregion
239
- export { type AfterAgentHook, type AfterModelHook, type AgentMiddleware, type AgentRunStream, AgentTypeConfig, type AnyAgentMiddleware, type AnyAnnotationRoot, type BeforeAgentHook, type BeforeModelHook, BuiltInState, CombineStreamTransformers, CombineTools, CreateAgentParams, DefaultAgentTypeConfig, type DefaultMiddlewareTypeConfig, ExecutedToolCall, ExtractZodArrayTypes, FakeToolCallingModel, InferAgentContext, InferAgentContextSchema, InferAgentMiddleware, InferAgentResponse, InferAgentState, InferAgentStateSchema, InferAgentStreamTransformers, InferAgentTools, InferAgentType, type InferChannelType, type InferContextInput, type InferMergedInputState, type InferMergedState, type InferMiddlewareContext, type InferMiddlewareContextInput, type InferMiddlewareContextInputs, type InferMiddlewareContextSchema, type InferMiddlewareContexts, type InferMiddlewareFullContext, type InferMiddlewareInputState, type InferMiddlewareInputStates, type InferMiddlewareSchema, type InferMiddlewareState, type InferMiddlewareStates, InferMiddlewareStreamTransformers, InferMiddlewareStreamTransformersArray, type InferMiddlewareStreamTransformersFromConfig, InferMiddlewareTools, InferMiddlewareToolsArray, type InferMiddlewareToolsFromConfig, type InferMiddlewareType, type InferSchemaInput, type InferSchemaUpdateType, type InferSchemaValue, type InferSchemaValueType, Interrupt, JumpTo, type JumpToTarget, MIDDLEWARE_BRAND, MiddlewareError, type MiddlewareResult, type MiddlewareTypeConfig, ModelRequest, MultipleStructuredOutputsError, MultipleToolsBoundError, N, type NormalizedSchemaInput, type NormalizedSchemaUpdate, ProviderStrategy, type ReactAgent, ResolveAgentTypeConfig, type ResolveMiddlewareTypeConfig, type ResponseFormat, type ResponseFormatUndefined, type Runtime$1 as Runtime, StructuredOutputParsingError, type SubagentRunStream, type ToAnnotationRoot, ToolCall, type ToolCallHandler, type ToolCallRequest, type ToolCallStreamUnion, ToolInvocationError, ToolResult, ToolStrategy, ToolsToMessageToolSet, type TracePolicy$1 as TracePolicy, type TypedToolStrategy, UserInput, WithStateGraphNodes, type WrapModelCallHandler, type WrapModelCallHook, type WrapToolCallHook, createAgent, createMiddleware, createSubagentTransformer, createToolCallTransformer, omitPayload, providerStrategy, toolStrategy };
239
+ export { type AfterAgentHook, type AfterModelHook, type AgentMiddleware, type AgentRunStream, AgentTypeConfig, type AnyAgentMiddleware, type AnyAnnotationRoot, type BeforeAgentHook, type BeforeModelHook, BuiltInState, CombineStreamTransformers, CombineTools, CreateAgentParams, DefaultAgentTypeConfig, type DefaultMiddlewareTypeConfig, ExecutedToolCall, ExtractZodArrayTypes, FakeToolCallingModel, InferAgentContext, InferAgentContextSchema, InferAgentMiddleware, InferAgentResponse, InferAgentState, InferAgentStateSchema, InferAgentStreamTransformers, InferAgentTools, InferAgentType, type InferChannelType, type InferContextInput, type InferMergedInputState, type InferMergedState, type InferMiddlewareContext, type InferMiddlewareContextInput, type InferMiddlewareContextInputs, type InferMiddlewareContextSchema, type InferMiddlewareContexts, type InferMiddlewareFullContext, type InferMiddlewareInputState, type InferMiddlewareInputStates, type InferMiddlewareSchema, type InferMiddlewareState, type InferMiddlewareStates, InferMiddlewareStreamTransformers, InferMiddlewareStreamTransformersArray, type InferMiddlewareStreamTransformersFromConfig, InferMiddlewareTools, InferMiddlewareToolsArray, type InferMiddlewareToolsFromConfig, type InferMiddlewareType, type InferSchemaInput, type InferSchemaUpdateType, type InferSchemaValue, type InferSchemaValueType, Interrupt, JumpTo, type JumpToTarget, MIDDLEWARE_BRAND, MiddlewareError, type MiddlewareResult, type MiddlewareTypeConfig, ModelRequest, MultipleStructuredOutputsError, MultipleToolsBoundError, N, type NormalizedSchemaInput, type NormalizedSchemaUpdate, ProviderStrategy, type ReactAgent, ResolveAgentTypeConfig, type ResolveMiddlewareTypeConfig, type ResponseFormat, type ResponseFormatUndefined, type Runtime$1 as Runtime, StructuredOutputParsingError, type SubagentRunStream, type ToAnnotationRoot, ToolCall, type ToolCallHandler, type ToolCallRequest, type ToolCallStreamUnion, ToolInvocationError, ToolResult, ToolStrategy, ToolsToMessageToolSet, type TypedToolStrategy, UserInput, WithStateGraphNodes, type WrapModelCallHandler, type WrapModelCallHook, type WrapToolCallHook, createAgent, createMiddleware, createSubagentTransformer, createToolCallTransformer, providerStrategy, toolStrategy };
240
240
  //# sourceMappingURL=index.d.cts.map
@@ -13,7 +13,7 @@ import { ReactAgent } from "./ReactAgent.js";
13
13
  import { createMiddleware } from "./middleware.js";
14
14
  import { FakeToolCallingModel } from "./tests/utils.js";
15
15
  import { ClientTool, ServerTool } from "@langchain/core/tools";
16
- import { StateDefinitionInit, StreamTransformer, TracePolicy as TracePolicy$1, omitPayload } from "@langchain/langgraph";
16
+ import { StateDefinitionInit, StreamTransformer } from "@langchain/langgraph";
17
17
  import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
18
18
  import { SerializableSchema } from "@langchain/core/utils/standard_schema";
19
19
  //#region src/agents/index.d.ts
@@ -236,5 +236,5 @@ declare function createAgent<StructuredResponseFormat extends Record<string, any
236
236
  streamTransformers?: TStreamTransformers;
237
237
  }): ReactAgent<AgentTypeConfig<StructuredResponseFormat, TStateSchema, ContextSchema, TMiddleware, CombineTools<TTools, TMiddleware>, CombineStreamTransformers<TStreamTransformers, TMiddleware>>>;
238
238
  //#endregion
239
- export { type AfterAgentHook, type AfterModelHook, type AgentMiddleware, type AgentRunStream, AgentTypeConfig, type AnyAgentMiddleware, type AnyAnnotationRoot, type BeforeAgentHook, type BeforeModelHook, BuiltInState, CombineStreamTransformers, CombineTools, CreateAgentParams, DefaultAgentTypeConfig, type DefaultMiddlewareTypeConfig, ExecutedToolCall, ExtractZodArrayTypes, FakeToolCallingModel, InferAgentContext, InferAgentContextSchema, InferAgentMiddleware, InferAgentResponse, InferAgentState, InferAgentStateSchema, InferAgentStreamTransformers, InferAgentTools, InferAgentType, type InferChannelType, type InferContextInput, type InferMergedInputState, type InferMergedState, type InferMiddlewareContext, type InferMiddlewareContextInput, type InferMiddlewareContextInputs, type InferMiddlewareContextSchema, type InferMiddlewareContexts, type InferMiddlewareFullContext, type InferMiddlewareInputState, type InferMiddlewareInputStates, type InferMiddlewareSchema, type InferMiddlewareState, type InferMiddlewareStates, InferMiddlewareStreamTransformers, InferMiddlewareStreamTransformersArray, type InferMiddlewareStreamTransformersFromConfig, InferMiddlewareTools, InferMiddlewareToolsArray, type InferMiddlewareToolsFromConfig, type InferMiddlewareType, type InferSchemaInput, type InferSchemaUpdateType, type InferSchemaValue, type InferSchemaValueType, Interrupt, JumpTo, type JumpToTarget, MIDDLEWARE_BRAND, MiddlewareError, type MiddlewareResult, type MiddlewareTypeConfig, ModelRequest, MultipleStructuredOutputsError, MultipleToolsBoundError, N, type NormalizedSchemaInput, type NormalizedSchemaUpdate, ProviderStrategy, type ReactAgent, ResolveAgentTypeConfig, type ResolveMiddlewareTypeConfig, type ResponseFormat, type ResponseFormatUndefined, type Runtime$1 as Runtime, StructuredOutputParsingError, type SubagentRunStream, type ToAnnotationRoot, ToolCall, type ToolCallHandler, type ToolCallRequest, type ToolCallStreamUnion, ToolInvocationError, ToolResult, ToolStrategy, ToolsToMessageToolSet, type TracePolicy$1 as TracePolicy, type TypedToolStrategy, UserInput, WithStateGraphNodes, type WrapModelCallHandler, type WrapModelCallHook, type WrapToolCallHook, createAgent, createMiddleware, createSubagentTransformer, createToolCallTransformer, omitPayload, providerStrategy, toolStrategy };
239
+ export { type AfterAgentHook, type AfterModelHook, type AgentMiddleware, type AgentRunStream, AgentTypeConfig, type AnyAgentMiddleware, type AnyAnnotationRoot, type BeforeAgentHook, type BeforeModelHook, BuiltInState, CombineStreamTransformers, CombineTools, CreateAgentParams, DefaultAgentTypeConfig, type DefaultMiddlewareTypeConfig, ExecutedToolCall, ExtractZodArrayTypes, FakeToolCallingModel, InferAgentContext, InferAgentContextSchema, InferAgentMiddleware, InferAgentResponse, InferAgentState, InferAgentStateSchema, InferAgentStreamTransformers, InferAgentTools, InferAgentType, type InferChannelType, type InferContextInput, type InferMergedInputState, type InferMergedState, type InferMiddlewareContext, type InferMiddlewareContextInput, type InferMiddlewareContextInputs, type InferMiddlewareContextSchema, type InferMiddlewareContexts, type InferMiddlewareFullContext, type InferMiddlewareInputState, type InferMiddlewareInputStates, type InferMiddlewareSchema, type InferMiddlewareState, type InferMiddlewareStates, InferMiddlewareStreamTransformers, InferMiddlewareStreamTransformersArray, type InferMiddlewareStreamTransformersFromConfig, InferMiddlewareTools, InferMiddlewareToolsArray, type InferMiddlewareToolsFromConfig, type InferMiddlewareType, type InferSchemaInput, type InferSchemaUpdateType, type InferSchemaValue, type InferSchemaValueType, Interrupt, JumpTo, type JumpToTarget, MIDDLEWARE_BRAND, MiddlewareError, type MiddlewareResult, type MiddlewareTypeConfig, ModelRequest, MultipleStructuredOutputsError, MultipleToolsBoundError, N, type NormalizedSchemaInput, type NormalizedSchemaUpdate, ProviderStrategy, type ReactAgent, ResolveAgentTypeConfig, type ResolveMiddlewareTypeConfig, type ResponseFormat, type ResponseFormatUndefined, type Runtime$1 as Runtime, StructuredOutputParsingError, type SubagentRunStream, type ToAnnotationRoot, ToolCall, type ToolCallHandler, type ToolCallRequest, type ToolCallStreamUnion, ToolInvocationError, ToolResult, ToolStrategy, ToolsToMessageToolSet, type TypedToolStrategy, UserInput, WithStateGraphNodes, type WrapModelCallHandler, type WrapModelCallHook, type WrapToolCallHook, createAgent, createMiddleware, createSubagentTransformer, createToolCallTransformer, providerStrategy, toolStrategy };
240
240
  //# sourceMappingURL=index.d.ts.map
@@ -7,12 +7,11 @@ import { ReactAgent } from "./ReactAgent.js";
7
7
  import { MIDDLEWARE_BRAND } from "./middleware/types.js";
8
8
  import { createMiddleware } from "./middleware.js";
9
9
  import { FakeToolCallingModel } from "./tests/utils.js";
10
- import { omitPayload } from "@langchain/langgraph";
11
10
  //#region src/agents/index.ts
12
11
  function createAgent(params) {
13
12
  return new ReactAgent(params);
14
13
  }
15
14
  //#endregion
16
- export { FakeToolCallingModel, MIDDLEWARE_BRAND, MiddlewareError, MultipleStructuredOutputsError, MultipleToolsBoundError, ProviderStrategy, StructuredOutputParsingError, ToolInvocationError, ToolStrategy, createAgent, createMiddleware, createSubagentTransformer, createToolCallTransformer, omitPayload, providerStrategy, toolStrategy };
15
+ export { FakeToolCallingModel, MIDDLEWARE_BRAND, MiddlewareError, MultipleStructuredOutputsError, MultipleToolsBoundError, ProviderStrategy, StructuredOutputParsingError, ToolInvocationError, ToolStrategy, createAgent, createMiddleware, createSubagentTransformer, createToolCallTransformer, providerStrategy, toolStrategy };
17
16
 
18
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/agents/index.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type {\n StateDefinitionInit,\n StreamTransformer,\n} from \"@langchain/langgraph\";\n\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nimport type {\n CreateAgentParams,\n AgentTypeConfig,\n CombineTools,\n CombineStreamTransformers,\n} from \"./types.js\";\nimport type {\n AnyAgentMiddleware,\n AnyAnnotationRoot,\n} from \"./middleware/types.js\";\nimport type { ExtractZodArrayTypes } from \"./types.js\";\nimport type { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools\n * and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively\n * work towards solutions.\n *\n * The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively\n * work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state\n * across interactions, and provide auditable decision processes.\n *\n * ## Core Components\n *\n * ### Model\n * The reasoning engine can be specified as:\n * - **String identifier**: `\"openai:gpt-4o\"` for simple setup\n * - **Model instance**: Configured model object for full control\n * - **Dynamic function**: Select models at runtime based on state\n *\n * ### Tools\n * Tools give agents the ability to take actions:\n * - Pass an array of tools created with the `tool` function\n * - Or provide a configured `ToolNode` for custom error handling\n *\n * ### Prompt\n * Shape how your agent approaches tasks:\n * - String for simple instructions\n * - SystemMessage for structured prompts\n * - Function for dynamic prompts based on state\n *\n * ### Middleware\n * Middleware allows you to extend the agent's behavior:\n * - Add pre/post-model processing for context injection or validation\n * - Add dynamic control flows, e.g. terminate invocation or retries\n * - Add human-in-the-loop capabilities\n * - Add tool calls to the agent\n * - Add tool results to the agent\n *\n * ## Advanced Features\n *\n * - **Structured Output**: Use `responseFormat` with a Zod schema to get typed responses\n * - **Memory**: Extend the state schema to remember information across interactions\n * - **Streaming**: Get real-time updates as the agent processes\n *\n * @param options - Configuration options for the agent\n * @param options.llm - The language model as an instance of a chat model\n * @param options.model - The language model as a string identifier, see more in {@link https://docs.langchain.com/oss/javascript/langchain/models#basic-usage | Models}.\n * @param options.tools - Array of tools or configured ToolNode\n * @param options.prompt - System instructions (string, SystemMessage, or function)\n * @param options.responseFormat - Zod schema for structured output\n * @param options.stateSchema - Custom state schema for memory\n * @param options.middleware - Array of middleware for extending agent behavior, see more in {@link https://docs.langchain.com/oss/javascript/langchain/middleware | Middleware}.\n *\n * @returns A ReactAgent instance with `invoke` and `stream` methods\n *\n * @example Basic agent with tools\n * ```ts\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const search = tool(\n * ({ query }) => `Results for: ${query}`,\n * {\n * name: \"search\",\n * description: \"Search for information\",\n * schema: z.object({\n * query: z.string().describe(\"The search query\"),\n * })\n * }\n * );\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [search],\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"user\", content: \"Search for ReAct agents\" }],\n * });\n * ```\n *\n * @example Structured output\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const ContactInfo = z.object({\n * name: z.string(),\n * email: z.string(),\n * phone: z.string(),\n * });\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [],\n * responseFormat: ContactInfo,\n * });\n *\n * const result = await agent.invoke({\n * messages: [{\n * role: \"user\",\n * content: \"Extract: John Doe, john@example.com, (555) 123-4567\"\n * }],\n * });\n *\n * console.log(result.structuredResponse);\n * // { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }\n * ```\n *\n * @example Streaming responses\n * ```ts\n * const stream = await agent.stream(\n * { messages: [{ role: \"user\", content: \"What's the weather?\" }] },\n * { streamMode: \"values\" }\n * );\n *\n * for await (const chunk of stream) {\n * // ...\n * }\n * ```\n *\n * @example With StateSchema\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { StateSchema, ReducedValue } from \"@langchain/langgraph\";\n * import { z } from \"zod\";\n *\n * const AgentState = new StateSchema({\n * userId: z.string(),\n * count: z.number().default(0),\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * { inputSchema: z.string(), reducer: (c, n) => [...c, n] }\n * ),\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [searchTool],\n * stateSchema: AgentState,\n * });\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n InteropZodType<StructuredResponseFormat>\n > & {\n responseFormat: InteropZodType<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n StructuredResponseFormat extends readonly InteropZodType<any>[],\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n StructuredResponseFormat\n > & {\n responseFormat: StructuredResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 6: With responseFormat as single SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema\n > & {\n responseFormat: SerializableSchema;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 7: With responseFormat as array of SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema[]\n > & {\n responseFormat: SerializableSchema[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 8: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TypedToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: TypedToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 9: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 10: With responseFormat as ProviderStrategy\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ProviderStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ProviderStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 11: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 12: With responseFormat explicitly undefined\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 13: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n TStateSchema extends StateDefinitionInit,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n any\n >\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n> {\n return new ReactAgent(params);\n}\n\n// Re-export types and utilities\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport * from \"./nodes/types.js\";\nexport type { JumpToTarget } from \"./constants.js\";\nexport type { Runtime } from \"./runtime.js\";\nexport {\n toolStrategy,\n providerStrategy,\n ToolStrategy,\n ProviderStrategy,\n type TypedToolStrategy,\n type ResponseFormat,\n type ResponseFormatUndefined,\n} from \"./responses.js\";\nexport { createMiddleware } from \"./middleware.js\";\nexport { omitPayload, type TracePolicy } from \"@langchain/langgraph\";\nexport { MIDDLEWARE_BRAND } from \"./middleware/types.js\";\nexport type * from \"./middleware/types.js\";\nexport { FakeToolCallingModel } from \"./tests/utils.js\";\nexport type { ReactAgent } from \"./ReactAgent.js\";\nexport {\n createToolCallTransformer,\n createSubagentTransformer,\n type AgentRunStream,\n type ToolCallStreamUnion,\n type SubagentRunStream,\n} from \"./transformers/index.js\";\n"],"mappings":";;;;;;;;;;;AA+pBA,SAAgB,YAad,QAeA;CACA,OAAO,IAAI,WAAW,MAAM;AAC9B"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/agents/index.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type {\n StateDefinitionInit,\n StreamTransformer,\n} from \"@langchain/langgraph\";\n\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nimport type {\n CreateAgentParams,\n AgentTypeConfig,\n CombineTools,\n CombineStreamTransformers,\n} from \"./types.js\";\nimport type {\n AnyAgentMiddleware,\n AnyAnnotationRoot,\n} from \"./middleware/types.js\";\nimport type { ExtractZodArrayTypes } from \"./types.js\";\nimport type { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools\n * and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively\n * work towards solutions.\n *\n * The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively\n * work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state\n * across interactions, and provide auditable decision processes.\n *\n * ## Core Components\n *\n * ### Model\n * The reasoning engine can be specified as:\n * - **String identifier**: `\"openai:gpt-4o\"` for simple setup\n * - **Model instance**: Configured model object for full control\n * - **Dynamic function**: Select models at runtime based on state\n *\n * ### Tools\n * Tools give agents the ability to take actions:\n * - Pass an array of tools created with the `tool` function\n * - Or provide a configured `ToolNode` for custom error handling\n *\n * ### Prompt\n * Shape how your agent approaches tasks:\n * - String for simple instructions\n * - SystemMessage for structured prompts\n * - Function for dynamic prompts based on state\n *\n * ### Middleware\n * Middleware allows you to extend the agent's behavior:\n * - Add pre/post-model processing for context injection or validation\n * - Add dynamic control flows, e.g. terminate invocation or retries\n * - Add human-in-the-loop capabilities\n * - Add tool calls to the agent\n * - Add tool results to the agent\n *\n * ## Advanced Features\n *\n * - **Structured Output**: Use `responseFormat` with a Zod schema to get typed responses\n * - **Memory**: Extend the state schema to remember information across interactions\n * - **Streaming**: Get real-time updates as the agent processes\n *\n * @param options - Configuration options for the agent\n * @param options.llm - The language model as an instance of a chat model\n * @param options.model - The language model as a string identifier, see more in {@link https://docs.langchain.com/oss/javascript/langchain/models#basic-usage | Models}.\n * @param options.tools - Array of tools or configured ToolNode\n * @param options.prompt - System instructions (string, SystemMessage, or function)\n * @param options.responseFormat - Zod schema for structured output\n * @param options.stateSchema - Custom state schema for memory\n * @param options.middleware - Array of middleware for extending agent behavior, see more in {@link https://docs.langchain.com/oss/javascript/langchain/middleware | Middleware}.\n *\n * @returns A ReactAgent instance with `invoke` and `stream` methods\n *\n * @example Basic agent with tools\n * ```ts\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const search = tool(\n * ({ query }) => `Results for: ${query}`,\n * {\n * name: \"search\",\n * description: \"Search for information\",\n * schema: z.object({\n * query: z.string().describe(\"The search query\"),\n * })\n * }\n * );\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [search],\n * });\n *\n * const result = await agent.invoke({\n * messages: [{ role: \"user\", content: \"Search for ReAct agents\" }],\n * });\n * ```\n *\n * @example Structured output\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const ContactInfo = z.object({\n * name: z.string(),\n * email: z.string(),\n * phone: z.string(),\n * });\n *\n * const agent = createAgent({\n * llm: \"openai:gpt-4o\",\n * tools: [],\n * responseFormat: ContactInfo,\n * });\n *\n * const result = await agent.invoke({\n * messages: [{\n * role: \"user\",\n * content: \"Extract: John Doe, john@example.com, (555) 123-4567\"\n * }],\n * });\n *\n * console.log(result.structuredResponse);\n * // { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }\n * ```\n *\n * @example Streaming responses\n * ```ts\n * const stream = await agent.stream(\n * { messages: [{ role: \"user\", content: \"What's the weather?\" }] },\n * { streamMode: \"values\" }\n * );\n *\n * for await (const chunk of stream) {\n * // ...\n * }\n * ```\n *\n * @example With StateSchema\n * ```ts\n * import { createAgent } from \"langchain\";\n * import { StateSchema, ReducedValue } from \"@langchain/langgraph\";\n * import { z } from \"zod\";\n *\n * const AgentState = new StateSchema({\n * userId: z.string(),\n * count: z.number().default(0),\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * { inputSchema: z.string(), reducer: (c, n) => [...c, n] }\n * ),\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [searchTool],\n * stateSchema: AgentState,\n * });\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n InteropZodType<StructuredResponseFormat>\n > & {\n responseFormat: InteropZodType<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n StructuredResponseFormat extends readonly InteropZodType<any>[],\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n StructuredResponseFormat\n > & {\n responseFormat: StructuredResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ExtractZodArrayTypes<StructuredResponseFormat> extends Record<string, any>\n ? ExtractZodArrayTypes<StructuredResponseFormat>\n : Record<string, any>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 6: With responseFormat as single SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema\n > & {\n responseFormat: SerializableSchema;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 7: With responseFormat as array of SerializableSchema\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n SerializableSchema[]\n > & {\n responseFormat: SerializableSchema[];\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n Record<string, unknown>,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 8: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TypedToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: TypedToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 9: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ToolStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ToolStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 10: With responseFormat as ProviderStrategy\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ProviderStrategy<StructuredResponseFormat>\n > & {\n responseFormat: ProviderStrategy<StructuredResponseFormat>;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 11: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 12: With responseFormat explicitly undefined\nexport function createAgent<\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: Omit<\n CreateAgentParams<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n ResponseFormatUndefined,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Overload 13: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n TStateSchema extends StateDefinitionInit | undefined = undefined,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject =\n AnyAnnotationRoot,\n const TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n const TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n const TStreamTransformers extends ReadonlyArray<\n () => StreamTransformer<any>\n > = readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middleware?: TMiddleware;\n tools?: TTools;\n streamTransformers?: TStreamTransformers;\n }\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n TStateSchema extends StateDefinitionInit,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddleware extends readonly AnyAgentMiddleware[] =\n readonly AnyAgentMiddleware[],\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n readonly [],\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n any\n >\n): ReactAgent<\n AgentTypeConfig<\n StructuredResponseFormat,\n TStateSchema,\n ContextSchema,\n TMiddleware,\n CombineTools<TTools, TMiddleware>,\n CombineStreamTransformers<TStreamTransformers, TMiddleware>\n >\n> {\n return new ReactAgent(params);\n}\n\n// Re-export types and utilities\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport * from \"./nodes/types.js\";\nexport type { JumpToTarget } from \"./constants.js\";\nexport type { Runtime } from \"./runtime.js\";\nexport {\n toolStrategy,\n providerStrategy,\n ToolStrategy,\n ProviderStrategy,\n type TypedToolStrategy,\n type ResponseFormat,\n type ResponseFormatUndefined,\n} from \"./responses.js\";\nexport { createMiddleware } from \"./middleware.js\";\nexport { MIDDLEWARE_BRAND } from \"./middleware/types.js\";\nexport type * from \"./middleware/types.js\";\nexport { FakeToolCallingModel } from \"./tests/utils.js\";\nexport type { ReactAgent } from \"./ReactAgent.js\";\nexport {\n createToolCallTransformer,\n createSubagentTransformer,\n type AgentRunStream,\n type ToolCallStreamUnion,\n type SubagentRunStream,\n} from \"./transformers/index.js\";\n"],"mappings":";;;;;;;;;;AA+pBA,SAAgB,YAad,QAeA;CACA,OAAO,IAAI,WAAW,MAAM;AAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","names":[],"sources":["../../../src/agents/middleware/types.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodDefault,\n InteropZodOptional,\n InferInteropZodInput,\n InferInteropZodOutput,\n} from \"@langchain/core/utils/types\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport type {\n AnnotationRoot,\n StateSchema,\n InferStateSchemaValue,\n InferStateSchemaUpdate,\n StateDefinitionInit,\n} from \"@langchain/langgraph\";\nimport type {\n AIMessage,\n SystemMessage,\n ToolMessage,\n} from \"@langchain/core/messages\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type {\n Command,\n StreamTransformer,\n TracePolicy,\n} from \"@langchain/langgraph\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\n\nimport type { JumpToTarget } from \"../constants.js\";\nimport type { Runtime, AgentBuiltInState } from \"../runtime.js\";\nimport type { ModelRequest } from \"../nodes/types.js\";\n\ntype PromiseOrValue<T> = T | Promise<T>;\n\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n\n/**\n * Type bag that encapsulates all middleware type parameters.\n *\n * This interface bundles all the generic type parameters used throughout the middleware system\n * into a single configuration object. This pattern simplifies type signatures and makes\n * it easier to add new type parameters without changing multiple function signatures.\n *\n * @typeParam TSchema - The middleware state schema type. Can be a `StateDefinitionInit`\n * (including `InteropZodObject`, `StateSchema`, or `AnnotationRoot`) or `undefined`.\n *\n * @typeParam TContextSchema - The middleware context schema type. Can be an `InteropZodObject`,\n * `InteropZodDefault`, `InteropZodOptional`, or `undefined`.\n *\n * @typeParam TFullContext - The full context type available to middleware hooks.\n *\n * @typeParam TTools - The tools array type registered by the middleware.\n *\n * @typeParam TStreamTransformers - The stream transformer factories registered\n * by the middleware.\n *\n * @example\n * ```typescript\n * // Define a type configuration\n * type MyMiddlewareTypes = MiddlewareTypeConfig<\n * typeof myStateSchema,\n * typeof myContextSchema,\n * MyContextType,\n * typeof myTools\n * >;\n * ```\n */\nexport interface MiddlewareTypeConfig<\n TSchema extends StateDefinitionInit | undefined =\n | StateDefinitionInit\n | undefined,\n TContextSchema extends\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined =\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined,\n TFullContext = any,\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n ReadonlyArray<() => StreamTransformer<any>>,\n> {\n /** The middleware state schema type */\n Schema: TSchema;\n /** The middleware context schema type */\n ContextSchema: TContextSchema;\n /** The full context type */\n FullContext: TFullContext;\n /** The tools array type */\n Tools: TTools;\n /** The stream transformer factories registered by the middleware */\n StreamTransformers: TStreamTransformers;\n}\n\n/**\n * Default type configuration for middleware.\n * Used when no explicit type parameters are provided.\n */\nexport type DefaultMiddlewareTypeConfig = MiddlewareTypeConfig;\n\nexport type InferSchemaValueType<TSchema> = [TSchema] extends [never]\n ? AgentBuiltInState\n : TSchema extends StateSchema<infer TFields>\n ? InferStateSchemaValue<TFields> & AgentBuiltInState\n : TSchema extends InteropZodObject\n ? InferInteropZodOutput<TSchema> & AgentBuiltInState\n : TSchema extends StateDefinitionInit\n ? InferSchemaValue<TSchema> & AgentBuiltInState\n : AgentBuiltInState;\n\nexport type InferSchemaUpdateType<TSchema> = [TSchema] extends [never]\n ? AgentBuiltInState\n : TSchema extends StateSchema<infer TFields>\n ? InferStateSchemaUpdate<TFields> & AgentBuiltInState\n : TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema> & AgentBuiltInState\n : TSchema extends StateDefinitionInit\n ? InferSchemaInput<TSchema> & AgentBuiltInState\n : AgentBuiltInState;\n\nexport type NormalizedSchemaInput<\n TSchema extends StateDefinitionInit | undefined | never = any,\n> = InferSchemaValueType<TSchema>;\n\nexport type NormalizedSchemaUpdate<\n TSchema extends StateDefinitionInit | undefined | never = any,\n> = InferSchemaUpdateType<TSchema>;\n\n/**\n * Result type for middleware functions.\n */\nexport type MiddlewareResult<TState> =\n | (TState & {\n jumpTo?: JumpToTarget;\n })\n | void;\n\n/**\n * Represents a tool call request for the wrapToolCall hook.\n * Contains the tool call information along with the agent's current state and runtime.\n */\nexport interface ToolCallRequest<\n TState extends Record<string, unknown> = Record<string, unknown>,\n TContext = unknown,\n> {\n /**\n * The tool call to be executed\n */\n toolCall: ToolCall;\n /**\n * The BaseTool instance being invoked.\n * Provides access to tool metadata like name, description, schema, etc.\n *\n * This will be `undefined` for dynamically registered tools that aren't\n * declared upfront when creating the agent. In such cases, middleware\n * should provide the tool implementation by spreading the request with\n * the tool property.\n *\n * @example Dynamic tool handling\n * ```ts\n * wrapToolCall: async (request, handler) => {\n * if (request.toolCall.name === \"dynamic_tool\" && !request.tool) {\n * // Provide the tool implementation for dynamically registered tools\n * return handler({ ...request, tool: myDynamicTool });\n * }\n * return handler(request);\n * }\n * ```\n */\n tool: ClientTool | ServerTool | undefined;\n /**\n * The current agent state (includes both middleware state and built-in state).\n */\n state: TState & AgentBuiltInState;\n /**\n * The runtime context containing metadata, signal, writer, interrupt, etc.\n */\n runtime: Runtime<TContext>;\n}\n\n/**\n * Handler function type for wrapping tool calls.\n * Takes a tool call request and returns the tool result or a command.\n */\nexport type ToolCallHandler<\n TSchema extends Record<string, unknown> = AgentBuiltInState,\n TContext = unknown,\n> = (\n request: ToolCallRequest<TSchema, TContext>\n) => PromiseOrValue<ToolMessage | Command>;\n\n/**\n * Wrapper function type for the wrapToolCall hook.\n * Allows middleware to intercept and modify tool execution.\n */\nexport type WrapToolCallHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> = (\n request: ToolCallRequest<NormalizedSchemaInput<TSchema>, TContext>,\n handler: ToolCallHandler<NormalizedSchemaInput<TSchema>, TContext>\n) => PromiseOrValue<ToolMessage | Command>;\n\n/**\n * Handler function type for wrapping model calls.\n * Takes a model request and returns the AI message response.\n *\n * @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime\n * @returns The AI message response from the model\n */\nexport type WrapModelCallHandler<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> = (\n request: Omit<\n ModelRequest<NormalizedSchemaInput<TSchema>, TContext>,\n /**\n * allow to reset the system prompt or system message\n */\n \"systemPrompt\" | \"systemMessage\"\n > & { systemPrompt?: string; systemMessage?: SystemMessage }\n) => PromiseOrValue<AIMessage>;\n\n/**\n * Wrapper function type for the wrapModelCall hook.\n * Allows middleware to intercept and modify model execution.\n * This enables you to:\n * - Modify the request before calling the model (e.g., change system prompt, add/remove tools)\n * - Handle errors and retry with different parameters\n * - Post-process the response\n * - Implement custom caching, logging, or other cross-cutting concerns\n *\n * @param request - The model request containing all parameters needed for the model call\n * @param handler - The function that invokes the model. Call this with a ModelRequest to get the response\n * @returns The AI message response from the model (or a modified version)\n */\nexport type WrapModelCallHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> = (\n request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>,\n handler: WrapModelCallHandler<TSchema, TContext>\n) => PromiseOrValue<AIMessage | Command>;\n\n/**\n * Handler function type for the beforeAgent hook.\n * Called once at the start of agent invocation before any model calls or tool executions.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype BeforeAgentHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the beforeAgent lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called once at the start of the agent invocation.\n */\nexport type BeforeAgentHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | BeforeAgentHandler<TSchema, TContext>\n | {\n hook: BeforeAgentHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Handler function type for the beforeModel hook.\n * Called before the model is invoked and before the wrapModelCall hook.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype BeforeModelHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the beforeModel lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called before each model invocation.\n */\nexport type BeforeModelHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | BeforeModelHandler<TSchema, TContext>\n | {\n hook: BeforeModelHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Handler function type for the afterModel hook.\n * Called after the model is invoked and before any tools are called.\n * Allows modifying the agent state after model invocation, e.g., to update tool call parameters.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype AfterModelHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the afterModel lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called after each model invocation.\n */\nexport type AfterModelHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | AfterModelHandler<TSchema, TContext>\n | {\n hook: AfterModelHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Handler function type for the afterAgent hook.\n * Called once at the end of agent invocation after all model calls and tool executions are complete.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype AfterAgentHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the afterAgent lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called once at the end of the agent invocation.\n */\nexport type AfterAgentHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | AfterAgentHandler<TSchema, TContext>\n | {\n hook: AfterAgentHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Unique symbol used to brand middleware instances.\n * This prevents functions from being accidentally assignable to AgentMiddleware\n * since functions have a 'name' property that would otherwise make them structurally compatible.\n */\nexport const MIDDLEWARE_BRAND: symbol = Symbol.for(\"AgentMiddleware\");\n\n/**\n * Widened middleware type for agent configuration arrays. Accepts middleware\n * instances with any registered tools or stream transformers while preserving\n * precise inference when middleware arrays are passed with `const`.\n */\nexport type AnyAgentMiddleware = AgentMiddleware<\n StateDefinitionInit | undefined,\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined,\n any,\n readonly (ClientTool | ServerTool)[],\n ReadonlyArray<() => StreamTransformer<any>>\n>;\n\n/**\n * Base middleware interface.\n *\n * @typeParam TSchema - The middleware state schema type\n * @typeParam TContextSchema - The middleware context schema type\n * @typeParam TFullContext - The full context type available to hooks\n * @typeParam TTools - The tools array type registered by the middleware\n * @typeParam TStreamTransformers - The stream transformer factories registered\n * by the middleware\n *\n * @example\n * ```typescript\n * const middleware = createMiddleware({\n * name: \"myMiddleware\",\n * stateSchema: z.object({ count: z.number() }),\n * tools: [myTool],\n * });\n * ```\n */\nexport interface AgentMiddleware<\n TSchema extends StateDefinitionInit | undefined = any,\n TContextSchema extends\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined = any,\n TFullContext = any,\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n ReadonlyArray<() => StreamTransformer<any>>,\n> {\n /**\n * Brand property to distinguish middleware instances from plain objects or functions.\n * This is required and prevents accidental assignment of functions to middleware arrays.\n */\n readonly [MIDDLEWARE_BRAND]: true;\n\n /**\n * Type marker for extracting the MiddlewareTypeConfig from a middleware instance.\n * This is a phantom property used only for type inference.\n * @internal\n */\n readonly \"~middlewareTypes\"?: MiddlewareTypeConfig<\n TSchema,\n TContextSchema,\n TFullContext,\n TTools,\n TStreamTransformers\n >;\n\n /**\n * The name of the middleware.\n */\n name: string;\n\n /**\n * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:\n * - A Zod object (InteropZodObject)\n * - A StateSchema from LangGraph (supports ReducedValue, UntrackedValue)\n * - An AnnotationRoot\n * - Undefined\n */\n stateSchema?: TSchema;\n\n /**\n * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n contextSchema?: TContextSchema;\n\n /**\n * Additional tools registered by the middleware.\n */\n tools?: TTools;\n\n /**\n * Stream transformer factories registered by the middleware.\n * These are merged with `createAgent({ streamTransformers })` when the agent\n * is compiled.\n */\n streamTransformers?: TStreamTransformers;\n\n /**\n * Controls the payloads recorded by this middleware's lifecycle hook spans.\n * Processors affect chain callback payloads, including `streamEvents`; output\n * omission can suppress messages directly returned by a lifecycle hook, and\n * input omission can affect message deduplication. They do not affect execution.\n *\n * @example\n * ```ts\n * import { createMiddleware, omitPayload } from \"langchain\";\n *\n * const middleware = createMiddleware({\n * name: \"PrivateMiddleware\",\n * tracePolicy: { processInputs: omitPayload },\n * beforeModel: () => undefined,\n * });\n * ```\n */\n tracePolicy?: TracePolicy;\n\n /**\n * Wraps tool execution with custom logic. This allows you to:\n * - Modify tool call parameters before execution\n * - Handle errors and retry with different parameters\n * - Post-process tool results\n * - Implement caching, logging, authentication, or other cross-cutting concerns\n * - Return Command objects for advanced control flow\n *\n * The handler receives a ToolCallRequest containing the tool call, state, and runtime,\n * along with a handler function to execute the actual tool.\n *\n * @param request - The tool call request containing toolCall, state, and runtime.\n * @param handler - The function that executes the tool. Call this with a ToolCallRequest to get the result.\n * @returns The tool result as a ToolMessage or a Command for advanced control flow.\n *\n * @example\n * ```ts\n * wrapToolCall: async (request, handler) => {\n * console.log(`Calling tool: ${request.tool.name}`);\n * console.log(`Tool description: ${request.tool.description}`);\n *\n * try {\n * // Execute the tool\n * const result = await handler(request);\n * console.log(`Tool ${request.tool.name} succeeded`);\n * return result;\n * } catch (error) {\n * console.error(`Tool ${request.tool.name} failed:`, error);\n * // Could return a custom error message or retry\n * throw error;\n * }\n * }\n * ```\n *\n * @example Authentication\n * ```ts\n * wrapToolCall: async (request, handler) => {\n * // Check if user is authorized for this tool\n * if (!request.runtime.context.isAuthorized(request.tool.name)) {\n * return new ToolMessage({\n * content: \"Unauthorized to call this tool\",\n * tool_call_id: request.toolCall.id,\n * });\n * }\n * return handler(request);\n * }\n * ```\n *\n * @example Caching\n * ```ts\n * const cache = new Map();\n * wrapToolCall: async (request, handler) => {\n * const cacheKey = `${request.tool.name}:${JSON.stringify(request.toolCall.args)}`;\n * if (cache.has(cacheKey)) {\n * return cache.get(cacheKey);\n * }\n * const result = await handler(request);\n * cache.set(cacheKey, result);\n * return result;\n * }\n * ```\n */\n wrapToolCall?: WrapToolCallHook<TSchema, TFullContext>;\n\n /**\n * Wraps the model invocation with custom logic. This allows you to:\n * - Modify the request before calling the model\n * - Handle errors and retry with different parameters\n * - Post-process the response\n * - Implement custom caching, logging, or other cross-cutting concerns\n *\n * @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime.\n * @param handler - The function that invokes the model. Call this with a ModelRequest to get the response.\n * @returns The response from the model (or a modified version).\n *\n * @example\n * ```ts\n * wrapModelCall: async (request, handler) => {\n * // Modify request before calling\n * const modifiedRequest = { ...request, systemPrompt: \"You are helpful\" };\n *\n * try {\n * // Call the model\n * return await handler(modifiedRequest);\n * } catch (error) {\n * // Handle errors and retry with fallback\n * const fallbackRequest = { ...request, model: fallbackModel };\n * return await handler(fallbackRequest);\n * }\n * }\n * ```\n */\n wrapModelCall?: WrapModelCallHook<TSchema, TFullContext>;\n\n /**\n * The function to run before the agent execution starts. This function is called once at the start of the agent invocation.\n * It allows to modify the state of the agent before any model calls or tool executions.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeAgent?: BeforeAgentHook<TSchema, TFullContext>;\n\n /**\n * The function to run before the model call. This function is called before the model is invoked and before the `wrapModelCall` hook.\n * It allows to modify the state of the agent.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeModel?: BeforeModelHook<TSchema, TFullContext>;\n\n /**\n * The function to run after the model call. This function is called after the model is invoked and before any tools are called.\n * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterModel?: AfterModelHook<TSchema, TFullContext>;\n\n /**\n * The function to run after the agent execution completes. This function is called once at the end of the agent invocation.\n * It allows to modify the final state of the agent after all model calls and tool executions are complete.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterAgent?: AfterAgentHook<TSchema, TFullContext>;\n}\n\n/**\n * Helper type to filter out properties that start with underscore (private properties)\n */\ntype FilterPrivateProps<T> = {\n [K in keyof T as K extends `_${string}` ? never : K]: T[K];\n};\n\n/**\n * Helper type to resolve a MiddlewareTypeConfig from either:\n * - A MiddlewareTypeConfig directly\n * - An AgentMiddleware instance (using `typeof middleware`)\n */\nexport type ResolveMiddlewareTypeConfig<T> = T extends {\n \"~middlewareTypes\"?: infer Types;\n}\n ? Types extends MiddlewareTypeConfig\n ? Types\n : never\n : T extends MiddlewareTypeConfig\n ? T\n : never;\n\n/**\n * Helper type to extract any property from a MiddlewareTypeConfig or AgentMiddleware.\n *\n * @typeParam T - The MiddlewareTypeConfig or AgentMiddleware to extract from\n * @typeParam K - The property key to extract (\"Schema\" | \"ContextSchema\" | \"FullContext\" | \"Tools\" | \"StreamTransformers\")\n */\nexport type InferMiddlewareType<\n T,\n K extends keyof MiddlewareTypeConfig,\n> = ResolveMiddlewareTypeConfig<T>[K];\n\n/**\n * Shorthand helper to extract the Schema type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareSchema<T> = InferMiddlewareType<T, \"Schema\">;\n\n/**\n * Shorthand helper to extract the ContextSchema type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareContextSchema<T> = InferMiddlewareType<\n T,\n \"ContextSchema\"\n>;\n\n/**\n * Shorthand helper to extract the FullContext type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareFullContext<T> = InferMiddlewareType<\n T,\n \"FullContext\"\n>;\n\n/**\n * Shorthand helper to extract the Tools type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareToolsFromConfig<T> = InferMiddlewareType<T, \"Tools\">;\n\n/**\n * Shorthand helper to extract the StreamTransformers type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareStreamTransformersFromConfig<T> =\n InferMiddlewareType<T, \"StreamTransformers\">;\n\nexport type InferChannelType<T extends AnyAnnotationRoot | InteropZodObject> =\n T extends AnyAnnotationRoot\n ? ToAnnotationRoot<T>[\"State\"]\n : T extends InteropZodObject\n ? InferInteropZodInput<T>\n : {};\n\n/**\n * Helper type to infer the state schema type from a middleware\n * This filters out private properties (those starting with underscore)\n * Supports both Zod schemas (InteropZodObject) and StateSchema from LangGraph\n */\nexport type InferMiddlewareState<T extends AgentMiddleware> =\n T extends AgentMiddleware<infer TSchema, any, any, any, any>\n ? TSchema extends StateSchema<infer TFields>\n ? FilterPrivateProps<InferStateSchemaValue<TFields>>\n : TSchema extends InteropZodObject\n ? FilterPrivateProps<InferInteropZodOutput<TSchema>>\n : TSchema extends StateDefinitionInit\n ? FilterPrivateProps<InferSchemaValue<TSchema>>\n : {}\n : {};\n\n/**\n * Helper type to infer the input state schema type from a middleware (all properties optional)\n * This filters out private properties (those starting with underscore)\n * Supports both Zod schemas (InteropZodObject) and StateSchema from LangGraph\n */\nexport type InferMiddlewareInputState<T extends AgentMiddleware> =\n T extends AgentMiddleware<infer TSchema, any, any, any, any>\n ? TSchema extends StateSchema<infer TFields>\n ? FilterPrivateProps<InferStateSchemaUpdate<TFields>>\n : TSchema extends InteropZodObject\n ? FilterPrivateProps<InferInteropZodInput<TSchema>>\n : TSchema extends StateDefinitionInit\n ? FilterPrivateProps<InferSchemaInput<TSchema>>\n : {}\n : {};\n\n/**\n * Helper type to infer merged state from an array of middleware (just the middleware states)\n */\nexport type InferMiddlewareStates<T extends readonly AnyAgentMiddleware[]> =\n T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? InferMiddlewareState<First> & InferMiddlewareStates<Rest>\n : InferMiddlewareState<First>\n : {}\n : {};\n\n/**\n * Helper type to infer merged input state from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareInputStates<\n T extends readonly AnyAgentMiddleware[],\n> = T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? InferMiddlewareInputState<First> & InferMiddlewareInputStates<Rest>\n : InferMiddlewareInputState<First>\n : {}\n : {};\n\n/**\n * Helper type to infer merged state from an array of middleware (includes built-in state)\n */\nexport type InferMergedState<T extends readonly AnyAgentMiddleware[]> =\n InferMiddlewareStates<T> & AgentBuiltInState;\n\n/**\n * Helper type to infer merged input state from an array of middleware (includes built-in state)\n */\nexport type InferMergedInputState<T extends readonly AnyAgentMiddleware[]> =\n InferMiddlewareInputStates<T> & AgentBuiltInState;\n\n/**\n * Helper type to infer the context schema type from a middleware\n */\nexport type InferMiddlewareContext<T extends AgentMiddleware> =\n T extends AgentMiddleware<any, infer TContextSchema, any, any, any>\n ? TContextSchema extends InteropZodObject\n ? InferInteropZodInput<TContextSchema>\n : {}\n : {};\n\n/**\n * Helper type to infer the input context schema type from a middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInput<T extends AgentMiddleware> =\n T extends AgentMiddleware<any, infer TContextSchema, any, any, any>\n ? TContextSchema extends InteropZodOptional<infer Inner>\n ? InferInteropZodInput<Inner> | undefined\n : TContextSchema extends InteropZodObject\n ? InferInteropZodInput<TContextSchema>\n : {}\n : {};\n\n/**\n * Helper type to infer merged context from an array of middleware\n */\nexport type InferMiddlewareContexts<T extends readonly AnyAgentMiddleware[]> =\n T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? InferMiddlewareContext<First> & InferMiddlewareContexts<Rest>\n : InferMiddlewareContext<First>\n : {}\n : {};\n\n/**\n * Helper to merge two context types, preserving undefined unions\n */\ntype MergeContextTypes<A, B> = [A] extends [undefined]\n ? [B] extends [undefined]\n ? undefined\n : B | undefined\n : [B] extends [undefined]\n ? A | undefined\n : [A] extends [B]\n ? A\n : [B] extends [A]\n ? B\n : A & B;\n\n/**\n * Helper type to infer merged input context from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInputs<\n T extends readonly AnyAgentMiddleware[],\n> = T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? MergeContextTypes<\n InferMiddlewareContextInput<First>,\n InferMiddlewareContextInputs<Rest>\n >\n : InferMiddlewareContextInput<First>\n : {}\n : {};\n\n/**\n * Helper type to extract input type from context schema (with optional defaults)\n */\nexport type InferContextInput<\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n> = ContextSchema extends InteropZodObject\n ? InferInteropZodInput<ContextSchema>\n : ContextSchema extends AnyAnnotationRoot\n ? ToAnnotationRoot<ContextSchema>[\"State\"]\n : {};\n\nexport type ToAnnotationRoot<A extends StateDefinitionInit> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? InteropZodToStateDefinition<A>\n : never;\n\nexport type InferSchemaValue<A extends StateDefinitionInit | undefined> = [\n A,\n] extends [undefined]\n ? {}\n : A extends StateSchema<infer TFields>\n ? InferStateSchemaValue<TFields>\n : A extends InteropZodObject\n ? InferInteropZodOutput<A>\n : A extends AnyAnnotationRoot\n ? A[\"State\"]\n : {};\n\nexport type InferSchemaInput<A extends StateDefinitionInit | undefined> = [\n A,\n] extends [undefined]\n ? {}\n : A extends StateSchema<infer TFields>\n ? InferStateSchemaUpdate<TFields>\n : A extends InteropZodObject\n ? InferInteropZodInput<A>\n : A extends AnyAnnotationRoot\n ? A[\"Update\"]\n : {};\n"],"mappings":";;;;;;AAiXA,MAAa,mBAA2B,OAAO,IAAI,iBAAiB"}
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../../../src/agents/middleware/types.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodDefault,\n InteropZodOptional,\n InferInteropZodInput,\n InferInteropZodOutput,\n} from \"@langchain/core/utils/types\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport type {\n AnnotationRoot,\n StateSchema,\n InferStateSchemaValue,\n InferStateSchemaUpdate,\n StateDefinitionInit,\n} from \"@langchain/langgraph\";\nimport type {\n AIMessage,\n SystemMessage,\n ToolMessage,\n} from \"@langchain/core/messages\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { Command, StreamTransformer } from \"@langchain/langgraph\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\n\nimport type { JumpToTarget } from \"../constants.js\";\nimport type { Runtime, AgentBuiltInState } from \"../runtime.js\";\nimport type { ModelRequest } from \"../nodes/types.js\";\n\ntype PromiseOrValue<T> = T | Promise<T>;\n\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n\n/**\n * Type bag that encapsulates all middleware type parameters.\n *\n * This interface bundles all the generic type parameters used throughout the middleware system\n * into a single configuration object. This pattern simplifies type signatures and makes\n * it easier to add new type parameters without changing multiple function signatures.\n *\n * @typeParam TSchema - The middleware state schema type. Can be a `StateDefinitionInit`\n * (including `InteropZodObject`, `StateSchema`, or `AnnotationRoot`) or `undefined`.\n *\n * @typeParam TContextSchema - The middleware context schema type. Can be an `InteropZodObject`,\n * `InteropZodDefault`, `InteropZodOptional`, or `undefined`.\n *\n * @typeParam TFullContext - The full context type available to middleware hooks.\n *\n * @typeParam TTools - The tools array type registered by the middleware.\n *\n * @typeParam TStreamTransformers - The stream transformer factories registered\n * by the middleware.\n *\n * @example\n * ```typescript\n * // Define a type configuration\n * type MyMiddlewareTypes = MiddlewareTypeConfig<\n * typeof myStateSchema,\n * typeof myContextSchema,\n * MyContextType,\n * typeof myTools\n * >;\n * ```\n */\nexport interface MiddlewareTypeConfig<\n TSchema extends StateDefinitionInit | undefined =\n | StateDefinitionInit\n | undefined,\n TContextSchema extends\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined =\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined,\n TFullContext = any,\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n ReadonlyArray<() => StreamTransformer<any>>,\n> {\n /** The middleware state schema type */\n Schema: TSchema;\n /** The middleware context schema type */\n ContextSchema: TContextSchema;\n /** The full context type */\n FullContext: TFullContext;\n /** The tools array type */\n Tools: TTools;\n /** The stream transformer factories registered by the middleware */\n StreamTransformers: TStreamTransformers;\n}\n\n/**\n * Default type configuration for middleware.\n * Used when no explicit type parameters are provided.\n */\nexport type DefaultMiddlewareTypeConfig = MiddlewareTypeConfig;\n\nexport type InferSchemaValueType<TSchema> = [TSchema] extends [never]\n ? AgentBuiltInState\n : TSchema extends StateSchema<infer TFields>\n ? InferStateSchemaValue<TFields> & AgentBuiltInState\n : TSchema extends InteropZodObject\n ? InferInteropZodOutput<TSchema> & AgentBuiltInState\n : TSchema extends StateDefinitionInit\n ? InferSchemaValue<TSchema> & AgentBuiltInState\n : AgentBuiltInState;\n\nexport type InferSchemaUpdateType<TSchema> = [TSchema] extends [never]\n ? AgentBuiltInState\n : TSchema extends StateSchema<infer TFields>\n ? InferStateSchemaUpdate<TFields> & AgentBuiltInState\n : TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema> & AgentBuiltInState\n : TSchema extends StateDefinitionInit\n ? InferSchemaInput<TSchema> & AgentBuiltInState\n : AgentBuiltInState;\n\nexport type NormalizedSchemaInput<\n TSchema extends StateDefinitionInit | undefined | never = any,\n> = InferSchemaValueType<TSchema>;\n\nexport type NormalizedSchemaUpdate<\n TSchema extends StateDefinitionInit | undefined | never = any,\n> = InferSchemaUpdateType<TSchema>;\n\n/**\n * Result type for middleware functions.\n */\nexport type MiddlewareResult<TState> =\n | (TState & {\n jumpTo?: JumpToTarget;\n })\n | void;\n\n/**\n * Represents a tool call request for the wrapToolCall hook.\n * Contains the tool call information along with the agent's current state and runtime.\n */\nexport interface ToolCallRequest<\n TState extends Record<string, unknown> = Record<string, unknown>,\n TContext = unknown,\n> {\n /**\n * The tool call to be executed\n */\n toolCall: ToolCall;\n /**\n * The BaseTool instance being invoked.\n * Provides access to tool metadata like name, description, schema, etc.\n *\n * This will be `undefined` for dynamically registered tools that aren't\n * declared upfront when creating the agent. In such cases, middleware\n * should provide the tool implementation by spreading the request with\n * the tool property.\n *\n * @example Dynamic tool handling\n * ```ts\n * wrapToolCall: async (request, handler) => {\n * if (request.toolCall.name === \"dynamic_tool\" && !request.tool) {\n * // Provide the tool implementation for dynamically registered tools\n * return handler({ ...request, tool: myDynamicTool });\n * }\n * return handler(request);\n * }\n * ```\n */\n tool: ClientTool | ServerTool | undefined;\n /**\n * The current agent state (includes both middleware state and built-in state).\n */\n state: TState & AgentBuiltInState;\n /**\n * The runtime context containing metadata, signal, writer, interrupt, etc.\n */\n runtime: Runtime<TContext>;\n}\n\n/**\n * Handler function type for wrapping tool calls.\n * Takes a tool call request and returns the tool result or a command.\n */\nexport type ToolCallHandler<\n TSchema extends Record<string, unknown> = AgentBuiltInState,\n TContext = unknown,\n> = (\n request: ToolCallRequest<TSchema, TContext>\n) => PromiseOrValue<ToolMessage | Command>;\n\n/**\n * Wrapper function type for the wrapToolCall hook.\n * Allows middleware to intercept and modify tool execution.\n */\nexport type WrapToolCallHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> = (\n request: ToolCallRequest<NormalizedSchemaInput<TSchema>, TContext>,\n handler: ToolCallHandler<NormalizedSchemaInput<TSchema>, TContext>\n) => PromiseOrValue<ToolMessage | Command>;\n\n/**\n * Handler function type for wrapping model calls.\n * Takes a model request and returns the AI message response.\n *\n * @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime\n * @returns The AI message response from the model\n */\nexport type WrapModelCallHandler<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> = (\n request: Omit<\n ModelRequest<NormalizedSchemaInput<TSchema>, TContext>,\n /**\n * allow to reset the system prompt or system message\n */\n \"systemPrompt\" | \"systemMessage\"\n > & { systemPrompt?: string; systemMessage?: SystemMessage }\n) => PromiseOrValue<AIMessage>;\n\n/**\n * Wrapper function type for the wrapModelCall hook.\n * Allows middleware to intercept and modify model execution.\n * This enables you to:\n * - Modify the request before calling the model (e.g., change system prompt, add/remove tools)\n * - Handle errors and retry with different parameters\n * - Post-process the response\n * - Implement custom caching, logging, or other cross-cutting concerns\n *\n * @param request - The model request containing all parameters needed for the model call\n * @param handler - The function that invokes the model. Call this with a ModelRequest to get the response\n * @returns The AI message response from the model (or a modified version)\n */\nexport type WrapModelCallHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> = (\n request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>,\n handler: WrapModelCallHandler<TSchema, TContext>\n) => PromiseOrValue<AIMessage | Command>;\n\n/**\n * Handler function type for the beforeAgent hook.\n * Called once at the start of agent invocation before any model calls or tool executions.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype BeforeAgentHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the beforeAgent lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called once at the start of the agent invocation.\n */\nexport type BeforeAgentHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | BeforeAgentHandler<TSchema, TContext>\n | {\n hook: BeforeAgentHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Handler function type for the beforeModel hook.\n * Called before the model is invoked and before the wrapModelCall hook.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype BeforeModelHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the beforeModel lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called before each model invocation.\n */\nexport type BeforeModelHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | BeforeModelHandler<TSchema, TContext>\n | {\n hook: BeforeModelHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Handler function type for the afterModel hook.\n * Called after the model is invoked and before any tools are called.\n * Allows modifying the agent state after model invocation, e.g., to update tool call parameters.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype AfterModelHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the afterModel lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called after each model invocation.\n */\nexport type AfterModelHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | AfterModelHandler<TSchema, TContext>\n | {\n hook: AfterModelHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Handler function type for the afterAgent hook.\n * Called once at the end of agent invocation after all model calls and tool executions are complete.\n *\n * @param state - The current agent state (includes both middleware state and built-in state)\n * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.\n * @returns A middleware result containing partial state updates or undefined to pass through\n */\ntype AfterAgentHandler<TSchema, TContext> = (\n state: InferSchemaValueType<TSchema>,\n runtime: Runtime<TContext>\n) => PromiseOrValue<MiddlewareResult<Partial<InferSchemaUpdateType<TSchema>>>>;\n\n/**\n * Hook type for the afterAgent lifecycle event.\n * Can be either a handler function or an object with a handler and optional jump targets.\n * This hook is called once at the end of the agent invocation.\n */\nexport type AfterAgentHook<\n TSchema extends StateDefinitionInit | undefined = undefined,\n TContext = unknown,\n> =\n | AfterAgentHandler<TSchema, TContext>\n | {\n hook: AfterAgentHandler<TSchema, TContext>;\n canJumpTo?: JumpToTarget[];\n };\n\n/**\n * Unique symbol used to brand middleware instances.\n * This prevents functions from being accidentally assignable to AgentMiddleware\n * since functions have a 'name' property that would otherwise make them structurally compatible.\n */\nexport const MIDDLEWARE_BRAND: symbol = Symbol.for(\"AgentMiddleware\");\n\n/**\n * Widened middleware type for agent configuration arrays. Accepts middleware\n * instances with any registered tools or stream transformers while preserving\n * precise inference when middleware arrays are passed with `const`.\n */\nexport type AnyAgentMiddleware = AgentMiddleware<\n StateDefinitionInit | undefined,\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined,\n any,\n readonly (ClientTool | ServerTool)[],\n ReadonlyArray<() => StreamTransformer<any>>\n>;\n\n/**\n * Base middleware interface.\n *\n * @typeParam TSchema - The middleware state schema type\n * @typeParam TContextSchema - The middleware context schema type\n * @typeParam TFullContext - The full context type available to hooks\n * @typeParam TTools - The tools array type registered by the middleware\n * @typeParam TStreamTransformers - The stream transformer factories registered\n * by the middleware\n *\n * @example\n * ```typescript\n * const middleware = createMiddleware({\n * name: \"myMiddleware\",\n * stateSchema: z.object({ count: z.number() }),\n * tools: [myTool],\n * });\n * ```\n */\nexport interface AgentMiddleware<\n TSchema extends StateDefinitionInit | undefined = any,\n TContextSchema extends\n | InteropZodObject\n | InteropZodDefault<InteropZodObject>\n | InteropZodOptional<InteropZodObject>\n | undefined = any,\n TFullContext = any,\n TTools extends readonly (ClientTool | ServerTool)[] = readonly (\n | ClientTool\n | ServerTool\n )[],\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n ReadonlyArray<() => StreamTransformer<any>>,\n> {\n /**\n * Brand property to distinguish middleware instances from plain objects or functions.\n * This is required and prevents accidental assignment of functions to middleware arrays.\n */\n readonly [MIDDLEWARE_BRAND]: true;\n\n /**\n * Type marker for extracting the MiddlewareTypeConfig from a middleware instance.\n * This is a phantom property used only for type inference.\n * @internal\n */\n readonly \"~middlewareTypes\"?: MiddlewareTypeConfig<\n TSchema,\n TContextSchema,\n TFullContext,\n TTools,\n TStreamTransformers\n >;\n\n /**\n * The name of the middleware.\n */\n name: string;\n\n /**\n * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:\n * - A Zod object (InteropZodObject)\n * - A StateSchema from LangGraph (supports ReducedValue, UntrackedValue)\n * - An AnnotationRoot\n * - Undefined\n */\n stateSchema?: TSchema;\n\n /**\n * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n contextSchema?: TContextSchema;\n\n /**\n * Additional tools registered by the middleware.\n */\n tools?: TTools;\n\n /**\n * Stream transformer factories registered by the middleware.\n * These are merged with `createAgent({ streamTransformers })` when the agent\n * is compiled.\n */\n streamTransformers?: TStreamTransformers;\n\n /**\n * Wraps tool execution with custom logic. This allows you to:\n * - Modify tool call parameters before execution\n * - Handle errors and retry with different parameters\n * - Post-process tool results\n * - Implement caching, logging, authentication, or other cross-cutting concerns\n * - Return Command objects for advanced control flow\n *\n * The handler receives a ToolCallRequest containing the tool call, state, and runtime,\n * along with a handler function to execute the actual tool.\n *\n * @param request - The tool call request containing toolCall, state, and runtime.\n * @param handler - The function that executes the tool. Call this with a ToolCallRequest to get the result.\n * @returns The tool result as a ToolMessage or a Command for advanced control flow.\n *\n * @example\n * ```ts\n * wrapToolCall: async (request, handler) => {\n * console.log(`Calling tool: ${request.tool.name}`);\n * console.log(`Tool description: ${request.tool.description}`);\n *\n * try {\n * // Execute the tool\n * const result = await handler(request);\n * console.log(`Tool ${request.tool.name} succeeded`);\n * return result;\n * } catch (error) {\n * console.error(`Tool ${request.tool.name} failed:`, error);\n * // Could return a custom error message or retry\n * throw error;\n * }\n * }\n * ```\n *\n * @example Authentication\n * ```ts\n * wrapToolCall: async (request, handler) => {\n * // Check if user is authorized for this tool\n * if (!request.runtime.context.isAuthorized(request.tool.name)) {\n * return new ToolMessage({\n * content: \"Unauthorized to call this tool\",\n * tool_call_id: request.toolCall.id,\n * });\n * }\n * return handler(request);\n * }\n * ```\n *\n * @example Caching\n * ```ts\n * const cache = new Map();\n * wrapToolCall: async (request, handler) => {\n * const cacheKey = `${request.tool.name}:${JSON.stringify(request.toolCall.args)}`;\n * if (cache.has(cacheKey)) {\n * return cache.get(cacheKey);\n * }\n * const result = await handler(request);\n * cache.set(cacheKey, result);\n * return result;\n * }\n * ```\n */\n wrapToolCall?: WrapToolCallHook<TSchema, TFullContext>;\n\n /**\n * Wraps the model invocation with custom logic. This allows you to:\n * - Modify the request before calling the model\n * - Handle errors and retry with different parameters\n * - Post-process the response\n * - Implement custom caching, logging, or other cross-cutting concerns\n *\n * @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime.\n * @param handler - The function that invokes the model. Call this with a ModelRequest to get the response.\n * @returns The response from the model (or a modified version).\n *\n * @example\n * ```ts\n * wrapModelCall: async (request, handler) => {\n * // Modify request before calling\n * const modifiedRequest = { ...request, systemPrompt: \"You are helpful\" };\n *\n * try {\n * // Call the model\n * return await handler(modifiedRequest);\n * } catch (error) {\n * // Handle errors and retry with fallback\n * const fallbackRequest = { ...request, model: fallbackModel };\n * return await handler(fallbackRequest);\n * }\n * }\n * ```\n */\n wrapModelCall?: WrapModelCallHook<TSchema, TFullContext>;\n\n /**\n * The function to run before the agent execution starts. This function is called once at the start of the agent invocation.\n * It allows to modify the state of the agent before any model calls or tool executions.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeAgent?: BeforeAgentHook<TSchema, TFullContext>;\n\n /**\n * The function to run before the model call. This function is called before the model is invoked and before the `wrapModelCall` hook.\n * It allows to modify the state of the agent.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeModel?: BeforeModelHook<TSchema, TFullContext>;\n\n /**\n * The function to run after the model call. This function is called after the model is invoked and before any tools are called.\n * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterModel?: AfterModelHook<TSchema, TFullContext>;\n\n /**\n * The function to run after the agent execution completes. This function is called once at the end of the agent invocation.\n * It allows to modify the final state of the agent after all model calls and tool executions are complete.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterAgent?: AfterAgentHook<TSchema, TFullContext>;\n}\n\n/**\n * Helper type to filter out properties that start with underscore (private properties)\n */\ntype FilterPrivateProps<T> = {\n [K in keyof T as K extends `_${string}` ? never : K]: T[K];\n};\n\n/**\n * Helper type to resolve a MiddlewareTypeConfig from either:\n * - A MiddlewareTypeConfig directly\n * - An AgentMiddleware instance (using `typeof middleware`)\n */\nexport type ResolveMiddlewareTypeConfig<T> = T extends {\n \"~middlewareTypes\"?: infer Types;\n}\n ? Types extends MiddlewareTypeConfig\n ? Types\n : never\n : T extends MiddlewareTypeConfig\n ? T\n : never;\n\n/**\n * Helper type to extract any property from a MiddlewareTypeConfig or AgentMiddleware.\n *\n * @typeParam T - The MiddlewareTypeConfig or AgentMiddleware to extract from\n * @typeParam K - The property key to extract (\"Schema\" | \"ContextSchema\" | \"FullContext\" | \"Tools\" | \"StreamTransformers\")\n */\nexport type InferMiddlewareType<\n T,\n K extends keyof MiddlewareTypeConfig,\n> = ResolveMiddlewareTypeConfig<T>[K];\n\n/**\n * Shorthand helper to extract the Schema type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareSchema<T> = InferMiddlewareType<T, \"Schema\">;\n\n/**\n * Shorthand helper to extract the ContextSchema type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareContextSchema<T> = InferMiddlewareType<\n T,\n \"ContextSchema\"\n>;\n\n/**\n * Shorthand helper to extract the FullContext type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareFullContext<T> = InferMiddlewareType<\n T,\n \"FullContext\"\n>;\n\n/**\n * Shorthand helper to extract the Tools type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareToolsFromConfig<T> = InferMiddlewareType<T, \"Tools\">;\n\n/**\n * Shorthand helper to extract the StreamTransformers type from a MiddlewareTypeConfig or AgentMiddleware.\n */\nexport type InferMiddlewareStreamTransformersFromConfig<T> =\n InferMiddlewareType<T, \"StreamTransformers\">;\n\nexport type InferChannelType<T extends AnyAnnotationRoot | InteropZodObject> =\n T extends AnyAnnotationRoot\n ? ToAnnotationRoot<T>[\"State\"]\n : T extends InteropZodObject\n ? InferInteropZodInput<T>\n : {};\n\n/**\n * Helper type to infer the state schema type from a middleware\n * This filters out private properties (those starting with underscore)\n * Supports both Zod schemas (InteropZodObject) and StateSchema from LangGraph\n */\nexport type InferMiddlewareState<T extends AgentMiddleware> =\n T extends AgentMiddleware<infer TSchema, any, any, any, any>\n ? TSchema extends StateSchema<infer TFields>\n ? FilterPrivateProps<InferStateSchemaValue<TFields>>\n : TSchema extends InteropZodObject\n ? FilterPrivateProps<InferInteropZodOutput<TSchema>>\n : TSchema extends StateDefinitionInit\n ? FilterPrivateProps<InferSchemaValue<TSchema>>\n : {}\n : {};\n\n/**\n * Helper type to infer the input state schema type from a middleware (all properties optional)\n * This filters out private properties (those starting with underscore)\n * Supports both Zod schemas (InteropZodObject) and StateSchema from LangGraph\n */\nexport type InferMiddlewareInputState<T extends AgentMiddleware> =\n T extends AgentMiddleware<infer TSchema, any, any, any, any>\n ? TSchema extends StateSchema<infer TFields>\n ? FilterPrivateProps<InferStateSchemaUpdate<TFields>>\n : TSchema extends InteropZodObject\n ? FilterPrivateProps<InferInteropZodInput<TSchema>>\n : TSchema extends StateDefinitionInit\n ? FilterPrivateProps<InferSchemaInput<TSchema>>\n : {}\n : {};\n\n/**\n * Helper type to infer merged state from an array of middleware (just the middleware states)\n */\nexport type InferMiddlewareStates<T extends readonly AnyAgentMiddleware[]> =\n T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? InferMiddlewareState<First> & InferMiddlewareStates<Rest>\n : InferMiddlewareState<First>\n : {}\n : {};\n\n/**\n * Helper type to infer merged input state from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareInputStates<\n T extends readonly AnyAgentMiddleware[],\n> = T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? InferMiddlewareInputState<First> & InferMiddlewareInputStates<Rest>\n : InferMiddlewareInputState<First>\n : {}\n : {};\n\n/**\n * Helper type to infer merged state from an array of middleware (includes built-in state)\n */\nexport type InferMergedState<T extends readonly AnyAgentMiddleware[]> =\n InferMiddlewareStates<T> & AgentBuiltInState;\n\n/**\n * Helper type to infer merged input state from an array of middleware (includes built-in state)\n */\nexport type InferMergedInputState<T extends readonly AnyAgentMiddleware[]> =\n InferMiddlewareInputStates<T> & AgentBuiltInState;\n\n/**\n * Helper type to infer the context schema type from a middleware\n */\nexport type InferMiddlewareContext<T extends AgentMiddleware> =\n T extends AgentMiddleware<any, infer TContextSchema, any, any, any>\n ? TContextSchema extends InteropZodObject\n ? InferInteropZodInput<TContextSchema>\n : {}\n : {};\n\n/**\n * Helper type to infer the input context schema type from a middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInput<T extends AgentMiddleware> =\n T extends AgentMiddleware<any, infer TContextSchema, any, any, any>\n ? TContextSchema extends InteropZodOptional<infer Inner>\n ? InferInteropZodInput<Inner> | undefined\n : TContextSchema extends InteropZodObject\n ? InferInteropZodInput<TContextSchema>\n : {}\n : {};\n\n/**\n * Helper type to infer merged context from an array of middleware\n */\nexport type InferMiddlewareContexts<T extends readonly AnyAgentMiddleware[]> =\n T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? InferMiddlewareContext<First> & InferMiddlewareContexts<Rest>\n : InferMiddlewareContext<First>\n : {}\n : {};\n\n/**\n * Helper to merge two context types, preserving undefined unions\n */\ntype MergeContextTypes<A, B> = [A] extends [undefined]\n ? [B] extends [undefined]\n ? undefined\n : B | undefined\n : [B] extends [undefined]\n ? A | undefined\n : [A] extends [B]\n ? A\n : [B] extends [A]\n ? B\n : A & B;\n\n/**\n * Helper type to infer merged input context from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInputs<\n T extends readonly AnyAgentMiddleware[],\n> = T extends readonly []\n ? {}\n : T extends readonly [infer First, ...infer Rest]\n ? First extends AgentMiddleware\n ? Rest extends readonly AnyAgentMiddleware[]\n ? MergeContextTypes<\n InferMiddlewareContextInput<First>,\n InferMiddlewareContextInputs<Rest>\n >\n : InferMiddlewareContextInput<First>\n : {}\n : {};\n\n/**\n * Helper type to extract input type from context schema (with optional defaults)\n */\nexport type InferContextInput<\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n> = ContextSchema extends InteropZodObject\n ? InferInteropZodInput<ContextSchema>\n : ContextSchema extends AnyAnnotationRoot\n ? ToAnnotationRoot<ContextSchema>[\"State\"]\n : {};\n\nexport type ToAnnotationRoot<A extends StateDefinitionInit> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? InteropZodToStateDefinition<A>\n : never;\n\nexport type InferSchemaValue<A extends StateDefinitionInit | undefined> = [\n A,\n] extends [undefined]\n ? {}\n : A extends StateSchema<infer TFields>\n ? InferStateSchemaValue<TFields>\n : A extends InteropZodObject\n ? InferInteropZodOutput<A>\n : A extends AnyAnnotationRoot\n ? A[\"State\"]\n : {};\n\nexport type InferSchemaInput<A extends StateDefinitionInit | undefined> = [\n A,\n] extends [undefined]\n ? {}\n : A extends StateSchema<infer TFields>\n ? InferStateSchemaUpdate<TFields>\n : A extends InteropZodObject\n ? InferInteropZodInput<A>\n : A extends AnyAnnotationRoot\n ? A[\"Update\"]\n : {};\n"],"mappings":";;;;;;AA6WA,MAAa,mBAA2B,OAAO,IAAI,iBAAiB"}
@@ -4,7 +4,7 @@ import { ModelRequest } from "../nodes/types.cjs";
4
4
  import { AIMessage, SystemMessage, ToolMessage } from "@langchain/core/messages";
5
5
  import { ClientTool, ServerTool } from "@langchain/core/tools";
6
6
  import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodObject, InteropZodOptional } from "@langchain/core/utils/types";
7
- import { AnnotationRoot, Command, InferStateSchemaUpdate, InferStateSchemaValue, StateDefinitionInit, StateSchema, StreamTransformer, TracePolicy } from "@langchain/langgraph";
7
+ import { AnnotationRoot, Command, InferStateSchemaUpdate, InferStateSchemaValue, StateDefinitionInit, StateSchema, StreamTransformer } from "@langchain/langgraph";
8
8
  import { ToolCall as ToolCall$1 } from "@langchain/core/messages/tool";
9
9
  import { InteropZodToStateDefinition } from "@langchain/langgraph/zod";
10
10
  //#region src/agents/middleware/types.d.ts
@@ -287,24 +287,6 @@ interface AgentMiddleware<TSchema extends StateDefinitionInit | undefined = any,
287
287
  * is compiled.
288
288
  */
289
289
  streamTransformers?: TStreamTransformers;
290
- /**
291
- * Controls the payloads recorded by this middleware's lifecycle hook spans.
292
- * Processors affect chain callback payloads, including `streamEvents`; output
293
- * omission can suppress messages directly returned by a lifecycle hook, and
294
- * input omission can affect message deduplication. They do not affect execution.
295
- *
296
- * @example
297
- * ```ts
298
- * import { createMiddleware, omitPayload } from "langchain";
299
- *
300
- * const middleware = createMiddleware({
301
- * name: "PrivateMiddleware",
302
- * tracePolicy: { processInputs: omitPayload },
303
- * beforeModel: () => undefined,
304
- * });
305
- * ```
306
- */
307
- tracePolicy?: TracePolicy;
308
290
  /**
309
291
  * Wraps tool execution with custom logic. This allows you to:
310
292
  * - Modify tool call parameters before execution
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../../../src/agents/middleware/types.ts"],"mappings":";;;;;;;;;;KAiCK,eAAe,KAAK,IAAI,QAAQ;KAEzB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiCf,qBACf,gBAAgB,kCACZ,iCAEJ,uBACI,mBACA,kBAAkB,oBAClB,mBAAmB,gCAEnB,mBACA,kBAAkB,oBAClB,mBAAmB,+BAEvB,oBACA,yBAAyB,aAAa,0BAClC,aACA,eAEJ,4BAA4B,oBAAoB,0BAC9C,oBAAoB;;EAGtB,QAAQ;;EAER,eAAe;;EAEf,aAAa;;EAEb,OAAO;;EAEP,oBAAoB;;;;;;KAOV,8BAA8B;KAE9B,qBAAqB,YAAY,2BACzC,oBACA,gBAAgB,kBAAkB,WAChC,sBAAsB,WAAW,oBACjC,gBAAgB,mBACd,sBAAsB,WAAW,oBACjC,gBAAgB,sBACd,iBAAiB,WAAW,oBAC5B;KAEE,sBAAsB,YAAY,2BAC1C,oBACA,gBAAgB,kBAAkB,WAChC,uBAAuB,WAAW,oBAClC,gBAAgB,mBACd,qBAAqB,WAAW,oBAChC,gBAAgB,sBACd,iBAAiB,WAAW,oBAC5B;KAEE,sBACV,gBAAgB,iDACd,qBAAqB;KAEb,uBACV,gBAAgB,iDACd,sBAAsB;;;;KAKd,iBAAiB,WACxB;EACC,SAAS;;;;;;UAQE,gBACf,eAAe,0BAA0B,yBACzC;;;;EAKA,UAAU;;;;;;;;;;;;;;;;;;;;;EAqBV,MAAM,aAAa;;;;EAInB,OAAO,SAAS;;;;EAIhB,SAAS,UAAQ;;;;;;KAOP,gBACV,gBAAgB,0BAA0B,mBAC1C,uBAEA,SAAS,gBAAgB,SAAS,cAC/B,eAAe,cAAc;;;;;KAMtB,iBACV,gBAAgB,6CAChB,uBAEA,SAAS,gBAAgB,sBAAsB,UAAU,WACzD,SAAS,gBAAgB,sBAAsB,UAAU,cACtD,eAAe,cAAc;;;;;;;;KAStB,qBACV,gBAAgB,6CAChB,uBAEA,SAAS,KACP,aAAa,sBAAsB,UAAU;;;;;EAKzC;EAAuB,gBAAgB;MAC1C,eAAe;;;;;;;;;;;;;;KAeR,kBACV,gBAAgB,6CAChB,uBAEA,SAAS,aAAa,sBAAsB,UAAU,WACtD,SAAS,qBAAqB,SAAS,cACpC,eAAe,YAAY;;;;;;;;;KAU3B,mBAAmB,SAAS,aAC/B,OAAO,qBAAqB,UAC5B,SAAS,UAAQ,cACd,eAAe,iBAAiB,QAAQ,sBAAsB;;;;;;KAOvD,gBACV,gBAAgB,6CAChB,sBAEE,mBAAmB,SAAS;EAE1B,MAAM,mBAAmB,SAAS;EAClC,YAAY;;;;;;;;;;KAWb,mBAAmB,SAAS,aAC/B,OAAO,qBAAqB,UAC5B,SAAS,UAAQ,cACd,eAAe,iBAAiB,QAAQ,sBAAsB;;;;;;KAOvD,gBACV,gBAAgB,6CAChB,sBAEE,mBAAmB,SAAS;EAE1B,MAAM,mBAAmB,SAAS;EAClC,YAAY;;;;;;;;;;;KAYb,kBAAkB,SAAS,aAC9B,OAAO,qBAAqB,UAC5B,SAAS,UAAQ,cACd,eAAe,iBAAiB,QAAQ,sBAAsB;;;;;;KAOvD,eACV,gBAAgB,6CAChB,sBAEE,kBAAkB,SAAS;EAEzB,MAAM,kBAAkB,SAAS;EACjC,YAAY;;;;;;;;;;KAWb,kBAAkB,SAAS,aAC9B,OAAO,qBAAqB,UAC5B,SAAS,UAAQ,cACd,eAAe,iBAAiB,QAAQ,sBAAsB;;;;;;KAOvD,eACV,gBAAgB,6CAChB,sBAEE,kBAAkB,SAAS;EAEzB,MAAM,kBAAkB,SAAS;EACjC,YAAY;;;;;;;cAQL;;;;;;KAOD,qBAAqB,gBAC/B,iCACE,mBACA,kBAAkB,oBAClB,mBAAmB,8CAGX,aAAa,eACvB,oBAAoB;;;;;;;;;;;;;;;;;;;;UAsBL,gBACf,gBAAgB,uCAChB,uBACI,mBACA,kBAAkB,oBAClB,mBAAmB,qCAEvB,oBACA,yBAAyB,aAAa,0BAClC,aACA,eAEJ,4BAA4B,oBAAoB,0BAC9C,oBAAoB;;;;;;WAab,qBAAqB,qBAC5B,SACA,gBACA,cACA,QACA;;;;EAMF;;;;;;;;EASA,cAAc;;;;;;;;EASd,gBAAgB;;;;EAKhB,QAAQ;;;;;;EAOR,qBAAqB;;;;;;;;;;;;;;;;;;EAmBrB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgEd,eAAe,iBAAiB,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BzC,gBAAgB,kBAAkB,SAAS;;;;;;;;;EAU3C,cAAc,gBAAgB,SAAS;;;;;;;;;EAUvC,cAAc,gBAAgB,SAAS;;;;;;;;;EAUvC,aAAa,eAAe,SAAS;;;;;;;;;EAUrC,aAAa,eAAe,SAAS;;;;;KAMlC,mBAAmB,QACrB,WAAW,KAAK,iCAAiC,IAAI,EAAE;;;;;;KAQ9C,4BAA4B,KAAK;EAC3C,2BAA2B;IAEzB,cAAc,uBACZ,gBAEF,UAAU,uBACR;;;;;;;KASM,oBACV,GACA,gBAAgB,wBACd,4BAA4B,GAAG;;;;KAKvB,sBAAsB,KAAK,oBAAoB;;;;KAK/C,6BAA6B,KAAK,oBAC5C;;;;KAOU,2BAA2B,KAAK,oBAC1C;;;;KAOU,+BAA+B,KAAK,oBAAoB;;;;KAKxD,4CAA4C,KACtD,oBAAoB;KAEV,iBAAiB,UAAU,oBAAoB,oBACzD,UAAU,oBACN,iBAAiB,cACjB,UAAU,mBACR,qBAAqB;;;;;;KAQjB,qBAAqB,UAAU,mBACzC,UAAU,sBAAsB,+BAC5B,gBAAgB,kBAAkB,WAChC,mBAAmB,sBAAsB,YACzC,gBAAgB,mBACd,mBAAmB,sBAAsB,YACzC,gBAAgB,sBACd,mBAAmB,iBAAiB;;;;;;KASpC,0BAA0B,UAAU,mBAC9C,UAAU,sBAAsB,+BAC5B,gBAAgB,kBAAkB,WAChC,mBAAmB,uBAAuB,YAC1C,gBAAgB,mBACd,mBAAmB,qBAAqB,YACxC,gBAAgB,sBACd,mBAAmB,iBAAiB;;;;KAOpC,sBAAsB,mBAAmB,wBACnD,6BAEI,0BAA0B,gBAAgB,QACxC,cAAc,kBACZ,sBAAsB,uBACpB,qBAAqB,SAAS,sBAAsB,QACpD,qBAAqB;;;;KAOrB,2BACV,mBAAmB,wBACjB,6BAEA,0BAA0B,gBAAgB,QACxC,cAAc,kBACZ,sBAAsB,uBACpB,0BAA0B,SAAS,2BAA2B,QAC9D,0BAA0B;;;;KAOxB,iBAAiB,mBAAmB,wBAC9C,sBAAsB,KAAK;;;;KAKjB,sBAAsB,mBAAmB,wBACnD,2BAA2B,KAAK;;;;KAKtB,uBAAuB,UAAU,mBAC3C,UAAU,2BAA2B,iCACjC,uBAAuB,mBACrB,qBAAqB;;;;KAOjB,4BAA4B,UAAU,mBAChD,UAAU,2BAA2B,iCACjC,uBAAuB,yBAAyB,SAC9C,qBAAqB,qBACrB,uBAAuB,mBACrB,qBAAqB;;;;KAOnB,wBAAwB,mBAAmB,wBACrD,6BAEI,0BAA0B,gBAAgB,QACxC,cAAc,kBACZ,sBAAsB,uBACpB,uBAAuB,SAAS,wBAAwB,QACxD,uBAAuB;;;;KAO9B,kBAAkB,GAAG,MAAM,0BAC3B,qCAEC,iBACD,yBACC,iBACC,YAAY,KACX,KACC,YAAY,KACX,IACA,IAAI;;;;KAKF,6BACV,mBAAmB,wBACjB,6BAEA,0BAA0B,gBAAgB,QACxC,cAAc,kBACZ,sBAAsB,uBACpB,kBACE,4BAA4B,QAC5B,6BAA6B,SAE/B,4BAA4B;;;;KAO1B,kBACV,sBAAsB,oBAAoB,oBACxC,sBAAsB,mBACtB,qBAAqB,iBACrB,sBAAsB,oBACpB,iBAAiB;KAGX,iBAAiB,UAAU,uBACrC,UAAU,oBACN,IACA,UAAU,mBACR,4BAA4B;KAGxB,iBAAiB,UAAU,oCACrC,8BAGE,UAAU,kBAAkB,WAC1B,sBAAsB,WACtB,UAAU,mBACR,sBAAsB,KACtB,UAAU,oBACR;KAGE,iBAAiB,UAAU,oCACrC,8BAGE,UAAU,kBAAkB,WAC1B,uBAAuB,WACvB,UAAU,mBACR,qBAAqB,KACrB,UAAU,oBACR"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../../src/agents/middleware/types.ts"],"mappings":"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"}
@@ -3,7 +3,7 @@ import { AgentBuiltInState, Runtime as Runtime$1 } from "../runtime.js";
3
3
  import { ModelRequest } from "../nodes/types.js";
4
4
  import { AIMessage, SystemMessage, ToolMessage } from "@langchain/core/messages";
5
5
  import { ClientTool, ServerTool } from "@langchain/core/tools";
6
- import { AnnotationRoot, Command, InferStateSchemaUpdate, InferStateSchemaValue, StateDefinitionInit, StateSchema, StreamTransformer, TracePolicy } from "@langchain/langgraph";
6
+ import { AnnotationRoot, Command, InferStateSchemaUpdate, InferStateSchemaValue, StateDefinitionInit, StateSchema, StreamTransformer } from "@langchain/langgraph";
7
7
  import { InteropZodToStateDefinition } from "@langchain/langgraph/zod";
8
8
  import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodObject, InteropZodOptional } from "@langchain/core/utils/types";
9
9
  import { ToolCall as ToolCall$1 } from "@langchain/core/messages/tool";
@@ -287,24 +287,6 @@ interface AgentMiddleware<TSchema extends StateDefinitionInit | undefined = any,
287
287
  * is compiled.
288
288
  */
289
289
  streamTransformers?: TStreamTransformers;
290
- /**
291
- * Controls the payloads recorded by this middleware's lifecycle hook spans.
292
- * Processors affect chain callback payloads, including `streamEvents`; output
293
- * omission can suppress messages directly returned by a lifecycle hook, and
294
- * input omission can affect message deduplication. They do not affect execution.
295
- *
296
- * @example
297
- * ```ts
298
- * import { createMiddleware, omitPayload } from "langchain";
299
- *
300
- * const middleware = createMiddleware({
301
- * name: "PrivateMiddleware",
302
- * tracePolicy: { processInputs: omitPayload },
303
- * beforeModel: () => undefined,
304
- * });
305
- * ```
306
- */
307
- tracePolicy?: TracePolicy;
308
290
  /**
309
291
  * Wraps tool execution with custom logic. This allows you to:
310
292
  * - Modify tool call parameters before execution