langchain 1.0.6 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +1 -1
  3. package/chat_models/universal.cjs +1 -0
  4. package/chat_models/universal.d.cts +1 -0
  5. package/chat_models/universal.d.ts +1 -0
  6. package/chat_models/universal.js +1 -0
  7. package/dist/agents/ReactAgent.cjs +1 -1
  8. package/dist/agents/ReactAgent.cjs.map +1 -1
  9. package/dist/agents/ReactAgent.js +2 -2
  10. package/dist/agents/ReactAgent.js.map +1 -1
  11. package/dist/agents/index.d.cts +0 -2
  12. package/dist/agents/index.d.ts +0 -2
  13. package/dist/agents/middleware/constants.cjs +16 -0
  14. package/dist/agents/middleware/constants.cjs.map +1 -0
  15. package/dist/agents/middleware/constants.js +15 -0
  16. package/dist/agents/middleware/constants.js.map +1 -0
  17. package/dist/agents/middleware/contextEditing.cjs.map +1 -1
  18. package/dist/agents/middleware/contextEditing.d.cts +23 -7
  19. package/dist/agents/middleware/contextEditing.d.ts +23 -7
  20. package/dist/agents/middleware/contextEditing.js.map +1 -1
  21. package/dist/agents/middleware/dynamicSystemPrompt.cjs +5 -2
  22. package/dist/agents/middleware/dynamicSystemPrompt.cjs.map +1 -1
  23. package/dist/agents/middleware/dynamicSystemPrompt.d.cts +2 -1
  24. package/dist/agents/middleware/dynamicSystemPrompt.d.ts +2 -1
  25. package/dist/agents/middleware/dynamicSystemPrompt.js +4 -2
  26. package/dist/agents/middleware/dynamicSystemPrompt.js.map +1 -1
  27. package/dist/agents/middleware/error.cjs +20 -0
  28. package/dist/agents/middleware/error.cjs.map +1 -0
  29. package/dist/agents/middleware/error.js +19 -0
  30. package/dist/agents/middleware/error.js.map +1 -0
  31. package/dist/agents/middleware/index.cjs +4 -2
  32. package/dist/agents/middleware/index.d.ts +18 -0
  33. package/dist/agents/middleware/index.js +4 -2
  34. package/dist/agents/middleware/modelRetry.cjs +162 -0
  35. package/dist/agents/middleware/modelRetry.cjs.map +1 -0
  36. package/dist/agents/middleware/modelRetry.d.cts +134 -0
  37. package/dist/agents/middleware/modelRetry.d.ts +134 -0
  38. package/dist/agents/middleware/modelRetry.js +161 -0
  39. package/dist/agents/middleware/modelRetry.js.map +1 -0
  40. package/dist/agents/middleware/{promptCaching.cjs → provider/anthropic/promptCaching.cjs} +3 -3
  41. package/dist/agents/middleware/provider/anthropic/promptCaching.cjs.map +1 -0
  42. package/dist/agents/middleware/{promptCaching.d.cts → provider/anthropic/promptCaching.d.cts} +2 -2
  43. package/dist/agents/middleware/{promptCaching.d.ts → provider/anthropic/promptCaching.d.ts} +2 -2
  44. package/dist/agents/middleware/{promptCaching.js → provider/anthropic/promptCaching.js} +2 -2
  45. package/dist/agents/middleware/provider/anthropic/promptCaching.js.map +1 -0
  46. package/dist/agents/middleware/provider/openai/moderation.cjs +299 -0
  47. package/dist/agents/middleware/provider/openai/moderation.cjs.map +1 -0
  48. package/dist/agents/middleware/provider/openai/moderation.d.cts +133 -0
  49. package/dist/agents/middleware/provider/openai/moderation.d.ts +133 -0
  50. package/dist/agents/middleware/provider/openai/moderation.js +298 -0
  51. package/dist/agents/middleware/provider/openai/moderation.js.map +1 -0
  52. package/dist/agents/middleware/summarization.d.cts +0 -4
  53. package/dist/agents/middleware/summarization.d.ts +0 -4
  54. package/dist/agents/middleware/todoListMiddleware.cjs +1 -1
  55. package/dist/agents/middleware/todoListMiddleware.cjs.map +1 -1
  56. package/dist/agents/middleware/todoListMiddleware.js +1 -1
  57. package/dist/agents/middleware/todoListMiddleware.js.map +1 -1
  58. package/dist/agents/middleware/toolRetry.cjs +32 -44
  59. package/dist/agents/middleware/toolRetry.cjs.map +1 -1
  60. package/dist/agents/middleware/toolRetry.d.cts +16 -36
  61. package/dist/agents/middleware/toolRetry.d.ts +16 -36
  62. package/dist/agents/middleware/toolRetry.js +32 -44
  63. package/dist/agents/middleware/toolRetry.js.map +1 -1
  64. package/dist/agents/middleware/types.d.cts +9 -10
  65. package/dist/agents/middleware/types.d.ts +9 -10
  66. package/dist/agents/middleware/utils.cjs +23 -0
  67. package/dist/agents/middleware/utils.cjs.map +1 -1
  68. package/dist/agents/middleware/utils.d.ts +2 -0
  69. package/dist/agents/middleware/utils.js +23 -1
  70. package/dist/agents/middleware/utils.js.map +1 -1
  71. package/dist/agents/nodes/AgentNode.cjs +50 -22
  72. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  73. package/dist/agents/nodes/AgentNode.js +52 -24
  74. package/dist/agents/nodes/AgentNode.js.map +1 -1
  75. package/dist/agents/nodes/types.d.cts +39 -3
  76. package/dist/agents/nodes/types.d.ts +39 -3
  77. package/dist/agents/responses.d.cts +0 -19
  78. package/dist/agents/responses.d.ts +0 -19
  79. package/dist/agents/runtime.d.ts +1 -0
  80. package/dist/agents/tests/utils.cjs +10 -1
  81. package/dist/agents/tests/utils.cjs.map +1 -1
  82. package/dist/agents/tests/utils.js +10 -1
  83. package/dist/agents/tests/utils.js.map +1 -1
  84. package/dist/agents/types.d.cts +68 -2
  85. package/dist/agents/types.d.ts +68 -2
  86. package/dist/agents/utils.cjs +15 -12
  87. package/dist/agents/utils.cjs.map +1 -1
  88. package/dist/agents/utils.js +16 -13
  89. package/dist/agents/utils.js.map +1 -1
  90. package/dist/chat_models/universal.cjs +50 -16
  91. package/dist/chat_models/universal.cjs.map +1 -1
  92. package/dist/chat_models/universal.d.cts +19 -1
  93. package/dist/chat_models/universal.d.ts +19 -1
  94. package/dist/chat_models/universal.js +50 -16
  95. package/dist/chat_models/universal.js.map +1 -1
  96. package/dist/index.cjs +8 -2
  97. package/dist/index.d.cts +5 -3
  98. package/dist/index.d.ts +6 -3
  99. package/dist/index.js +7 -3
  100. package/dist/load/import_constants.cjs +2 -1
  101. package/dist/load/import_constants.cjs.map +1 -1
  102. package/dist/load/import_constants.js +2 -1
  103. package/dist/load/import_constants.js.map +1 -1
  104. package/dist/load/import_map.cjs +2 -19
  105. package/dist/load/import_map.cjs.map +1 -1
  106. package/dist/load/import_map.js +2 -19
  107. package/dist/load/import_map.js.map +1 -1
  108. package/hub/node.cjs +1 -0
  109. package/hub/node.d.cts +1 -0
  110. package/hub/node.d.ts +1 -0
  111. package/hub/node.js +1 -0
  112. package/hub.cjs +1 -0
  113. package/hub.d.cts +1 -0
  114. package/hub.d.ts +1 -0
  115. package/hub.js +1 -0
  116. package/load/serializable.cjs +1 -0
  117. package/load/serializable.d.cts +1 -0
  118. package/load/serializable.d.ts +1 -0
  119. package/load/serializable.js +1 -0
  120. package/load.cjs +1 -0
  121. package/load.d.cts +1 -0
  122. package/load.d.ts +1 -0
  123. package/load.js +1 -0
  124. package/package.json +66 -53
  125. package/storage/encoder_backed.cjs +1 -0
  126. package/storage/encoder_backed.d.cts +1 -0
  127. package/storage/encoder_backed.d.ts +1 -0
  128. package/storage/encoder_backed.js +1 -0
  129. package/storage/file_system.cjs +1 -0
  130. package/storage/file_system.d.cts +1 -0
  131. package/storage/file_system.d.ts +1 -0
  132. package/storage/file_system.js +1 -0
  133. package/storage/in_memory.cjs +1 -0
  134. package/storage/in_memory.d.cts +1 -0
  135. package/storage/in_memory.d.ts +1 -0
  136. package/storage/in_memory.js +1 -0
  137. package/dist/agents/ReactAgent.d.cts.map +0 -1
  138. package/dist/agents/ReactAgent.d.ts.map +0 -1
  139. package/dist/agents/constants.cjs +0 -7
  140. package/dist/agents/constants.cjs.map +0 -1
  141. package/dist/agents/constants.d.cts.map +0 -1
  142. package/dist/agents/constants.d.ts.map +0 -1
  143. package/dist/agents/constants.js +0 -6
  144. package/dist/agents/constants.js.map +0 -1
  145. package/dist/agents/errors.d.cts.map +0 -1
  146. package/dist/agents/errors.d.ts.map +0 -1
  147. package/dist/agents/index.d.cts.map +0 -1
  148. package/dist/agents/index.d.ts.map +0 -1
  149. package/dist/agents/middleware/contextEditing.d.cts.map +0 -1
  150. package/dist/agents/middleware/contextEditing.d.ts.map +0 -1
  151. package/dist/agents/middleware/dynamicSystemPrompt.d.cts.map +0 -1
  152. package/dist/agents/middleware/dynamicSystemPrompt.d.ts.map +0 -1
  153. package/dist/agents/middleware/hitl.d.cts.map +0 -1
  154. package/dist/agents/middleware/hitl.d.ts.map +0 -1
  155. package/dist/agents/middleware/llmToolSelector.d.cts.map +0 -1
  156. package/dist/agents/middleware/llmToolSelector.d.ts.map +0 -1
  157. package/dist/agents/middleware/modelCallLimit.d.cts.map +0 -1
  158. package/dist/agents/middleware/modelCallLimit.d.ts.map +0 -1
  159. package/dist/agents/middleware/modelFallback.d.cts.map +0 -1
  160. package/dist/agents/middleware/modelFallback.d.ts.map +0 -1
  161. package/dist/agents/middleware/pii.d.cts.map +0 -1
  162. package/dist/agents/middleware/pii.d.ts.map +0 -1
  163. package/dist/agents/middleware/piiRedaction.d.cts.map +0 -1
  164. package/dist/agents/middleware/piiRedaction.d.ts.map +0 -1
  165. package/dist/agents/middleware/promptCaching.cjs.map +0 -1
  166. package/dist/agents/middleware/promptCaching.d.cts.map +0 -1
  167. package/dist/agents/middleware/promptCaching.d.ts.map +0 -1
  168. package/dist/agents/middleware/promptCaching.js.map +0 -1
  169. package/dist/agents/middleware/summarization.d.cts.map +0 -1
  170. package/dist/agents/middleware/summarization.d.ts.map +0 -1
  171. package/dist/agents/middleware/todoListMiddleware.d.cts.map +0 -1
  172. package/dist/agents/middleware/todoListMiddleware.d.ts.map +0 -1
  173. package/dist/agents/middleware/toolCallLimit.d.cts.map +0 -1
  174. package/dist/agents/middleware/toolCallLimit.d.ts.map +0 -1
  175. package/dist/agents/middleware/toolEmulator.d.cts.map +0 -1
  176. package/dist/agents/middleware/toolEmulator.d.ts.map +0 -1
  177. package/dist/agents/middleware/toolRetry.d.cts.map +0 -1
  178. package/dist/agents/middleware/toolRetry.d.ts.map +0 -1
  179. package/dist/agents/middleware/types.d.cts.map +0 -1
  180. package/dist/agents/middleware/types.d.ts.map +0 -1
  181. package/dist/agents/middleware/utils.d.cts.map +0 -1
  182. package/dist/agents/middleware/utils.d.ts.map +0 -1
  183. package/dist/agents/middleware.d.cts.map +0 -1
  184. package/dist/agents/middleware.d.ts.map +0 -1
  185. package/dist/agents/nodes/types.d.cts.map +0 -1
  186. package/dist/agents/nodes/types.d.ts.map +0 -1
  187. package/dist/agents/responses.d.cts.map +0 -1
  188. package/dist/agents/responses.d.ts.map +0 -1
  189. package/dist/agents/runtime.d.cts.map +0 -1
  190. package/dist/agents/runtime.d.ts.map +0 -1
  191. package/dist/agents/tests/utils.d.cts.map +0 -1
  192. package/dist/agents/tests/utils.d.ts.map +0 -1
  193. package/dist/agents/types.d.cts.map +0 -1
  194. package/dist/agents/types.d.ts.map +0 -1
  195. package/dist/chat_models/universal.d.cts.map +0 -1
  196. package/dist/chat_models/universal.d.ts.map +0 -1
  197. package/dist/hub/base.d.cts.map +0 -1
  198. package/dist/hub/base.d.ts.map +0 -1
  199. package/dist/hub/index.d.cts.map +0 -1
  200. package/dist/hub/index.d.ts.map +0 -1
  201. package/dist/hub/node.d.cts.map +0 -1
  202. package/dist/hub/node.d.ts.map +0 -1
  203. package/dist/load/import_type.d.cts.map +0 -1
  204. package/dist/load/import_type.d.ts.map +0 -1
  205. package/dist/load/index.d.cts.map +0 -1
  206. package/dist/load/index.d.ts.map +0 -1
  207. package/dist/storage/encoder_backed.d.cts.map +0 -1
  208. package/dist/storage/encoder_backed.d.ts.map +0 -1
  209. package/dist/storage/file_system.d.cts.map +0 -1
  210. package/dist/storage/file_system.d.ts.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"promptCaching.js","names":["message: string","middlewareOptions?: PromptCachingMiddlewareConfig"],"sources":["../../../src/agents/middleware/promptCaching.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { ContentBlock } from \"@langchain/core/messages\";\nimport { InferInteropZodInput } from \"@langchain/core/utils/types\";\n\nimport { ConfigurableModel } from \"../../chat_models/universal.js\";\nimport { createMiddleware } from \"../middleware.js\";\n\nconst DEFAULT_ENABLE_CACHING = true;\nconst DEFAULT_TTL = \"5m\";\nconst DEFAULT_MIN_MESSAGES_TO_CACHE = 3;\nconst DEFAULT_UNSUPPORTED_MODEL_BEHAVIOR = \"warn\";\n\nconst contextSchema = z.object({\n /**\n * Whether to enable prompt caching.\n * @default true\n */\n enableCaching: z.boolean().optional(),\n /**\n * The time-to-live for the cached prompt.\n * @default \"5m\"\n */\n ttl: z.enum([\"5m\", \"1h\"]).optional(),\n /**\n * The minimum number of messages required before caching is applied.\n * @default 3\n */\n minMessagesToCache: z.number().optional(),\n /**\n * The behavior to take when an unsupported model is used.\n * - \"ignore\" will ignore the unsupported model and continue without caching.\n * - \"warn\" will warn the user and continue without caching.\n * - \"raise\" will raise an error and stop the agent.\n * @default \"warn\"\n */\n unsupportedModelBehavior: z.enum([\"ignore\", \"warn\", \"raise\"]).optional(),\n});\nexport type PromptCachingMiddlewareConfig = Partial<\n InferInteropZodInput<typeof contextSchema>\n>;\n\nclass PromptCachingMiddlewareError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PromptCachingMiddlewareError\";\n }\n}\n\n/**\n * Creates a prompt caching middleware for Anthropic models to optimize API usage.\n *\n * This middleware automatically adds cache control headers to the last messages when using Anthropic models,\n * enabling their prompt caching feature. This can significantly reduce costs for applications with repetitive\n * prompts, long system messages, or extensive conversation histories.\n *\n * ## How It Works\n *\n * The middleware intercepts model requests and adds cache control metadata that tells Anthropic's\n * API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the\n * cached representations are reused, skipping redundant token processing.\n *\n * ## Benefits\n *\n * - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)\n * - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed\n * - **Better Scalability**: Reduced computational load enables handling more requests\n * - **Consistent Performance**: Stable response times for repetitive queries\n *\n * @param middlewareOptions - Configuration options for the caching behavior\n * @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)\n * @param middlewareOptions.ttl - Cache time-to-live: `\"5m\"` for 5 minutes or `\"1h\"` for 1 hour (default: `\"5m\"`)\n * @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)\n * @param middlewareOptions.unsupportedModelBehavior - The behavior to take when an unsupported model is used (default: `\"warn\"`)\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @throws {Error} If used with non-Anthropic models\n *\n * @example\n * Basic usage with default settings\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { anthropicPromptCachingMiddleware } from \"langchain\";\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middleware: [\n * anthropicPromptCachingMiddleware()\n * ]\n * });\n * ```\n *\n * @example\n * Custom configuration for longer conversations\n * ```typescript\n * const cachingMiddleware = anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Cache for 1 hour instead of default 5 minutes\n * minMessagesToCache: 5 // Only cache after 5 messages\n * });\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemPrompt: \"You are a helpful assistant with deep knowledge of...\", // Long system prompt\n * middleware: [cachingMiddleware]\n * });\n * ```\n *\n * @example\n * Conditional caching based on runtime context\n * ```typescript\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middleware: [\n * anthropicPromptCachingMiddleware({\n * enableCaching: true,\n * ttl: \"5m\"\n * })\n * ]\n * });\n *\n * // Disable caching for specific requests\n * await agent.invoke(\n * { messages: [new HumanMessage(\"Process this without caching\")] },\n * {\n * configurable: {\n * middleware_context: { enableCaching: false }\n * }\n * }\n * );\n * ```\n *\n * @example\n * Optimal setup for customer support chatbot\n * ```typescript\n * const supportAgent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemPrompt: `You are a customer support agent for ACME Corp.\n *\n * Company policies:\n * - Always be polite and professional\n * - Refer to knowledge base for product information\n * - Escalate billing issues to human agents\n * ... (extensive policies and guidelines)\n * `,\n * tools: [searchKnowledgeBase, createTicket, checkOrderStatus],\n * middleware: [\n * anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Long TTL for stable system prompt\n * minMessagesToCache: 1 // Cache immediately due to large system prompt\n * })\n * ]\n * });\n * ```\n *\n * @remarks\n * - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers\n * - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`\n * - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys\n * - **TTL Options**: Only supports \"5m\" (5 minutes) and \"1h\" (1 hour) as TTL values per Anthropic's API\n * - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications\n * - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base\n *\n * @see {@link createAgent} for agent creation\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation\n * @public\n */\nexport function anthropicPromptCachingMiddleware(\n middlewareOptions?: PromptCachingMiddlewareConfig\n) {\n return createMiddleware({\n name: \"PromptCachingMiddleware\",\n contextSchema,\n wrapModelCall: (request, handler) => {\n /**\n * Prefer runtime context values over middleware options values over defaults\n */\n const enableCaching =\n request.runtime.context.enableCaching ??\n middlewareOptions?.enableCaching ??\n DEFAULT_ENABLE_CACHING;\n const ttl =\n request.runtime.context.ttl ?? middlewareOptions?.ttl ?? DEFAULT_TTL;\n const minMessagesToCache =\n request.runtime.context.minMessagesToCache ??\n middlewareOptions?.minMessagesToCache ??\n DEFAULT_MIN_MESSAGES_TO_CACHE;\n const unsupportedModelBehavior =\n request.runtime.context.unsupportedModelBehavior ??\n middlewareOptions?.unsupportedModelBehavior ??\n DEFAULT_UNSUPPORTED_MODEL_BEHAVIOR;\n\n // Skip if caching is disabled\n if (!enableCaching || !request.model) {\n return handler(request);\n }\n\n const isAnthropicModel =\n request.model.getName() === \"ChatAnthropic\" ||\n (request.model.getName() === \"ConfigurableModel\" &&\n (request.model as ConfigurableModel)._defaultConfig?.modelProvider ===\n \"anthropic\");\n if (!isAnthropicModel) {\n // Get model name for better error context\n const modelName = request.model.getName();\n const modelInfo =\n request.model.getName() === \"ConfigurableModel\"\n ? `${modelName} (${\n (request.model as ConfigurableModel)._defaultConfig\n ?.modelProvider\n })`\n : modelName;\n\n const baseMessage = `Unsupported model '${modelInfo}'. Prompt caching requires an Anthropic model`;\n\n if (unsupportedModelBehavior === \"raise\") {\n throw new PromptCachingMiddlewareError(\n `${baseMessage} (e.g., 'anthropic:claude-4-0-sonnet').`\n );\n } else if (unsupportedModelBehavior === \"warn\") {\n console.warn(\n `PromptCachingMiddleware: Skipping caching for ${modelName}. Consider switching to an Anthropic model for caching benefits.`\n );\n }\n return handler(request);\n }\n\n const messagesCount =\n request.state.messages.length + (request.systemPrompt ? 1 : 0);\n\n if (messagesCount < minMessagesToCache) {\n return handler(request);\n }\n\n /**\n * Add cache_control to the last message\n */\n const lastMessage = request.messages.at(-1);\n if (!lastMessage) {\n return handler(request);\n }\n\n const NewMessageConstructor =\n Object.getPrototypeOf(lastMessage).constructor;\n if (Array.isArray(lastMessage.content)) {\n const newMessage = new NewMessageConstructor({\n ...lastMessage,\n content: [\n ...lastMessage.content.slice(0, -1),\n {\n ...lastMessage.content.at(-1),\n cache_control: {\n type: \"ephemeral\",\n ttl,\n },\n } as ContentBlock,\n ],\n });\n return handler({\n ...request,\n messages: [...request.messages.slice(0, -1), newMessage],\n });\n } else if (typeof lastMessage.content === \"string\") {\n const newMessage = new NewMessageConstructor({\n ...lastMessage,\n content: [\n {\n type: \"text\",\n text: lastMessage.content,\n cache_control: {\n type: \"ephemeral\",\n ttl,\n },\n },\n ],\n });\n return handler({\n ...request,\n messages: [...request.messages.slice(0, -1), newMessage],\n });\n }\n\n throw new PromptCachingMiddlewareError(\n \"Last message content is not a string or array\"\n );\n },\n });\n}\n"],"mappings":";;;;AAOA,MAAM,yBAAyB;AAC/B,MAAM,cAAc;AACpB,MAAM,gCAAgC;AACtC,MAAM,qCAAqC;AAE3C,MAAM,gBAAgB,EAAE,OAAO;CAK7B,eAAe,EAA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,6BAA6B,QAC/B,OAAM,IAAI,6BACR,GAAG,YAAY,uCAAuC,CAAC;aAEhD,6BAA6B,QACtC,QAAQ,KACN,CAAC,8CAA8C,EAAE,UAAU,gEAAgE,CAAC,CAC7H;AAEH,WAAO,QAAQ,QAAQ;GACxB;GAED,MAAM,gBACJ,QAAQ,MAAM,SAAS,UAAU,QAAQ,eAAe,IAAI;AAE9D,OAAI,gBAAgB,mBAClB,QAAO,QAAQ,QAAQ;;;;GAMzB,MAAM,cAAc,QAAQ,SAAS,GAAG,GAAG;AAC3C,OAAI,CAAC,YACH,QAAO,QAAQ,QAAQ;GAGzB,MAAM,wBACJ,OAAO,eAAe,YAAY,CAAC;AACrC,OAAI,MAAM,QAAQ,YAAY,QAAQ,EAAE;IACtC,MAAM,aAAa,IAAI,sBAAsB;KAC3C,GAAG;KACH,SAAS,CACP,GAAG,YAAY,QAAQ,MAAM,GAAG,GAAG,EACnC;MACE,GAAG,YAAY,QAAQ,GAAG,GAAG;MAC7B,eAAe;OACb,MAAM;OACN;MACD;KACF,CACF;IACF;AACD,WAAO,QAAQ;KACb,GAAG;KACH,UAAU,CAAC,GAAG,QAAQ,SAAS,MAAM,GAAG,GAAG,EAAE,UAAW;IACzD,EAAC;GACH,WAAU,OAAO,YAAY,YAAY,UAAU;IAClD,MAAM,aAAa,IAAI,sBAAsB;KAC3C,GAAG;KACH,SAAS,CACP;MACE,MAAM;MACN,MAAM,YAAY;MAClB,eAAe;OACb,MAAM;OACN;MACD;KACF,CACF;IACF;AACD,WAAO,QAAQ;KACb,GAAG;KACH,UAAU,CAAC,GAAG,QAAQ,SAAS,MAAM,GAAG,GAAG,EAAE,UAAW;IACzD,EAAC;GACH;AAED,SAAM,IAAI,6BACR;EAEH;CACF,EAAC;AACH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarization.d.cts","names":["_langchain_core_messages0","__types_js7","z","BaseMessage","BaseLanguageModel","InferInteropZodInput","DEFAULT_SUMMARY_PROMPT","TokenCounter","Promise","contextSizeSchema","ZodNumber","ZodOptional","ZodTypeAny","ZodObject","ZodEffects","ContextSize","infer","keepSchema","KeepSize","contextSchema","_langchain_core_language_models_base0","BaseLanguageModelCallOptions","ZodTypeDef","ZodType","ZodArray","ZodUnion","MessageStructure","MessageType","ZodUnknown","ZodTuple","ZodPromise","ZodFunction","ZodString","ZodDefault","SummarizationMiddlewareConfig","getProfileLimits","summarizationMiddleware","AgentMiddleware"],"sources":["../../../src/agents/middleware/summarization.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { BaseLanguageModel } from \"@langchain/core/language_models/base\";\nimport { InferInteropZodInput } from \"@langchain/core/utils/types\";\nexport declare const DEFAULT_SUMMARY_PROMPT = \"<role>\\nContext Extraction Assistant\\n</role>\\n\\n<primary_objective>\\nYour sole objective in this task is to extract the highest quality/most relevant context from the conversation history below.\\n</primary_objective>\\n\\n<objective_information>\\nYou're nearing the total number of input tokens you can accept, so you must extract the highest quality/most relevant pieces of information from your conversation history.\\nThis context will then overwrite the conversation history presented below. Because of this, ensure the context you extract is only the most important information to your overall goal.\\n</objective_information>\\n\\n<instructions>\\nThe conversation history below will be replaced with the context you extract in this step. Because of this, you must do your very best to extract and record all of the most important context from the conversation history.\\nYou want to ensure that you don't repeat any actions you've already completed, so the context you extract from the conversation history should be focused on the most important information to your overall goal.\\n</instructions>\\n\\nThe user will message you with the full message history you'll be extracting context from, to then replace. Carefully read over it all, and think deeply about what information is most important to your overall goal that should be saved:\\n\\nWith all of this in mind, please carefully read over the entire conversation history, and extract the most important and relevant context to replace it so that you can free up space in the conversation history.\\nRespond ONLY with the extracted context. Do not include any additional information, or text before or after the extracted context.\\n\\n<messages>\\nMessages to summarize:\\n{messages}\\n</messages>\";\nexport type TokenCounter = (messages: BaseMessage[]) => number | Promise<number>;\nexport declare const contextSizeSchema: z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>;\nexport type ContextSize = z.infer<typeof contextSizeSchema>;\nexport declare const keepSchema: z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to keep\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to keep\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n messages: z.ZodOptional<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>;\nexport type KeepSize = z.infer<typeof keepSchema>;\ndeclare const contextSchema: z.ZodObject<{\n /**\n * Model to use for summarization\n */\n model: z.ZodType<string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>, z.ZodTypeDef, string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>>;\n /**\n * Trigger conditions for summarization.\n * Can be a single condition object (all properties must be met) or an array of conditions (any condition must be met).\n *\n * @example\n * ```ts\n * // Single condition: trigger if tokens >= 5000 AND messages >= 3\n * trigger: { tokens: 5000, messages: 3 }\n *\n * // Multiple conditions: trigger if (tokens >= 5000 AND messages >= 3) OR (tokens >= 3000 AND messages >= 6)\n * trigger: [\n * { tokens: 5000, messages: 3 },\n * { tokens: 3000, messages: 6 }\n * ]\n * ```\n */\n trigger: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, z.ZodArray<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, \"many\">]>>;\n /**\n * Keep conditions for summarization\n */\n keep: z.ZodOptional<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to keep\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to keep\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>>;\n /**\n * Token counter function to use for summarization\n */\n tokenCounter: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodType<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>, z.ZodTypeDef, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>>, \"many\">], z.ZodUnknown>, z.ZodUnion<[z.ZodNumber, z.ZodPromise<z.ZodNumber>]>>>;\n /**\n * Summary prompt to use for summarization\n * @default {@link DEFAULT_SUMMARY_PROMPT}\n */\n summaryPrompt: z.ZodDefault<z.ZodString>;\n /**\n * Number of tokens to trim to before summarizing\n */\n trimTokensToSummarize: z.ZodOptional<z.ZodNumber>;\n /**\n * Prefix to add to the summary\n */\n summaryPrefix: z.ZodOptional<z.ZodString>;\n /**\n * @deprecated Use `trigger: { tokens: value }` instead.\n */\n maxTokensBeforeSummary: z.ZodOptional<z.ZodNumber>;\n /**\n * @deprecated Use `keep: { messages: value }` instead.\n */\n messagesToKeep: z.ZodOptional<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n model: string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>;\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt: string;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n}, {\n model: string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>;\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt?: string | undefined;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n}>;\nexport type SummarizationMiddlewareConfig = InferInteropZodInput<typeof contextSchema>;\n/**\n * Get max input tokens from model profile or fallback to model name lookup\n */\nexport declare function getProfileLimits(input: BaseLanguageModel): number | undefined;\n/**\n * Summarization middleware that automatically summarizes conversation history when token limits are approached.\n *\n * This middleware monitors message token counts and automatically summarizes older\n * messages when a threshold is reached, preserving recent messages and maintaining\n * context continuity by ensuring AI/Tool message pairs remain together.\n *\n * @param options Configuration options for the summarization middleware\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * import { summarizationMiddleware } from \"langchain\";\n * import { createAgent } from \"langchain\";\n *\n * // Single condition: trigger if tokens >= 4000 AND messages >= 10\n * const agent1 = createAgent({\n * llm: model,\n * tools: [getWeather],\n * middleware: [\n * summarizationMiddleware({\n * model: new ChatOpenAI({ model: \"gpt-4o\" }),\n * trigger: { tokens: 4000, messages: 10 },\n * keep: { messages: 20 },\n * })\n * ],\n * });\n *\n * // Multiple conditions: trigger if (tokens >= 5000 AND messages >= 3) OR (tokens >= 3000 AND messages >= 6)\n * const agent2 = createAgent({\n * llm: model,\n * tools: [getWeather],\n * middleware: [\n * summarizationMiddleware({\n * model: new ChatOpenAI({ model: \"gpt-4o\" }),\n * trigger: [\n * { tokens: 5000, messages: 3 },\n * { tokens: 3000, messages: 6 },\n * ],\n * keep: { messages: 20 },\n * })\n * ],\n * });\n *\n * ```\n */\nexport declare function summarizationMiddleware(options: SummarizationMiddlewareConfig): import(\"./types.js\").AgentMiddleware<undefined, z.ZodObject<{\n trigger: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, z.ZodArray<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, \"many\">]>>;\n keep: z.ZodOptional<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to keep\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to keep\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>>;\n tokenCounter: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodType<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>, z.ZodTypeDef, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>>, \"many\">], z.ZodUnknown>, z.ZodUnion<[z.ZodNumber, z.ZodPromise<z.ZodNumber>]>>>;\n summaryPrompt: z.ZodDefault<z.ZodString>;\n trimTokensToSummarize: z.ZodOptional<z.ZodNumber>;\n summaryPrefix: z.ZodOptional<z.ZodString>;\n maxTokensBeforeSummary: z.ZodOptional<z.ZodNumber>;\n messagesToKeep: z.ZodOptional<z.ZodNumber>;\n} & {\n model: z.ZodOptional<z.ZodType<BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>, z.ZodTypeDef, BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>>>;\n}, \"strip\", z.ZodTypeAny, {\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt: string;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n model?: BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions> | undefined;\n}, {\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt?: string | undefined;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n model?: BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions> | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;;;;;;KAKYO,YAAAA,cAA0BJ,2BAA2BK;cAC5CC,mBAAmBP,CAAAA,CAAEY,WAAWZ,CAAAA,CAAEW;;;AADvD;EAAwB,QAAA,EAKVX,CAAAA,CAAES,WALQ,CAKIT,CAAAA,CAAEQ,SALN,CAAA;EAAA;;AAAgD;EACnDD,MAAAA,EAQTP,CAAAA,CAAES,WAqBZ,CArBwBT,CAAAA,CAAEQ,SAqB1B,CAAA;EAAA;;;EAzByB,QAICA,EAIdR,CAAAA,CAAES,WAJYD,CAIAR,CAAAA,CAAEQ,SAJFA,CAAAA;CAAS,EAAA,OAAvBC,EAKFT,CAAAA,CAAEU,UALAD,EAAAA;EAAW,QAIKD,CAAAA,EAAAA,MAAAA,GAAAA,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;SAEzBR,CAAAA,CAAES,YAAYT,CAAAA,CAAEqB,QAAQnB,uBAFFgB,qCAAAA,CAEwEC,4BAAAA,GAA+BnB,CAAAA,CAAEoB,YAAYlB,uBAAFgB,qCAAAA,CAAwEC,4BAAAA;YAChNnB,CAAAA,CAAEU;;;;;;;;;;;;;;;2BAeeT,YAfLH,yBAAAA,CAeoD0B,gBAAAA,EAAgB1B,yBAAAA,CAAqC2B,WAAAA,qCAAgDnB;;;;;;UAMrKJ,uBAN4KgB,qCAAAA,CAMtGC,4BAAAA;;;;;;;;;;;;;;;;2BAgBrDlB,YAhBAH,yBAAAA,CAgB+C0B,gBAAAA,EAAgB1B,yBAAAA,CAAqC2B,WAAAA,qCAAgDnB;;;;;;UAMrKJ,uBAN4KgB,qCAAAA,CAMtGC,4BAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarization.d.ts","names":["_langchain_core_messages0","__types_js0","z","BaseMessage","BaseLanguageModel","InferInteropZodInput","DEFAULT_SUMMARY_PROMPT","TokenCounter","Promise","contextSizeSchema","ZodNumber","ZodOptional","ZodTypeAny","ZodObject","ZodEffects","ContextSize","infer","keepSchema","KeepSize","contextSchema","_langchain_core_language_models_base0","BaseLanguageModelCallOptions","ZodTypeDef","ZodType","ZodArray","ZodUnion","MessageStructure","MessageType","ZodUnknown","ZodTuple","ZodPromise","ZodFunction","ZodString","ZodDefault","SummarizationMiddlewareConfig","getProfileLimits","summarizationMiddleware","AgentMiddleware"],"sources":["../../../src/agents/middleware/summarization.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { BaseLanguageModel } from \"@langchain/core/language_models/base\";\nimport { InferInteropZodInput } from \"@langchain/core/utils/types\";\nexport declare const DEFAULT_SUMMARY_PROMPT = \"<role>\\nContext Extraction Assistant\\n</role>\\n\\n<primary_objective>\\nYour sole objective in this task is to extract the highest quality/most relevant context from the conversation history below.\\n</primary_objective>\\n\\n<objective_information>\\nYou're nearing the total number of input tokens you can accept, so you must extract the highest quality/most relevant pieces of information from your conversation history.\\nThis context will then overwrite the conversation history presented below. Because of this, ensure the context you extract is only the most important information to your overall goal.\\n</objective_information>\\n\\n<instructions>\\nThe conversation history below will be replaced with the context you extract in this step. Because of this, you must do your very best to extract and record all of the most important context from the conversation history.\\nYou want to ensure that you don't repeat any actions you've already completed, so the context you extract from the conversation history should be focused on the most important information to your overall goal.\\n</instructions>\\n\\nThe user will message you with the full message history you'll be extracting context from, to then replace. Carefully read over it all, and think deeply about what information is most important to your overall goal that should be saved:\\n\\nWith all of this in mind, please carefully read over the entire conversation history, and extract the most important and relevant context to replace it so that you can free up space in the conversation history.\\nRespond ONLY with the extracted context. Do not include any additional information, or text before or after the extracted context.\\n\\n<messages>\\nMessages to summarize:\\n{messages}\\n</messages>\";\nexport type TokenCounter = (messages: BaseMessage[]) => number | Promise<number>;\nexport declare const contextSizeSchema: z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>;\nexport type ContextSize = z.infer<typeof contextSizeSchema>;\nexport declare const keepSchema: z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to keep\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to keep\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n messages: z.ZodOptional<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n}>;\nexport type KeepSize = z.infer<typeof keepSchema>;\ndeclare const contextSchema: z.ZodObject<{\n /**\n * Model to use for summarization\n */\n model: z.ZodType<string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>, z.ZodTypeDef, string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>>;\n /**\n * Trigger conditions for summarization.\n * Can be a single condition object (all properties must be met) or an array of conditions (any condition must be met).\n *\n * @example\n * ```ts\n * // Single condition: trigger if tokens >= 5000 AND messages >= 3\n * trigger: { tokens: 5000, messages: 3 }\n *\n * // Multiple conditions: trigger if (tokens >= 5000 AND messages >= 3) OR (tokens >= 3000 AND messages >= 6)\n * trigger: [\n * { tokens: 5000, messages: 3 },\n * { tokens: 3000, messages: 6 }\n * ]\n * ```\n */\n trigger: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, z.ZodArray<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, \"many\">]>>;\n /**\n * Keep conditions for summarization\n */\n keep: z.ZodOptional<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to keep\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to keep\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>>;\n /**\n * Token counter function to use for summarization\n */\n tokenCounter: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodType<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>, z.ZodTypeDef, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>>, \"many\">], z.ZodUnknown>, z.ZodUnion<[z.ZodNumber, z.ZodPromise<z.ZodNumber>]>>>;\n /**\n * Summary prompt to use for summarization\n * @default {@link DEFAULT_SUMMARY_PROMPT}\n */\n summaryPrompt: z.ZodDefault<z.ZodString>;\n /**\n * Number of tokens to trim to before summarizing\n */\n trimTokensToSummarize: z.ZodOptional<z.ZodNumber>;\n /**\n * Prefix to add to the summary\n */\n summaryPrefix: z.ZodOptional<z.ZodString>;\n /**\n * @deprecated Use `trigger: { tokens: value }` instead.\n */\n maxTokensBeforeSummary: z.ZodOptional<z.ZodNumber>;\n /**\n * @deprecated Use `keep: { messages: value }` instead.\n */\n messagesToKeep: z.ZodOptional<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n model: string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>;\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt: string;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n}, {\n model: string | BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>;\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt?: string | undefined;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n}>;\nexport type SummarizationMiddlewareConfig = InferInteropZodInput<typeof contextSchema>;\n/**\n * Get max input tokens from model profile or fallback to model name lookup\n */\nexport declare function getProfileLimits(input: BaseLanguageModel): number | undefined;\n/**\n * Summarization middleware that automatically summarizes conversation history when token limits are approached.\n *\n * This middleware monitors message token counts and automatically summarizes older\n * messages when a threshold is reached, preserving recent messages and maintaining\n * context continuity by ensuring AI/Tool message pairs remain together.\n *\n * @param options Configuration options for the summarization middleware\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * import { summarizationMiddleware } from \"langchain\";\n * import { createAgent } from \"langchain\";\n *\n * // Single condition: trigger if tokens >= 4000 AND messages >= 10\n * const agent1 = createAgent({\n * llm: model,\n * tools: [getWeather],\n * middleware: [\n * summarizationMiddleware({\n * model: new ChatOpenAI({ model: \"gpt-4o\" }),\n * trigger: { tokens: 4000, messages: 10 },\n * keep: { messages: 20 },\n * })\n * ],\n * });\n *\n * // Multiple conditions: trigger if (tokens >= 5000 AND messages >= 3) OR (tokens >= 3000 AND messages >= 6)\n * const agent2 = createAgent({\n * llm: model,\n * tools: [getWeather],\n * middleware: [\n * summarizationMiddleware({\n * model: new ChatOpenAI({ model: \"gpt-4o\" }),\n * trigger: [\n * { tokens: 5000, messages: 3 },\n * { tokens: 3000, messages: 6 },\n * ],\n * keep: { messages: 20 },\n * })\n * ],\n * });\n *\n * ```\n */\nexport declare function summarizationMiddleware(options: SummarizationMiddlewareConfig): import(\"./types.js\").AgentMiddleware<undefined, z.ZodObject<{\n trigger: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, z.ZodArray<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to use as the trigger\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to use as the trigger\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of messages to use as the trigger\n */\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, \"many\">]>>;\n keep: z.ZodOptional<z.ZodEffects<z.ZodObject<{\n /**\n * Fraction of the model's context size to keep\n */\n fraction: z.ZodOptional<z.ZodNumber>;\n /**\n * Number of tokens to keep\n */\n tokens: z.ZodOptional<z.ZodNumber>;\n messages: z.ZodOptional<z.ZodNumber>;\n }, \"strip\", z.ZodTypeAny, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }, {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }>>;\n tokenCounter: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodType<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>, z.ZodTypeDef, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>>, \"many\">], z.ZodUnknown>, z.ZodUnion<[z.ZodNumber, z.ZodPromise<z.ZodNumber>]>>>;\n summaryPrompt: z.ZodDefault<z.ZodString>;\n trimTokensToSummarize: z.ZodOptional<z.ZodNumber>;\n summaryPrefix: z.ZodOptional<z.ZodString>;\n maxTokensBeforeSummary: z.ZodOptional<z.ZodNumber>;\n messagesToKeep: z.ZodOptional<z.ZodNumber>;\n} & {\n model: z.ZodOptional<z.ZodType<BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>, z.ZodTypeDef, BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions>>>;\n}, \"strip\", z.ZodTypeAny, {\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt: string;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n model?: BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions> | undefined;\n}, {\n trigger?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n }[] | {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n keep?: {\n fraction?: number | undefined;\n tokens?: number | undefined;\n messages?: number | undefined;\n } | undefined;\n tokenCounter?: ((args_0: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[], ...args: unknown[]) => number | Promise<number>) | undefined;\n summaryPrompt?: string | undefined;\n trimTokensToSummarize?: number | undefined;\n summaryPrefix?: string | undefined;\n maxTokensBeforeSummary?: number | undefined;\n messagesToKeep?: number | undefined;\n model?: BaseLanguageModel<any, import(\"@langchain/core/language_models/base\").BaseLanguageModelCallOptions> | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;;;;;;KAKYO,YAAAA,cAA0BJ,2BAA2BK;cAC5CC,mBAAmBP,CAAAA,CAAEY,WAAWZ,CAAAA,CAAEW;;;AADvD;EAAwB,QAAA,EAKVX,CAAAA,CAAES,WALQ,CAKIT,CAAAA,CAAEQ,SALN,CAAA;EAAA;;AAAgD;EACnDD,MAAAA,EAQTP,CAAAA,CAAES,WAqBZ,CArBwBT,CAAAA,CAAEQ,SAqB1B,CAAA;EAAA;;;EAzByB,QAICA,EAIdR,CAAAA,CAAES,WAJYD,CAIAR,CAAAA,CAAEQ,SAJFA,CAAAA;CAAS,EAAA,OAAvBC,EAKFT,CAAAA,CAAEU,UALAD,EAAAA;EAAW,QAIKD,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAS,MAAvBC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAW,QACbC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;CAAU,EAAA;EAbwC,QAAtBE,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAU,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EA8BxCC,QAAAA,CAAAA,EAAAA,MAAW,GAAA,SAAA;CAAA,CAAA,EAAA;EAAA,QAAkBN,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAiB,MAA9BO,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAK,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;AACjC,CAAA,EAAA;EA0BE,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAA,MAtB4BN,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAS,QAAvBC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;CAAW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PT","stateSchema","ZodString","ZodEnum","ZodTypeAny","ZodObject","ZodArray","ZodDefault","TodoMiddlewareState","infer","TodoListMiddlewareOptions","todoListMiddleware","__types_js13","AgentMiddleware"],"sources":["../../../src/agents/middleware/todoListMiddleware.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nexport declare const TODO_LIST_MIDDLEWARE_SYSTEM_PROMPT = \"## `write_todos`\\n\\nYou have access to the `write_todos` tool to help you manage and plan complex objectives. \\nUse this tool for complex objectives to ensure that you are tracking each necessary step and giving the user visibility into your progress.\\nThis tool is very helpful for planning complex objectives, and for breaking down these larger complex objectives into smaller steps.\\n\\nIt is critical that you mark todos as completed as soon as you are done with a step. Do not batch up multiple steps before marking them as completed.\\nFor simple objectives that only require a few steps, it is better to just complete the objective directly and NOT use this tool.\\nWriting todos takes time and tokens, use it when it is helpful for managing complex many-step problems! But not for simple few-step requests.\\n\\n## Important To-Do List Usage Notes to Remember\\n- The `write_todos` tool should never be called multiple times in parallel.\\n- Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.\";\ndeclare const stateSchema: z.ZodObject<{\n todos: z.ZodDefault<z.ZodArray<z.ZodObject<{\n content: z.ZodString;\n status: z.ZodEnum<[\"pending\", \"in_progress\", \"completed\"]>;\n }, \"strip\", z.ZodTypeAny, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }>, \"many\">>;\n}, \"strip\", z.ZodTypeAny, {\n todos: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[];\n}, {\n todos?: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[] | undefined;\n}>;\nexport type TodoMiddlewareState = z.infer<typeof stateSchema>;\nexport interface TodoListMiddlewareOptions {\n /**\n * Custom system prompt to guide the agent on using the todo tool.\n * If not provided, uses the default {@link PLANNING_MIDDLEWARE_SYSTEM_PROMPT}.\n */\n systemPrompt?: string;\n /**\n * Custom description for the {@link writeTodos} tool.\n * If not provided, uses the default {@link WRITE_TODOS_DESCRIPTION}.\n */\n toolDescription?: string;\n}\n/**\n * Creates a middleware that provides todo list management capabilities to agents.\n *\n * This middleware adds a `write_todos` tool that allows agents to create and manage\n * structured task lists for complex multi-step operations. It's designed to help\n * agents track progress, organize complex tasks, and provide users with visibility\n * into task completion status.\n *\n * The middleware automatically injects system prompts that guide the agent on when\n * and how to use the todo functionality effectively.\n *\n * @example\n * ```typescript\n * import { todoListMiddleware, createAgent } from 'langchain';\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [todoListMiddleware()],\n * });\n *\n * // Agent now has access to write_todos tool and todo state tracking\n * const result = await agent.invoke({\n * messages: [new HumanMessage(\"Help me refactor my codebase\")]\n * });\n *\n * console.log(result.todos); // Array of todo items with status tracking\n * ```\n *\n * @returns A configured middleware instance that provides todo management capabilities\n *\n * @see {@link TodoMiddlewareState} for the state schema\n * @see {@link writeTodos} for the tool implementation\n */\nexport declare function todoListMiddleware(options?: TodoListMiddlewareOptions): import(\"./types.js\").AgentMiddleware<z.ZodObject<{\n todos: z.ZodDefault<z.ZodArray<z.ZodObject<{\n content: z.ZodString;\n status: z.ZodEnum<[\"pending\", \"in_progress\", \"completed\"]>;\n }, \"strip\", z.ZodTypeAny, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }>, \"many\">>;\n}, \"strip\", z.ZodTypeAny, {\n todos: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[];\n}, {\n todos?: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[] | undefined;\n}>, undefined, any>;\nexport {};\n"],"mappings":";;;;cACqBC,kCAAAA;UAwBJU,yBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6COC,kBAAAA,WAA6BD,4BAA4E,gBAAXX,CAAAA,CAAEM;SAC7GN,CAAAA,CAAEQ,WAAWR,CAAAA,CAAEO,SAASP,CAAAA,CAAEM;aACpBN,CAAAA,CAAEG;YACHH,CAAAA,CAAEI;cACFJ,CAAAA,CAAEK;;;;;;;YAONL,CAAAA,CAAEK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"todoListMiddleware.d.ts","names":["z","TODO_LIST_MIDDLEWARE_SYSTEM_PROMPT","stateSchema","ZodString","ZodEnum","ZodTypeAny","ZodObject","ZodArray","ZodDefault","TodoMiddlewareState","infer","TodoListMiddlewareOptions","todoListMiddleware","__types_js13","AgentMiddleware"],"sources":["../../../src/agents/middleware/todoListMiddleware.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nexport declare const TODO_LIST_MIDDLEWARE_SYSTEM_PROMPT = \"## `write_todos`\\n\\nYou have access to the `write_todos` tool to help you manage and plan complex objectives. \\nUse this tool for complex objectives to ensure that you are tracking each necessary step and giving the user visibility into your progress.\\nThis tool is very helpful for planning complex objectives, and for breaking down these larger complex objectives into smaller steps.\\n\\nIt is critical that you mark todos as completed as soon as you are done with a step. Do not batch up multiple steps before marking them as completed.\\nFor simple objectives that only require a few steps, it is better to just complete the objective directly and NOT use this tool.\\nWriting todos takes time and tokens, use it when it is helpful for managing complex many-step problems! But not for simple few-step requests.\\n\\n## Important To-Do List Usage Notes to Remember\\n- The `write_todos` tool should never be called multiple times in parallel.\\n- Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.\";\ndeclare const stateSchema: z.ZodObject<{\n todos: z.ZodDefault<z.ZodArray<z.ZodObject<{\n content: z.ZodString;\n status: z.ZodEnum<[\"pending\", \"in_progress\", \"completed\"]>;\n }, \"strip\", z.ZodTypeAny, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }>, \"many\">>;\n}, \"strip\", z.ZodTypeAny, {\n todos: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[];\n}, {\n todos?: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[] | undefined;\n}>;\nexport type TodoMiddlewareState = z.infer<typeof stateSchema>;\nexport interface TodoListMiddlewareOptions {\n /**\n * Custom system prompt to guide the agent on using the todo tool.\n * If not provided, uses the default {@link PLANNING_MIDDLEWARE_SYSTEM_PROMPT}.\n */\n systemPrompt?: string;\n /**\n * Custom description for the {@link writeTodos} tool.\n * If not provided, uses the default {@link WRITE_TODOS_DESCRIPTION}.\n */\n toolDescription?: string;\n}\n/**\n * Creates a middleware that provides todo list management capabilities to agents.\n *\n * This middleware adds a `write_todos` tool that allows agents to create and manage\n * structured task lists for complex multi-step operations. It's designed to help\n * agents track progress, organize complex tasks, and provide users with visibility\n * into task completion status.\n *\n * The middleware automatically injects system prompts that guide the agent on when\n * and how to use the todo functionality effectively.\n *\n * @example\n * ```typescript\n * import { todoListMiddleware, createAgent } from 'langchain';\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [todoListMiddleware()],\n * });\n *\n * // Agent now has access to write_todos tool and todo state tracking\n * const result = await agent.invoke({\n * messages: [new HumanMessage(\"Help me refactor my codebase\")]\n * });\n *\n * console.log(result.todos); // Array of todo items with status tracking\n * ```\n *\n * @returns A configured middleware instance that provides todo management capabilities\n *\n * @see {@link TodoMiddlewareState} for the state schema\n * @see {@link writeTodos} for the tool implementation\n */\nexport declare function todoListMiddleware(options?: TodoListMiddlewareOptions): import(\"./types.js\").AgentMiddleware<z.ZodObject<{\n todos: z.ZodDefault<z.ZodArray<z.ZodObject<{\n content: z.ZodString;\n status: z.ZodEnum<[\"pending\", \"in_progress\", \"completed\"]>;\n }, \"strip\", z.ZodTypeAny, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }, {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }>, \"many\">>;\n}, \"strip\", z.ZodTypeAny, {\n todos: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[];\n}, {\n todos?: {\n content: string;\n status: \"completed\" | \"in_progress\" | \"pending\";\n }[] | undefined;\n}>, undefined, any>;\nexport {};\n"],"mappings":";;;;cACqBC,kCAAAA;UAwBJU,yBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6COC,kBAAAA,WAA6BD,4BAA4E,gBAAXX,CAAAA,CAAEM;SAC7GN,CAAAA,CAAEQ,WAAWR,CAAAA,CAAEO,SAASP,CAAAA,CAAEM;aACpBN,CAAAA,CAAEG;YACHH,CAAAA,CAAEI;cACFJ,CAAAA,CAAEK;;;;;;;YAONL,CAAAA,CAAEK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toolCallLimit.d.cts","names":["z","InferInteropZodInput","ToolCallLimitExceededError","Error","ToolCallLimitOptionsSchema","ZodString","ZodOptional","ZodNumber","ZodEnum","ZodDefault","ZodTypeAny","ZodObject","ToolCallLimitConfig","toolCallLimitMiddleware","ZodRecord","Record","__types_js12","AgentMiddleware"],"sources":["../../../src/agents/middleware/toolCallLimit.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport type { InferInteropZodInput } from \"@langchain/core/utils/types\";\n/**\n * Exception raised when tool call limits are exceeded.\n *\n * This exception is raised when the configured exit behavior is 'error'\n * and either the thread or run tool call limit has been exceeded.\n */\nexport declare class ToolCallLimitExceededError extends Error {\n /**\n * Current thread tool call count.\n */\n threadCount: number;\n /**\n * Current run tool call count.\n */\n runCount: number;\n /**\n * Thread tool call limit (if set).\n */\n threadLimit: number | undefined;\n /**\n * Run tool call limit (if set).\n */\n runLimit: number | undefined;\n /**\n * Tool name being limited (if specific tool), or undefined for all tools.\n */\n toolName: string | undefined;\n constructor(threadCount: number, runCount: number, threadLimit: number | undefined, runLimit: number | undefined, toolName?: string | undefined);\n}\n/**\n * Options for configuring the Tool Call Limit middleware.\n */\nexport declare const ToolCallLimitOptionsSchema: z.ZodObject<{\n /**\n * Name of the specific tool to limit. If undefined, limits apply to all tools.\n */\n toolName: z.ZodOptional<z.ZodString>;\n /**\n * Maximum number of tool calls allowed per thread.\n * undefined means no limit.\n */\n threadLimit: z.ZodOptional<z.ZodNumber>;\n /**\n * Maximum number of tool calls allowed per run.\n * undefined means no limit.\n */\n runLimit: z.ZodOptional<z.ZodNumber>;\n /**\n * What to do when limits are exceeded.\n * - \"continue\": Block exceeded tools with error messages, let other tools continue (default)\n * - \"error\": Raise a ToolCallLimitExceededError exception\n * - \"end\": Stop execution immediately, injecting a ToolMessage and an AI message\n * for the single tool call that exceeded the limit. Raises NotImplementedError\n * if there are multiple tool calls.\n *\n * @default \"continue\"\n */\n exitBehavior: z.ZodDefault<z.ZodEnum<[\"continue\", \"error\", \"end\"]>>;\n}, \"strip\", z.ZodTypeAny, {\n toolName?: string | undefined;\n threadLimit?: number | undefined;\n runLimit?: number | undefined;\n exitBehavior: \"continue\" | \"end\" | \"error\";\n}, {\n toolName?: string | undefined;\n threadLimit?: number | undefined;\n runLimit?: number | undefined;\n exitBehavior?: \"continue\" | \"end\" | \"error\" | undefined;\n}>;\nexport type ToolCallLimitConfig = InferInteropZodInput<typeof ToolCallLimitOptionsSchema>;\n/**\n * Middleware that tracks tool call counts and enforces limits.\n *\n * This middleware monitors the number of tool calls made during agent execution\n * and can terminate the agent when specified limits are reached. It supports\n * both thread-level and run-level call counting with configurable exit behaviors.\n *\n * Thread-level: The middleware counts all tool calls in the entire message history\n * and persists this count across multiple runs (invocations) of the agent.\n *\n * Run-level: The middleware counts tool calls made after the last HumanMessage,\n * representing the current run (invocation) of the agent.\n *\n * @param options - Configuration options for the middleware\n * @param options.toolName - Name of the specific tool to limit. If undefined, limits apply to all tools.\n * @param options.threadLimit - Maximum number of tool calls allowed per thread. undefined means no limit.\n * @param options.runLimit - Maximum number of tool calls allowed per run. undefined means no limit.\n * @param options.exitBehavior - What to do when limits are exceeded.\n * - \"continue\": Block exceeded tools with error messages, let other tools continue. Model decides when to end. (default)\n * - \"error\": Raise a ToolCallLimitExceededError exception\n * - \"end\": Stop execution immediately with a ToolMessage + AI message for the single tool call that exceeded the limit. Raises NotImplementedError if there are multiple tool calls.\n *\n * @throws {Error} If both limits are undefined, if exitBehavior is invalid, or if runLimit exceeds threadLimit.\n * @throws {NotImplementedError} If exitBehavior is \"end\" and there are multiple tool calls.\n *\n * @example Continue execution with blocked tools (default)\n * ```ts\n * import { toolCallLimitMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * // Block exceeded tools but let other tools and model continue\n * const limiter = toolCallLimitMiddleware({\n * threadLimit: 20,\n * runLimit: 10,\n * exitBehavior: \"continue\", // default\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [limiter]\n * });\n * ```\n *\n * @example Stop immediately when limit exceeded\n * ```ts\n * // End execution immediately with an AI message\n * const limiter = toolCallLimitMiddleware({\n * runLimit: 5,\n * exitBehavior: \"end\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [limiter]\n * });\n * ```\n *\n * @example Raise exception on limit\n * ```ts\n * // Strict limit with exception handling\n * const limiter = toolCallLimitMiddleware({\n * toolName: \"search\",\n * threadLimit: 5,\n * exitBehavior: \"error\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [limiter]\n * });\n *\n * try {\n * const result = await agent.invoke({ messages: [new HumanMessage(\"Task\")] });\n * } catch (error) {\n * if (error instanceof ToolCallLimitExceededError) {\n * console.log(`Search limit exceeded: ${error}`);\n * }\n * }\n * ```\n */\nexport declare function toolCallLimitMiddleware(options: ToolCallLimitConfig): import(\"./types.js\").AgentMiddleware<z.ZodObject<{\n threadToolCallCount: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;\n runToolCallCount: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;\n}, \"strip\", z.ZodTypeAny, {\n threadToolCallCount: Record<string, number>;\n runToolCallCount: Record<string, number>;\n}, {\n threadToolCallCount?: Record<string, number> | undefined;\n runToolCallCount?: Record<string, number> | undefined;\n}>, undefined, any>;\n"],"mappings":";;;;;;;;;AAQA;AA0BA;;AAI4BA,cA9BPE,0BAAAA,SAAmCC,KAAK,CA8B/BE;EAAS;;;EAKT,WAKAE,EAAAA,MAAAA;EAAS;;;EAWT,QAChBG,EAAAA,MAAAA;EAAU;AA1BoC;AAqC5D;EAA+B,WAAA,EAAA,MAAA,GAAA,SAAA;EAAA;;AAAuB;EAiF9BG,QAAAA,EAAAA,MAAAA,GAAAA,SAAuB;EAAA;;;EACc,QAAIN,EAAAA,MAAAA,GAAAA,SAAAA;EAAS,WAAlCO,CAAAA,WAAAA,EAAAA,MAAAA,EAAAA,QAAAA,EAAAA,MAAAA,EAAAA,WAAAA,EAAAA,MAAAA,GAAAA,SAAAA,EAAAA,QAAAA,EAAAA,MAAAA,GAAAA,SAAAA,EAAAA,QAAAA,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;;;;;AAClBd,cAxHDI,0BAwHGK,EAxHyBT,CAAAA,CAAEW,SAwH3BF,CAAAA;EAAU;;;EAGN,QAEFM,EAzHZf,CAAAA,CAAEM,WAyHUS,CAzHEf,CAAAA,CAAEK,SAyHJU,CAAAA;EAAM;;;AAPmF;eA7GlGf,CAAAA,CAAEM,YAAYN,CAAAA,CAAEO;;;;;YAKnBP,CAAAA,CAAEM,YAAYN,CAAAA,CAAEO;;;;;;;;;;;gBAWZP,CAAAA,CAAES,WAAWT,CAAAA,CAAEQ;YACrBR,CAAAA,CAAEU;;;;;;;;;;;KAWFE,mBAAAA,GAAsBX,4BAA4BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiFtCS,uBAAAA,UAAiCD,sBAAsE,gBAAXZ,CAAAA,CAAEW;uBAC7FX,CAAAA,CAAES,WAAWT,CAAAA,CAAEc,UAAUd,CAAAA,CAAEK,WAAWL,CAAAA,CAAEO;oBAC3CP,CAAAA,CAAES,WAAWT,CAAAA,CAAEc,UAAUd,CAAAA,CAAEK,WAAWL,CAAAA,CAAEO;YAClDP,CAAAA,CAAEU;uBACWK;oBACHA;;wBAEIA;qBACHA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toolCallLimit.d.ts","names":["z","InferInteropZodInput","ToolCallLimitExceededError","Error","ToolCallLimitOptionsSchema","ZodString","ZodOptional","ZodNumber","ZodEnum","ZodDefault","ZodTypeAny","ZodObject","ToolCallLimitConfig","toolCallLimitMiddleware","ZodRecord","Record","__types_js12","AgentMiddleware"],"sources":["../../../src/agents/middleware/toolCallLimit.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport type { InferInteropZodInput } from \"@langchain/core/utils/types\";\n/**\n * Exception raised when tool call limits are exceeded.\n *\n * This exception is raised when the configured exit behavior is 'error'\n * and either the thread or run tool call limit has been exceeded.\n */\nexport declare class ToolCallLimitExceededError extends Error {\n /**\n * Current thread tool call count.\n */\n threadCount: number;\n /**\n * Current run tool call count.\n */\n runCount: number;\n /**\n * Thread tool call limit (if set).\n */\n threadLimit: number | undefined;\n /**\n * Run tool call limit (if set).\n */\n runLimit: number | undefined;\n /**\n * Tool name being limited (if specific tool), or undefined for all tools.\n */\n toolName: string | undefined;\n constructor(threadCount: number, runCount: number, threadLimit: number | undefined, runLimit: number | undefined, toolName?: string | undefined);\n}\n/**\n * Options for configuring the Tool Call Limit middleware.\n */\nexport declare const ToolCallLimitOptionsSchema: z.ZodObject<{\n /**\n * Name of the specific tool to limit. If undefined, limits apply to all tools.\n */\n toolName: z.ZodOptional<z.ZodString>;\n /**\n * Maximum number of tool calls allowed per thread.\n * undefined means no limit.\n */\n threadLimit: z.ZodOptional<z.ZodNumber>;\n /**\n * Maximum number of tool calls allowed per run.\n * undefined means no limit.\n */\n runLimit: z.ZodOptional<z.ZodNumber>;\n /**\n * What to do when limits are exceeded.\n * - \"continue\": Block exceeded tools with error messages, let other tools continue (default)\n * - \"error\": Raise a ToolCallLimitExceededError exception\n * - \"end\": Stop execution immediately, injecting a ToolMessage and an AI message\n * for the single tool call that exceeded the limit. Raises NotImplementedError\n * if there are multiple tool calls.\n *\n * @default \"continue\"\n */\n exitBehavior: z.ZodDefault<z.ZodEnum<[\"continue\", \"error\", \"end\"]>>;\n}, \"strip\", z.ZodTypeAny, {\n toolName?: string | undefined;\n threadLimit?: number | undefined;\n runLimit?: number | undefined;\n exitBehavior: \"continue\" | \"end\" | \"error\";\n}, {\n toolName?: string | undefined;\n threadLimit?: number | undefined;\n runLimit?: number | undefined;\n exitBehavior?: \"continue\" | \"end\" | \"error\" | undefined;\n}>;\nexport type ToolCallLimitConfig = InferInteropZodInput<typeof ToolCallLimitOptionsSchema>;\n/**\n * Middleware that tracks tool call counts and enforces limits.\n *\n * This middleware monitors the number of tool calls made during agent execution\n * and can terminate the agent when specified limits are reached. It supports\n * both thread-level and run-level call counting with configurable exit behaviors.\n *\n * Thread-level: The middleware counts all tool calls in the entire message history\n * and persists this count across multiple runs (invocations) of the agent.\n *\n * Run-level: The middleware counts tool calls made after the last HumanMessage,\n * representing the current run (invocation) of the agent.\n *\n * @param options - Configuration options for the middleware\n * @param options.toolName - Name of the specific tool to limit. If undefined, limits apply to all tools.\n * @param options.threadLimit - Maximum number of tool calls allowed per thread. undefined means no limit.\n * @param options.runLimit - Maximum number of tool calls allowed per run. undefined means no limit.\n * @param options.exitBehavior - What to do when limits are exceeded.\n * - \"continue\": Block exceeded tools with error messages, let other tools continue. Model decides when to end. (default)\n * - \"error\": Raise a ToolCallLimitExceededError exception\n * - \"end\": Stop execution immediately with a ToolMessage + AI message for the single tool call that exceeded the limit. Raises NotImplementedError if there are multiple tool calls.\n *\n * @throws {Error} If both limits are undefined, if exitBehavior is invalid, or if runLimit exceeds threadLimit.\n * @throws {NotImplementedError} If exitBehavior is \"end\" and there are multiple tool calls.\n *\n * @example Continue execution with blocked tools (default)\n * ```ts\n * import { toolCallLimitMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * // Block exceeded tools but let other tools and model continue\n * const limiter = toolCallLimitMiddleware({\n * threadLimit: 20,\n * runLimit: 10,\n * exitBehavior: \"continue\", // default\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [limiter]\n * });\n * ```\n *\n * @example Stop immediately when limit exceeded\n * ```ts\n * // End execution immediately with an AI message\n * const limiter = toolCallLimitMiddleware({\n * runLimit: 5,\n * exitBehavior: \"end\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [limiter]\n * });\n * ```\n *\n * @example Raise exception on limit\n * ```ts\n * // Strict limit with exception handling\n * const limiter = toolCallLimitMiddleware({\n * toolName: \"search\",\n * threadLimit: 5,\n * exitBehavior: \"error\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [limiter]\n * });\n *\n * try {\n * const result = await agent.invoke({ messages: [new HumanMessage(\"Task\")] });\n * } catch (error) {\n * if (error instanceof ToolCallLimitExceededError) {\n * console.log(`Search limit exceeded: ${error}`);\n * }\n * }\n * ```\n */\nexport declare function toolCallLimitMiddleware(options: ToolCallLimitConfig): import(\"./types.js\").AgentMiddleware<z.ZodObject<{\n threadToolCallCount: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;\n runToolCallCount: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;\n}, \"strip\", z.ZodTypeAny, {\n threadToolCallCount: Record<string, number>;\n runToolCallCount: Record<string, number>;\n}, {\n threadToolCallCount?: Record<string, number> | undefined;\n runToolCallCount?: Record<string, number> | undefined;\n}>, undefined, any>;\n"],"mappings":";;;;;;;;;AAQA;AA0BA;;AAI4BA,cA9BPE,0BAAAA,SAAmCC,KAAK,CA8B/BE;EAAS;;;EAKT,WAKAE,EAAAA,MAAAA;EAAS;;;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d.cts","names":["BaseChatModel","ClientTool","ServerTool","createMiddleware","ToolEmulatorOptions","toolEmulatorMiddleware","ReturnType"],"sources":["../../../src/agents/middleware/toolEmulator.d.ts"],"sourcesContent":["import type { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport { createMiddleware } from \"../middleware.js\";\n/**\n * Options for configuring the Tool Emulator middleware.\n */\nexport interface ToolEmulatorOptions {\n /**\n * List of tool names (string) or tool instances to emulate.\n * - If `undefined` (default), ALL tools will be emulated.\n * - If empty array, no tools will be emulated.\n * - If array with tool names/instances, only those tools will be emulated.\n */\n tools?: (string | ClientTool | ServerTool)[];\n /**\n * Model to use for emulation.\n * - Can be a model identifier string (e.g., \"anthropic:claude-sonnet-4-5-20250929\")\n * - Can be a BaseChatModel instance\n * - Defaults to agent model\n */\n model?: string | BaseChatModel;\n}\n/**\n * Middleware that emulates specified tools using an LLM instead of executing them.\n *\n * This middleware allows selective emulation of tools for testing purposes.\n * By default (when `tools` is undefined), all tools are emulated. You can specify\n * which tools to emulate by passing a list of tool names or tool instances.\n *\n * @param options - Configuration options for the middleware\n * @param options.tools - List of tool names or tool instances to emulate. If undefined, all tools are emulated.\n * @param options.model - Model to use for emulation. Defaults to \"anthropic:claude-sonnet-4-5-20250929\".\n *\n * @example Emulate all tools (default behavior)\n * ```ts\n * import { toolEmulatorMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * const middleware = toolEmulatorMiddleware();\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [getWeather, getUserLocation, calculator],\n * middleware: [middleware],\n * });\n * ```\n *\n * @example Emulate specific tools by name\n * ```ts\n * const middleware = toolEmulatorMiddleware({\n * tools: [\"get_weather\", \"get_user_location\"]\n * });\n * ```\n *\n * @example Use a custom model for emulation\n * ```ts\n * const middleware = toolEmulatorMiddleware({\n * tools: [\"get_weather\"],\n * model: \"anthropic:claude-sonnet-4-5-20250929\"\n * });\n * ```\n *\n * @example Emulate specific tools by passing tool instances\n * ```ts\n * const middleware = toolEmulatorMiddleware({\n * tools: [getWeather, getUserLocation]\n * });\n * ```\n */\nexport declare function toolEmulatorMiddleware(options?: ToolEmulatorOptions): ReturnType<typeof createMiddleware>;\n"],"mappings":";;;;;;;;AAMA;AAAoC,UAAnBI,mBAAAA,CAAmB;EAAA;;;AAcF;AAiDlC;;EAA8C,KAAWA,CAAAA,EAAAA,CAAAA,MAAAA,GAxDnCH,UAwDmCG,GAxDtBF,UAwDsBE,CAAAA,EAAAA;EAAmB;;AAAa;;;;mBAjDpEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDGK,sBAAAA,WAAiCD,sBAAsBE,kBAAkBH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toolEmulator.d.ts","names":["BaseChatModel","ClientTool","ServerTool","createMiddleware","ToolEmulatorOptions","toolEmulatorMiddleware","ReturnType"],"sources":["../../../src/agents/middleware/toolEmulator.d.ts"],"sourcesContent":["import type { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport { createMiddleware } from \"../middleware.js\";\n/**\n * Options for configuring the Tool Emulator middleware.\n */\nexport interface ToolEmulatorOptions {\n /**\n * List of tool names (string) or tool instances to emulate.\n * - If `undefined` (default), ALL tools will be emulated.\n * - If empty array, no tools will be emulated.\n * - If array with tool names/instances, only those tools will be emulated.\n */\n tools?: (string | ClientTool | ServerTool)[];\n /**\n * Model to use for emulation.\n * - Can be a model identifier string (e.g., \"anthropic:claude-sonnet-4-5-20250929\")\n * - Can be a BaseChatModel instance\n * - Defaults to agent model\n */\n model?: string | BaseChatModel;\n}\n/**\n * Middleware that emulates specified tools using an LLM instead of executing them.\n *\n * This middleware allows selective emulation of tools for testing purposes.\n * By default (when `tools` is undefined), all tools are emulated. You can specify\n * which tools to emulate by passing a list of tool names or tool instances.\n *\n * @param options - Configuration options for the middleware\n * @param options.tools - List of tool names or tool instances to emulate. If undefined, all tools are emulated.\n * @param options.model - Model to use for emulation. Defaults to \"anthropic:claude-sonnet-4-5-20250929\".\n *\n * @example Emulate all tools (default behavior)\n * ```ts\n * import { toolEmulatorMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * const middleware = toolEmulatorMiddleware();\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [getWeather, getUserLocation, calculator],\n * middleware: [middleware],\n * });\n * ```\n *\n * @example Emulate specific tools by name\n * ```ts\n * const middleware = toolEmulatorMiddleware({\n * tools: [\"get_weather\", \"get_user_location\"]\n * });\n * ```\n *\n * @example Use a custom model for emulation\n * ```ts\n * const middleware = toolEmulatorMiddleware({\n * tools: [\"get_weather\"],\n * model: \"anthropic:claude-sonnet-4-5-20250929\"\n * });\n * ```\n *\n * @example Emulate specific tools by passing tool instances\n * ```ts\n * const middleware = toolEmulatorMiddleware({\n * tools: [getWeather, getUserLocation]\n * });\n * ```\n */\nexport declare function toolEmulatorMiddleware(options?: ToolEmulatorOptions): ReturnType<typeof createMiddleware>;\n"],"mappings":";;;;;;;;AAMA;AAAoC,UAAnBI,mBAAAA,CAAmB;EAAA;;;AAcF;AAiDlC;;EAA8C,KAAWA,CAAAA,EAAAA,CAAAA,MAAAA,GAxDnCH,UAwDmCG,GAxDtBF,UAwDsBE,CAAAA,EAAAA;EAAmB;;AAAa;;;;mBAjDpEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDGK,sBAAAA,WAAiCD,sBAAsBE,kBAAkBH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toolRetry.d.cts","names":["z","ClientTool","ServerTool","AgentMiddleware","calculateRetryDelay","ToolRetryMiddlewareOptionsSchema","ZodNumber","ZodDefault","ZodTypeDef","ZodType","ZodString","ZodUnion","ZodArray","ZodOptional","Error","ZodUnknown","ZodTuple","ZodBoolean","ZodFunction","ZodLiteral","ZodTypeAny","ZodObject","ToolRetryMiddlewareConfig","input","toolRetryMiddleware"],"sources":["../../../src/agents/middleware/toolRetry.d.ts"],"sourcesContent":["/**\n * Tool retry middleware for agents.\n */\nimport { z } from \"zod/v3\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type { AgentMiddleware } from \"./types.js\";\n/**\n * Calculate delay for a retry attempt with exponential backoff and jitter.\n *\n * @param retryNumber - The retry attempt number (0-indexed)\n * @param config - Configuration for backoff calculation\n * @returns Delay in milliseconds before next retry\n *\n * @internal Exported for testing purposes\n */\nexport declare function calculateRetryDelay(config: {\n backoffFactor: number;\n initialDelayMs: number;\n maxDelayMs: number;\n jitter: boolean;\n}, retryNumber: number): number;\n/**\n * Configuration options for the Tool Retry Middleware.\n */\nexport declare const ToolRetryMiddlewareOptionsSchema: z.ZodObject<{\n /**\n * Maximum number of retry attempts after the initial call.\n * Default is 2 retries (3 total attempts). Must be >= 0.\n */\n maxRetries: z.ZodDefault<z.ZodNumber>;\n /**\n * Optional list of tools or tool names to apply retry logic to.\n * Can be a list of `BaseTool` instances or tool name strings.\n * If `undefined`, applies to all tools. Default is `undefined`.\n */\n tools: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<ClientTool, z.ZodTypeDef, ClientTool>, z.ZodType<ServerTool, z.ZodTypeDef, ServerTool>, z.ZodString]>, \"many\">>;\n /**\n * Either an array of error constructors to retry on, or a function\n * that takes an error and returns `true` if it should be retried.\n * Default is to retry on all errors.\n */\n retryOn: z.ZodDefault<z.ZodUnion<[z.ZodFunction<z.ZodTuple<[z.ZodType<Error, z.ZodTypeDef, Error>], z.ZodUnknown>, z.ZodBoolean>, z.ZodArray<z.ZodType<new (...args: any[]) => Error, z.ZodTypeDef, new (...args: any[]) => Error>, \"many\">]>>;\n /**\n * Behavior when all retries are exhausted. Options:\n * - `\"return_message\"` (default): Return a ToolMessage with error details,\n * allowing the LLM to handle the failure and potentially recover.\n * - `\"raise\"`: Re-raise the exception, stopping agent execution.\n * - Custom function: Function that takes the exception and returns a string\n * for the ToolMessage content, allowing custom error formatting.\n */\n onFailure: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<\"raise\">, z.ZodLiteral<\"return_message\">, z.ZodFunction<z.ZodTuple<[z.ZodType<Error, z.ZodTypeDef, Error>], z.ZodUnknown>, z.ZodString>]>>;\n /**\n * Multiplier for exponential backoff. Each retry waits\n * `initialDelayMs * (backoffFactor ** retryNumber)` milliseconds.\n * Set to 0.0 for constant delay. Default is 2.0.\n */\n backoffFactor: z.ZodDefault<z.ZodNumber>;\n /**\n * Initial delay in milliseconds before first retry. Default is 1000 (1 second).\n */\n initialDelayMs: z.ZodDefault<z.ZodNumber>;\n /**\n * Maximum delay in milliseconds between retries. Caps exponential\n * backoff growth. Default is 60000 (60 seconds).\n */\n maxDelayMs: z.ZodDefault<z.ZodNumber>;\n /**\n * Whether to add random jitter (±25%) to delay to avoid thundering herd.\n * Default is `true`.\n */\n jitter: z.ZodDefault<z.ZodBoolean>;\n}, \"strip\", z.ZodTypeAny, {\n maxRetries: number;\n tools?: (string | ServerTool | ClientTool)[] | undefined;\n retryOn: (new (...args: any[]) => Error)[] | ((args_0: Error, ...args: unknown[]) => boolean);\n onFailure: \"raise\" | \"return_message\" | ((args_0: Error, ...args: unknown[]) => string);\n backoffFactor: number;\n initialDelayMs: number;\n maxDelayMs: number;\n jitter: boolean;\n}, {\n maxRetries?: number | undefined;\n tools?: (string | ServerTool | ClientTool)[] | undefined;\n retryOn?: (new (...args: any[]) => Error)[] | ((args_0: Error, ...args: unknown[]) => boolean) | undefined;\n onFailure?: \"raise\" | \"return_message\" | ((args_0: Error, ...args: unknown[]) => string) | undefined;\n backoffFactor?: number | undefined;\n initialDelayMs?: number | undefined;\n maxDelayMs?: number | undefined;\n jitter?: boolean | undefined;\n}>;\nexport type ToolRetryMiddlewareConfig = z.input<typeof ToolRetryMiddlewareOptionsSchema>;\n/**\n * Middleware that automatically retries failed tool calls with configurable backoff.\n *\n * Supports retrying on specific exceptions and exponential backoff.\n *\n * @example Basic usage with default settings (2 retries, exponential backoff)\n * ```ts\n * import { createAgent, toolRetryMiddleware } from \"langchain\";\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [searchTool],\n * middleware: [toolRetryMiddleware()],\n * });\n * ```\n *\n * @example Retry specific exceptions only\n * ```ts\n * import { toolRetryMiddleware } from \"langchain\";\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 4,\n * retryOn: [TimeoutError, NetworkError],\n * backoffFactor: 1.5,\n * });\n * ```\n *\n * @example Custom exception filtering\n * ```ts\n * function shouldRetry(error: Error): boolean {\n * // Only retry on 5xx errors\n * if (error.name === \"HTTPError\" && \"statusCode\" in error) {\n * const statusCode = (error as any).statusCode;\n * return 500 <= statusCode && statusCode < 600;\n * }\n * return false;\n * }\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 3,\n * retryOn: shouldRetry,\n * });\n * ```\n *\n * @example Apply to specific tools with custom error handling\n * ```ts\n * const formatError = (error: Error) =>\n * \"Database temporarily unavailable. Please try again later.\";\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 4,\n * tools: [\"search_database\"],\n * onFailure: formatError,\n * });\n * ```\n *\n * @example Apply to specific tools using BaseTool instances\n * ```ts\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n *\n * const searchDatabase = tool(\n * async ({ query }) => {\n * // Search implementation\n * return results;\n * },\n * {\n * name: \"search_database\",\n * description: \"Search the database\",\n * schema: z.object({ query: z.string() }),\n * }\n * );\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 4,\n * tools: [searchDatabase], // Pass BaseTool instance\n * });\n * ```\n *\n * @example Constant backoff (no exponential growth)\n * ```ts\n * const retry = toolRetryMiddleware({\n * maxRetries: 5,\n * backoffFactor: 0.0, // No exponential growth\n * initialDelayMs: 2000, // Always wait 2 seconds\n * });\n * ```\n *\n * @example Raise exception on failure\n * ```ts\n * const retry = toolRetryMiddleware({\n * maxRetries: 2,\n * onFailure: \"raise\", // Re-raise exception instead of returning message\n * });\n * ```\n *\n * @param config - Configuration options for the retry middleware\n * @returns A middleware instance that handles tool failures with retries\n */\nexport declare function toolRetryMiddleware(config?: ToolRetryMiddlewareConfig): AgentMiddleware;\n"],"mappings":";;;;;;;;;AAyCgEA,cAjB3CK,gCAiB6CI,EAjBXT,CAAAA,CAAEqB,SAiBSZ,CAAAA;EAAO;;;;EAAtB,UAAgIK,EAZnKd,CAAAA,CAAEO,UAYiKO,CAZtJd,CAAAA,CAAEM,SAYoJQ,CAAAA;EAAK;;;;;EAApJ,KAArBP,EANJP,CAAAA,CAAEa,WAMEN,CANUP,CAAAA,CAAEY,QAMZL,CANqBP,CAAAA,CAAEW,QAMvBJ,CAAAA,CANiCP,CAAAA,CAAES,OAMnCF,CAN2CN,UAM3CM,EANuDP,CAAAA,CAAEQ,UAMzDD,EANqEN,UAMrEM,CAAAA,EANkFP,CAAAA,CAAES,OAMpFF,CAN4FL,UAM5FK,EANwGP,CAAAA,CAAEQ,UAM1GD,EANsHL,UAMtHK,CAAAA,EANmIP,CAAAA,CAAEU,SAMrIH,CAAAA,CAAAA,EAAAA,MAAAA,CAAAA,CAAAA;EAAU;;;;;EASoI,OAAlCE,EAT9GT,CAAAA,CAAEO,UAS4GE,CATjGT,CAAAA,CAAEW,QAS+FF,CAAAA,CATrFT,CAAAA,CAAEkB,WASmFT,CATvET,CAAAA,CAAEgB,QASqEP,CAAAA,CAT3DT,CAAAA,CAAES,OASyDA,CATjDK,KASiDL,EAT1CT,CAAAA,CAAEQ,UASwCC,EAT5BK,KAS4BL,CAAAA,CAAAA,EATnBT,CAAAA,CAAEe,UASiBN,CAAAA,EATJT,CAAAA,CAAEiB,UASER,CAAAA,EATWT,CAAAA,CAAEY,QASbH,CATsBT,CAAAA,CAAES,OASxBA,CAAAA,KAAAA,GAAAA,IAAAA,EAAAA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AiBY,CAAA,EAAA,GAAA,SAAA;EAoGvBuB,OAAAA,EAAAA,CAAAA,KAAAA,GAAAA,IAAmB,EAAA,GAAA,EAAA,EAAA,GApHLV,KAoHK,CAAA,EAAA,GAAA,CAAA,CAAA,MAAA,EApHgBA,KAoHhB,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,EAAA,GAAA,OAAA,CAAA;EAAA,SAAA,EAAA,OAAA,GAAA,gBAAA,GAAA,CAAA,CAAA,MAAA,EAnHWA,KAmHX,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,EAAA,GAAA,MAAA,CAAA;EAAA,aAAUQ,EAAAA,MAAAA;EAAyB,cAAGnB,EAAAA,MAAAA;EAAe,UAAA,EAAA,MAAA;;;;oBA5G1ED,aAAaD;qCACIa,qBAAqBA;qDACLA;;;;;;KAM3CQ,yBAAAA,GAA4BtB,CAAAA,CAAEuB,aAAalB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoG/BmB,mBAAAA,UAA6BF,4BAA4BnB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toolRetry.d.ts","names":["z","ClientTool","ServerTool","AgentMiddleware","calculateRetryDelay","ToolRetryMiddlewareOptionsSchema","ZodNumber","ZodDefault","ZodTypeDef","ZodType","ZodString","ZodUnion","ZodArray","ZodOptional","Error","ZodUnknown","ZodTuple","ZodBoolean","ZodFunction","ZodLiteral","ZodTypeAny","ZodObject","ToolRetryMiddlewareConfig","input","toolRetryMiddleware"],"sources":["../../../src/agents/middleware/toolRetry.d.ts"],"sourcesContent":["/**\n * Tool retry middleware for agents.\n */\nimport { z } from \"zod/v3\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type { AgentMiddleware } from \"./types.js\";\n/**\n * Calculate delay for a retry attempt with exponential backoff and jitter.\n *\n * @param retryNumber - The retry attempt number (0-indexed)\n * @param config - Configuration for backoff calculation\n * @returns Delay in milliseconds before next retry\n *\n * @internal Exported for testing purposes\n */\nexport declare function calculateRetryDelay(config: {\n backoffFactor: number;\n initialDelayMs: number;\n maxDelayMs: number;\n jitter: boolean;\n}, retryNumber: number): number;\n/**\n * Configuration options for the Tool Retry Middleware.\n */\nexport declare const ToolRetryMiddlewareOptionsSchema: z.ZodObject<{\n /**\n * Maximum number of retry attempts after the initial call.\n * Default is 2 retries (3 total attempts). Must be >= 0.\n */\n maxRetries: z.ZodDefault<z.ZodNumber>;\n /**\n * Optional list of tools or tool names to apply retry logic to.\n * Can be a list of `BaseTool` instances or tool name strings.\n * If `undefined`, applies to all tools. Default is `undefined`.\n */\n tools: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<ClientTool, z.ZodTypeDef, ClientTool>, z.ZodType<ServerTool, z.ZodTypeDef, ServerTool>, z.ZodString]>, \"many\">>;\n /**\n * Either an array of error constructors to retry on, or a function\n * that takes an error and returns `true` if it should be retried.\n * Default is to retry on all errors.\n */\n retryOn: z.ZodDefault<z.ZodUnion<[z.ZodFunction<z.ZodTuple<[z.ZodType<Error, z.ZodTypeDef, Error>], z.ZodUnknown>, z.ZodBoolean>, z.ZodArray<z.ZodType<new (...args: any[]) => Error, z.ZodTypeDef, new (...args: any[]) => Error>, \"many\">]>>;\n /**\n * Behavior when all retries are exhausted. Options:\n * - `\"return_message\"` (default): Return a ToolMessage with error details,\n * allowing the LLM to handle the failure and potentially recover.\n * - `\"raise\"`: Re-raise the exception, stopping agent execution.\n * - Custom function: Function that takes the exception and returns a string\n * for the ToolMessage content, allowing custom error formatting.\n */\n onFailure: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<\"raise\">, z.ZodLiteral<\"return_message\">, z.ZodFunction<z.ZodTuple<[z.ZodType<Error, z.ZodTypeDef, Error>], z.ZodUnknown>, z.ZodString>]>>;\n /**\n * Multiplier for exponential backoff. Each retry waits\n * `initialDelayMs * (backoffFactor ** retryNumber)` milliseconds.\n * Set to 0.0 for constant delay. Default is 2.0.\n */\n backoffFactor: z.ZodDefault<z.ZodNumber>;\n /**\n * Initial delay in milliseconds before first retry. Default is 1000 (1 second).\n */\n initialDelayMs: z.ZodDefault<z.ZodNumber>;\n /**\n * Maximum delay in milliseconds between retries. Caps exponential\n * backoff growth. Default is 60000 (60 seconds).\n */\n maxDelayMs: z.ZodDefault<z.ZodNumber>;\n /**\n * Whether to add random jitter (±25%) to delay to avoid thundering herd.\n * Default is `true`.\n */\n jitter: z.ZodDefault<z.ZodBoolean>;\n}, \"strip\", z.ZodTypeAny, {\n maxRetries: number;\n tools?: (string | ServerTool | ClientTool)[] | undefined;\n retryOn: (new (...args: any[]) => Error)[] | ((args_0: Error, ...args: unknown[]) => boolean);\n onFailure: \"raise\" | \"return_message\" | ((args_0: Error, ...args: unknown[]) => string);\n backoffFactor: number;\n initialDelayMs: number;\n maxDelayMs: number;\n jitter: boolean;\n}, {\n maxRetries?: number | undefined;\n tools?: (string | ServerTool | ClientTool)[] | undefined;\n retryOn?: (new (...args: any[]) => Error)[] | ((args_0: Error, ...args: unknown[]) => boolean) | undefined;\n onFailure?: \"raise\" | \"return_message\" | ((args_0: Error, ...args: unknown[]) => string) | undefined;\n backoffFactor?: number | undefined;\n initialDelayMs?: number | undefined;\n maxDelayMs?: number | undefined;\n jitter?: boolean | undefined;\n}>;\nexport type ToolRetryMiddlewareConfig = z.input<typeof ToolRetryMiddlewareOptionsSchema>;\n/**\n * Middleware that automatically retries failed tool calls with configurable backoff.\n *\n * Supports retrying on specific exceptions and exponential backoff.\n *\n * @example Basic usage with default settings (2 retries, exponential backoff)\n * ```ts\n * import { createAgent, toolRetryMiddleware } from \"langchain\";\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [searchTool],\n * middleware: [toolRetryMiddleware()],\n * });\n * ```\n *\n * @example Retry specific exceptions only\n * ```ts\n * import { toolRetryMiddleware } from \"langchain\";\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 4,\n * retryOn: [TimeoutError, NetworkError],\n * backoffFactor: 1.5,\n * });\n * ```\n *\n * @example Custom exception filtering\n * ```ts\n * function shouldRetry(error: Error): boolean {\n * // Only retry on 5xx errors\n * if (error.name === \"HTTPError\" && \"statusCode\" in error) {\n * const statusCode = (error as any).statusCode;\n * return 500 <= statusCode && statusCode < 600;\n * }\n * return false;\n * }\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 3,\n * retryOn: shouldRetry,\n * });\n * ```\n *\n * @example Apply to specific tools with custom error handling\n * ```ts\n * const formatError = (error: Error) =>\n * \"Database temporarily unavailable. Please try again later.\";\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 4,\n * tools: [\"search_database\"],\n * onFailure: formatError,\n * });\n * ```\n *\n * @example Apply to specific tools using BaseTool instances\n * ```ts\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n *\n * const searchDatabase = tool(\n * async ({ query }) => {\n * // Search implementation\n * return results;\n * },\n * {\n * name: \"search_database\",\n * description: \"Search the database\",\n * schema: z.object({ query: z.string() }),\n * }\n * );\n *\n * const retry = toolRetryMiddleware({\n * maxRetries: 4,\n * tools: [searchDatabase], // Pass BaseTool instance\n * });\n * ```\n *\n * @example Constant backoff (no exponential growth)\n * ```ts\n * const retry = toolRetryMiddleware({\n * maxRetries: 5,\n * backoffFactor: 0.0, // No exponential growth\n * initialDelayMs: 2000, // Always wait 2 seconds\n * });\n * ```\n *\n * @example Raise exception on failure\n * ```ts\n * const retry = toolRetryMiddleware({\n * maxRetries: 2,\n * onFailure: \"raise\", // Re-raise exception instead of returning message\n * });\n * ```\n *\n * @param config - Configuration options for the retry middleware\n * @returns A middleware instance that handles tool failures with retries\n */\nexport declare function toolRetryMiddleware(config?: ToolRetryMiddlewareConfig): AgentMiddleware;\n"],"mappings":";;;;;;;;;AAyCgEA,cAjB3CK,gCAiB6CI,EAjBXT,CAAAA,CAAEqB,SAiBSZ,CAAAA;EAAO;;;;EAAtB,UAA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AA,EAAA,EAAA,GAAA,MAAA,CAAA;EAAA,aAAUQ,EAAAA,MAAAA;EAAyB,cAAGnB,EAAAA,MAAAA;EAAe,UAAA,EAAA,MAAA;;;;oBA5G1ED,aAAaD;qCACIa,qBAAqBA;qDACLA;;;;;;KAM3CQ,yBAAAA,GAA4BtB,CAAAA,CAAEuB,aAAalB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoG/BmB,mBAAAA,UAA6BF,4BAA4BnB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.cts","names":["InteropZodObject","InteropZodDefault","InteropZodOptional","InferInteropZodInput","InferInteropZodOutput","InteropZodToStateDefinition","AnnotationRoot","AIMessage","ToolMessage","ToolCall","Command","ClientTool","ServerTool","JumpToTarget","Runtime","AgentBuiltInState","ModelRequest","PromiseOrValue","T","Promise","AnyAnnotationRoot","NormalizedSchemaInput","TSchema","Record","MiddlewareResult","TState","ToolCallRequest","TContext","ToolCallHandler","WrapToolCallHook","WrapModelCallHandler","WrapModelCallHook","BeforeAgentHandler","Partial","BeforeAgentHook","BeforeModelHandler","BeforeModelHook","AfterModelHandler","AfterModelHook","AfterAgentHandler","AfterAgentHook","AgentMiddleware","TContextSchema","TFullContext","FilterPrivateProps","K","InferChannelType","ToAnnotationRoot","InferMiddlewareState","S","InferMiddlewareInputState","InferMiddlewareStates","First","Rest","InferMiddlewareInputStates","InferMergedState","InferMergedInputState","InferMiddlewareContext","C","InferMiddlewareContextInput","Inner","InferMiddlewareContexts","MergeContextTypes","A","B","InferMiddlewareContextInputs","InferContextInput","ContextSchema","InferSchemaInput"],"sources":["../../../src/agents/middleware/types.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { InteropZodObject, InteropZodDefault, InteropZodOptional, InferInteropZodInput, InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport type { AnnotationRoot } from \"@langchain/langgraph\";\nimport type { AIMessage, ToolMessage } from \"@langchain/core/messages\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { Command } from \"@langchain/langgraph\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type { JumpToTarget } from \"../constants.js\";\nimport type { Runtime, AgentBuiltInState } from \"../runtime.js\";\nimport type { ModelRequest } from \"../nodes/types.js\";\ntype PromiseOrValue<T> = T | Promise<T>;\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\nexport type NormalizedSchemaInput<TSchema extends InteropZodObject | undefined | never = any> = [TSchema] extends [never] ? AgentBuiltInState : TSchema extends InteropZodObject ? InferInteropZodOutput<TSchema> & AgentBuiltInState : TSchema extends Record<string, unknown> ? TSchema & AgentBuiltInState : AgentBuiltInState;\n/**\n * Result type for middleware functions.\n */\nexport type MiddlewareResult<TState> = (TState & {\n jumpTo?: JumpToTarget;\n}) | void;\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<TState extends Record<string, unknown> = Record<string, unknown>, TContext = unknown> {\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 tool: ClientTool | ServerTool;\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 * 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<TSchema extends Record<string, unknown> = AgentBuiltInState, TContext = unknown> = (request: ToolCallRequest<TSchema, TContext>) => PromiseOrValue<ToolMessage | Command>;\n/**\n * Wrapper function type for the wrapToolCall hook.\n * Allows middleware to intercept and modify tool execution.\n */\nexport type WrapToolCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ToolCallRequest<NormalizedSchemaInput<TSchema>, TContext>, handler: ToolCallHandler<NormalizedSchemaInput<TSchema>, TContext>) => PromiseOrValue<ToolMessage | Command>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>) => PromiseOrValue<AIMessage>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>, handler: WrapModelCallHandler<TSchema, TContext>) => PromiseOrValue<AIMessage>;\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeAgentHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: BeforeAgentHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeModelHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: BeforeModelHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterModelHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: AfterModelHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterAgentHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: AfterAgentHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\n};\n/**\n * Base middleware interface.\n */\nexport interface AgentMiddleware<TSchema extends InteropZodObject | undefined = any, TContextSchema extends InteropZodObject | InteropZodDefault<InteropZodObject> | InteropZodOptional<InteropZodObject> | undefined = any, TFullContext = any> {\n /**\n * The name of the middleware.\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is 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 stateSchema?: TSchema;\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 * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\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 * 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 * 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 * 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 * 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 * 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 * 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};\nexport type InferChannelType<T extends AnyAnnotationRoot | InteropZodObject> = T extends AnyAnnotationRoot ? ToAnnotationRoot<T>[\"State\"] : T extends InteropZodObject ? InferInteropZodInput<T> : {};\n/**\n * Helper type to infer the state schema type from a middleware\n * This filters out private properties (those starting with underscore)\n */\nexport type InferMiddlewareState<T extends AgentMiddleware> = T extends AgentMiddleware<infer S, any, any> ? S extends InteropZodObject ? FilterPrivateProps<InferInteropZodOutput<S>> : {} : {};\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 */\nexport type InferMiddlewareInputState<T extends AgentMiddleware> = T extends AgentMiddleware<infer S, any, any> ? S extends InteropZodObject ? FilterPrivateProps<InferInteropZodInput<S>> : {} : {};\n/**\n * Helper type to infer merged state from an array of middleware (just the middleware states)\n */\nexport type InferMiddlewareStates<T = AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? InferMiddlewareState<First> & InferMiddlewareStates<Rest> : InferMiddlewareState<First> : {} : {};\n/**\n * Helper type to infer merged input state from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareInputStates<T extends readonly AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? InferMiddlewareInputState<First> & InferMiddlewareInputStates<Rest> : InferMiddlewareInputState<First> : {} : {};\n/**\n * Helper type to infer merged state from an array of middleware (includes built-in state)\n */\nexport type InferMergedState<T extends readonly AgentMiddleware[]> = InferMiddlewareStates<T> & AgentBuiltInState;\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 AgentMiddleware[]> = InferMiddlewareInputStates<T> & AgentBuiltInState;\n/**\n * Helper type to infer the context schema type from a middleware\n */\nexport type InferMiddlewareContext<T extends AgentMiddleware> = T extends AgentMiddleware<any, infer C, any> ? C extends InteropZodObject ? InferInteropZodInput<C> : {} : {};\n/**\n * Helper type to infer the input context schema type from a middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInput<T extends AgentMiddleware> = T extends AgentMiddleware<any, infer C, any> ? C extends InteropZodOptional<infer Inner> ? InferInteropZodInput<Inner> | undefined : C extends InteropZodObject ? InferInteropZodInput<C> : {} : {};\n/**\n * Helper type to infer merged context from an array of middleware\n */\nexport type InferMiddlewareContexts<T extends readonly AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? InferMiddlewareContext<First> & InferMiddlewareContexts<Rest> : InferMiddlewareContext<First> : {} : {};\n/**\n * Helper to merge two context types, preserving undefined unions\n */\ntype MergeContextTypes<A, B> = [A] extends [undefined] ? [B] extends [undefined] ? undefined : B | undefined : [B] extends [undefined] ? A | undefined : [A] extends [B] ? A : [B] extends [A] ? B : A & B;\n/**\n * Helper type to infer merged input context from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInputs<T extends readonly AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? MergeContextTypes<InferMiddlewareContextInput<First>, InferMiddlewareContextInputs<Rest>> : InferMiddlewareContextInput<First> : {} : {};\n/**\n * Helper type to extract input type from context schema (with optional defaults)\n */\nexport type InferContextInput<ContextSchema extends AnyAnnotationRoot | InteropZodObject> = ContextSchema extends InteropZodObject ? InferInteropZodInput<ContextSchema> : ContextSchema extends AnyAnnotationRoot ? ToAnnotationRoot<ContextSchema>[\"State\"] : {};\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\nexport type InferSchemaInput<A extends AnyAnnotationRoot | InteropZodObject | undefined> = A extends AnyAnnotationRoot | InteropZodObject ? ToAnnotationRoot<A>[\"State\"] : {};\nexport {};\n"],"mappings":";;;;;;;;;;;AAUsD,KACjDiB,cAAAA,CAAAA,CAAc,CAAA,GAAMC,CAAN,GAAUC,OAAV,CAAkBD,CAAlB,CAAA;AAAA,KACPE,iBAAAA,GAAoBd,cADb,CAAA,GAAA,CAAA;AAAMY,KAEbG,qBAFaH,CAAAA,gBAEyBlB,gBAFzBkB,GAAAA,SAAAA,GAAAA,KAAAA,GAAAA,GAAAA,CAAAA,GAAAA,CAEwEI,OAFxEJ,CAAAA,SAAAA,CAAAA,KAAAA,CAAAA,GAEmGH,iBAFnGG,GAEuHI,OAFvHJ,SAEuIlB,gBAFvIkB,GAE0Jd,qBAF1Jc,CAEgLI,OAFhLJ,CAAAA,GAE2LH,iBAF3LG,GAE+MI,O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0CoB,GAAAA,SAAAA,CAAAA,GAAV2C,CAAU3C,SAAAA,iBAAAA,GAAoBpB,gBAApBoB,GAAuC2B,gBAAvC3B,CAAwD2C,CAAxD3C,CAAAA,CAAAA,OAAAA,CAAAA,GAAAA,CAAAA,CAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","names":["InteropZodObject","InteropZodDefault","InteropZodOptional","InferInteropZodInput","InferInteropZodOutput","InteropZodToStateDefinition","AnnotationRoot","AIMessage","ToolMessage","ToolCall","Command","ClientTool","ServerTool","JumpToTarget","Runtime","AgentBuiltInState","ModelRequest","PromiseOrValue","T","Promise","AnyAnnotationRoot","NormalizedSchemaInput","TSchema","Record","MiddlewareResult","TState","ToolCallRequest","TContext","ToolCallHandler","WrapToolCallHook","WrapModelCallHandler","WrapModelCallHook","BeforeAgentHandler","Partial","BeforeAgentHook","BeforeModelHandler","BeforeModelHook","AfterModelHandler","AfterModelHook","AfterAgentHandler","AfterAgentHook","AgentMiddleware","TContextSchema","TFullContext","FilterPrivateProps","K","InferChannelType","ToAnnotationRoot","InferMiddlewareState","S","InferMiddlewareInputState","InferMiddlewareStates","First","Rest","InferMiddlewareInputStates","InferMergedState","InferMergedInputState","InferMiddlewareContext","C","InferMiddlewareContextInput","Inner","InferMiddlewareContexts","MergeContextTypes","A","B","InferMiddlewareContextInputs","InferContextInput","ContextSchema","InferSchemaInput"],"sources":["../../../src/agents/middleware/types.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { InteropZodObject, InteropZodDefault, InteropZodOptional, InferInteropZodInput, InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport type { AnnotationRoot } from \"@langchain/langgraph\";\nimport type { AIMessage, ToolMessage } from \"@langchain/core/messages\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { Command } from \"@langchain/langgraph\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type { JumpToTarget } from \"../constants.js\";\nimport type { Runtime, AgentBuiltInState } from \"../runtime.js\";\nimport type { ModelRequest } from \"../nodes/types.js\";\ntype PromiseOrValue<T> = T | Promise<T>;\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\nexport type NormalizedSchemaInput<TSchema extends InteropZodObject | undefined | never = any> = [TSchema] extends [never] ? AgentBuiltInState : TSchema extends InteropZodObject ? InferInteropZodOutput<TSchema> & AgentBuiltInState : TSchema extends Record<string, unknown> ? TSchema & AgentBuiltInState : AgentBuiltInState;\n/**\n * Result type for middleware functions.\n */\nexport type MiddlewareResult<TState> = (TState & {\n jumpTo?: JumpToTarget;\n}) | void;\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<TState extends Record<string, unknown> = Record<string, unknown>, TContext = unknown> {\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 tool: ClientTool | ServerTool;\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 * 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<TSchema extends Record<string, unknown> = AgentBuiltInState, TContext = unknown> = (request: ToolCallRequest<TSchema, TContext>) => PromiseOrValue<ToolMessage | Command>;\n/**\n * Wrapper function type for the wrapToolCall hook.\n * Allows middleware to intercept and modify tool execution.\n */\nexport type WrapToolCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ToolCallRequest<NormalizedSchemaInput<TSchema>, TContext>, handler: ToolCallHandler<NormalizedSchemaInput<TSchema>, TContext>) => PromiseOrValue<ToolMessage | Command>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>) => PromiseOrValue<AIMessage>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>, handler: WrapModelCallHandler<TSchema, TContext>) => PromiseOrValue<AIMessage>;\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeAgentHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: BeforeAgentHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeModelHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: BeforeModelHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterModelHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: AfterModelHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\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> = (state: TSchema, runtime: Runtime<TContext>) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;\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<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterAgentHandler<NormalizedSchemaInput<TSchema>, TContext> | {\n hook: AfterAgentHandler<NormalizedSchemaInput<TSchema>, TContext>;\n canJumpTo?: JumpToTarget[];\n};\n/**\n * Base middleware interface.\n */\nexport interface AgentMiddleware<TSchema extends InteropZodObject | undefined = any, TContextSchema extends InteropZodObject | InteropZodDefault<InteropZodObject> | InteropZodOptional<InteropZodObject> | undefined = any, TFullContext = any> {\n /**\n * The name of the middleware.\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is 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 stateSchema?: TSchema;\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 * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\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 * 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 * 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 * 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 * 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 * 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 * 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};\nexport type InferChannelType<T extends AnyAnnotationRoot | InteropZodObject> = T extends AnyAnnotationRoot ? ToAnnotationRoot<T>[\"State\"] : T extends InteropZodObject ? InferInteropZodInput<T> : {};\n/**\n * Helper type to infer the state schema type from a middleware\n * This filters out private properties (those starting with underscore)\n */\nexport type InferMiddlewareState<T extends AgentMiddleware> = T extends AgentMiddleware<infer S, any, any> ? S extends InteropZodObject ? FilterPrivateProps<InferInteropZodOutput<S>> : {} : {};\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 */\nexport type InferMiddlewareInputState<T extends AgentMiddleware> = T extends AgentMiddleware<infer S, any, any> ? S extends InteropZodObject ? FilterPrivateProps<InferInteropZodInput<S>> : {} : {};\n/**\n * Helper type to infer merged state from an array of middleware (just the middleware states)\n */\nexport type InferMiddlewareStates<T = AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? InferMiddlewareState<First> & InferMiddlewareStates<Rest> : InferMiddlewareState<First> : {} : {};\n/**\n * Helper type to infer merged input state from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareInputStates<T extends readonly AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? InferMiddlewareInputState<First> & InferMiddlewareInputStates<Rest> : InferMiddlewareInputState<First> : {} : {};\n/**\n * Helper type to infer merged state from an array of middleware (includes built-in state)\n */\nexport type InferMergedState<T extends readonly AgentMiddleware[]> = InferMiddlewareStates<T> & AgentBuiltInState;\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 AgentMiddleware[]> = InferMiddlewareInputStates<T> & AgentBuiltInState;\n/**\n * Helper type to infer the context schema type from a middleware\n */\nexport type InferMiddlewareContext<T extends AgentMiddleware> = T extends AgentMiddleware<any, infer C, any> ? C extends InteropZodObject ? InferInteropZodInput<C> : {} : {};\n/**\n * Helper type to infer the input context schema type from a middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInput<T extends AgentMiddleware> = T extends AgentMiddleware<any, infer C, any> ? C extends InteropZodOptional<infer Inner> ? InferInteropZodInput<Inner> | undefined : C extends InteropZodObject ? InferInteropZodInput<C> : {} : {};\n/**\n * Helper type to infer merged context from an array of middleware\n */\nexport type InferMiddlewareContexts<T extends readonly AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? InferMiddlewareContext<First> & InferMiddlewareContexts<Rest> : InferMiddlewareContext<First> : {} : {};\n/**\n * Helper to merge two context types, preserving undefined unions\n */\ntype MergeContextTypes<A, B> = [A] extends [undefined] ? [B] extends [undefined] ? undefined : B | undefined : [B] extends [undefined] ? A | undefined : [A] extends [B] ? A : [B] extends [A] ? B : A & B;\n/**\n * Helper type to infer merged input context from an array of middleware (with optional defaults)\n */\nexport type InferMiddlewareContextInputs<T extends readonly AgentMiddleware[]> = T extends readonly [] ? {} : T extends readonly [infer First, ...infer Rest] ? First extends AgentMiddleware ? Rest extends readonly AgentMiddleware[] ? MergeContextTypes<InferMiddlewareContextInput<First>, InferMiddlewareContextInputs<Rest>> : InferMiddlewareContextInput<First> : {} : {};\n/**\n * Helper type to extract input type from context schema (with optional defaults)\n */\nexport type InferContextInput<ContextSchema extends AnyAnnotationRoot | InteropZodObject> = ContextSchema extends InteropZodObject ? InferInteropZodInput<ContextSchema> : ContextSchema extends AnyAnnotationRoot ? ToAnnotationRoot<ContextSchema>[\"State\"] : {};\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\nexport type InferSchemaInput<A extends AnyAnnotationRoot | InteropZodObject | undefined> = A extends AnyAnnotationRoot | InteropZodObject ? ToAnnotationRoot<A>[\"State\"] : {};\nexport {};\n"],"mappings":";;;;;;;;;;;AAUsD,KACjDiB,cAAAA,CAAAA,CAAc,CAAA,GAAMC,CAAN,GAAUC,OAAV,CAAkBD,CAAlB,CAAA;AAAA,KACPE,iBAAAA,GAAoBd,cADb,CAAA,GAAA,CAAA;AAAMY,KAEbG,qBAFaH,CAAAA,gBAEyBlB,gBAFzBkB,GAAAA,SAAAA,GAAAA,KAAAA,GAAAA,GAAAA,CAAAA,GAAAA,CAEwEI,OAFxEJ,CAAAA,SAAAA,CAAAA,KAAAA,CAAAA,GAEmGH,iBAFnGG,GAEuHI,OAFvHJ,SAEuIlB,gBAFvIkB,GAE0Jd,qBAF1Jc,CAEgLI,OAFhLJ,CAAAA,GAE2LH,iBAF3LG,GAE+MI,OAF/MJ,SAE+NK,MAF/NL,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GAEyPI,OAFzPJ,GAEmQH,iBAFnQG,GAEuRH,iBAFvRG;;;AAAW;AACxBE,KAKAI,gBALiB,CAAA,MAAA,CAAGlB,GAAAA,CAKQmB,MALRnB,GAAAA;EACpBe,MAAA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d.cts","names":["__types_js0","BaseMessage","AfterModelHook","AfterAgentHook","BeforeAgentHook","BeforeModelHook","JumpToTarget","countTokensApproximately","getHookConstraint","getHookFunction","___runtime_js0","AgentBuiltInState","Runtime","Partial","MiddlewareResult","Promise","sleep"],"sources":["../../../src/agents/middleware/utils.d.ts"],"sourcesContent":["import { type BaseMessage } from \"@langchain/core/messages\";\nimport { AfterModelHook, AfterAgentHook, BeforeAgentHook, BeforeModelHook } from \"./types.js\";\nimport { JumpToTarget } from \"../constants.js\";\n/**\n * Default token counter that approximates based on character count\n * @param messages Messages to count tokens for\n * @returns Approximate token count\n */\nexport declare function countTokensApproximately(messages: BaseMessage[]): number;\nexport declare function getHookConstraint(hook: BeforeAgentHook | BeforeModelHook | AfterAgentHook | AfterModelHook | undefined): JumpToTarget[] | undefined;\nexport declare function getHookFunction(arg: BeforeAgentHook | BeforeModelHook | AfterAgentHook | AfterModelHook): ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>) | ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>) | ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>) | ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>);\n/**\n * Sleep for the specified number of milliseconds.\n */\nexport declare function sleep(ms: number): Promise<void>;\n"],"mappings":";;;;AAQA;;;;;iBAAwBO,wBAAAA,WAAmCN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","names":["__types_js3","BaseMessage","AfterModelHook","AfterAgentHook","BeforeAgentHook","BeforeModelHook","JumpToTarget","countTokensApproximately","getHookConstraint","getHookFunction","___runtime_js0","AgentBuiltInState","Runtime","Partial","MiddlewareResult","Promise","sleep"],"sources":["../../../src/agents/middleware/utils.d.ts"],"sourcesContent":["import { type BaseMessage } from \"@langchain/core/messages\";\nimport { AfterModelHook, AfterAgentHook, BeforeAgentHook, BeforeModelHook } from \"./types.js\";\nimport { JumpToTarget } from \"../constants.js\";\n/**\n * Default token counter that approximates based on character count\n * @param messages Messages to count tokens for\n * @returns Approximate token count\n */\nexport declare function countTokensApproximately(messages: BaseMessage[]): number;\nexport declare function getHookConstraint(hook: BeforeAgentHook | BeforeModelHook | AfterAgentHook | AfterModelHook | undefined): JumpToTarget[] | undefined;\nexport declare function getHookFunction(arg: BeforeAgentHook | BeforeModelHook | AfterAgentHook | AfterModelHook): ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>) | ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>) | ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>) | ((state: import(\"../runtime.js\").AgentBuiltInState, runtime: import(\"../runtime.js\").Runtime<unknown>) => Promise<import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>> | import(\"./types.js\").MiddlewareResult<Partial<import(\"../runtime.js\").AgentBuiltInState>>);\n/**\n * Sleep for the specified number of milliseconds.\n */\nexport declare function sleep(ms: number): Promise<void>;\n"],"mappings":";;;;AAQA;;;;;iBAAwBO,wBAAAA,WAAmCN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.d.cts","names":["InteropZodObject","InferInteropZodOutput","ClientTool","ServerTool","AgentMiddleware","WrapToolCallHook","WrapModelCallHook","BeforeAgentHook","BeforeModelHook","AfterModelHook","AfterAgentHook","createMiddleware","TSchema","TContextSchema","NormalizeContextSchema"],"sources":["../../src/agents/middleware.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { InteropZodObject, InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type { AgentMiddleware, WrapToolCallHook, WrapModelCallHook, BeforeAgentHook, BeforeModelHook, AfterModelHook, AfterAgentHook } from \"./middleware/types.js\";\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.wrapModelCall - The function to wrap model invocation\n * @param config.wrapToolCall - The function to wrap tool invocation\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @param config.beforeAgent - The function to run before the agent execution starts\n * @param config.afterAgent - The function to run after the agent execution completes\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport declare function createMiddleware<TSchema extends InteropZodObject | undefined = undefined, TContextSchema extends InteropZodObject | undefined = undefined>(config: {\n /**\n * The name of the middleware\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is 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 stateSchema?: TSchema;\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 * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\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 wrapToolCall?: WrapToolCallHook<TSchema, NormalizeContextSchema<TContextSchema>>;\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 * The request parameter contains: model, messages, systemPrompt, tools, state, and runtime.\n *\n * @param request - The model request containing all the parameters needed.\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\n}): AgentMiddleware<TSchema, TContextSchema, any>;\ntype NormalizeContextSchema<TContextSchema extends InteropZodObject | undefined = undefined> = TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : never;\nexport {};\n"],"mappings":";;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IoBY,iBA7IID,gBA6IJC,CAAAA,gBA7IqCZ,gBA6IrCY,GAAAA,SAAAA,GAAAA,SAAAA,EAAAA,uBA7IsGZ,gBA6ItGY,GAAAA,SAAAA,GAAAA,SAAAA,CAAAA,CAAAA,MAAAA,EAAAA;EAAO;;AAAR;EACdE,IAAAA,EAAAA,MAAAA;EAAsB;;;;;;AAAmI;gBAlI5IF;;;;;;;;kBAQEC;;;;WAIPX,aAAaC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDPE,iBAAiBO,SAASE,uBAAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA+BhDP,kBAAkBM,SAASE,uBAAuBD;;;;;;;;;gBASpDN,gBAAgBK,SAASE,uBAAuBD;;;;;;;;;gBAShDL,gBAAgBI,SAASE,uBAAuBD;;;;;;;;;eASjDJ,eAAeG,SAASE,uBAAuBD;;;;;;;;;eAS/CH,eAAeE,SAASE,uBAAuBD;IAC5DT,gBAAgBQ,SAASC;KACxBC,8CAA8Cd,4CAA4Ca,uBAAuBb,mBAAmBC,sBAAsBY"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.d.ts","names":["InteropZodObject","InferInteropZodOutput","ClientTool","ServerTool","AgentMiddleware","WrapToolCallHook","WrapModelCallHook","BeforeAgentHook","BeforeModelHook","AfterModelHook","AfterAgentHook","createMiddleware","TSchema","TContextSchema","NormalizeContextSchema"],"sources":["../../src/agents/middleware.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { InteropZodObject, InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport type { ClientTool, ServerTool } from \"@langchain/core/tools\";\nimport type { AgentMiddleware, WrapToolCallHook, WrapModelCallHook, BeforeAgentHook, BeforeModelHook, AfterModelHook, AfterAgentHook } from \"./middleware/types.js\";\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.wrapModelCall - The function to wrap model invocation\n * @param config.wrapToolCall - The function to wrap tool invocation\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @param config.beforeAgent - The function to run before the agent execution starts\n * @param config.afterAgent - The function to run after the agent execution completes\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport declare function createMiddleware<TSchema extends InteropZodObject | undefined = undefined, TContextSchema extends InteropZodObject | undefined = undefined>(config: {\n /**\n * The name of the middleware\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is 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 stateSchema?: TSchema;\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 * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\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 wrapToolCall?: WrapToolCallHook<TSchema, NormalizeContextSchema<TContextSchema>>;\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 * The request parameter contains: model, messages, systemPrompt, tools, state, and runtime.\n *\n * @param request - The model request containing all the parameters needed.\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\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, NormalizeContextSchema<TContextSchema>>;\n}): AgentMiddleware<TSchema, TContextSchema, any>;\ntype NormalizeContextSchema<TContextSchema extends InteropZodObject | undefined = undefined> = TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : never;\nexport {};\n"],"mappings":";;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IoBY,iBA7IID,gBA6IJC,CAAAA,gBA7IqCZ,gBA6IrCY,GAAAA,SAAAA,GAAAA,SAAAA,EAAAA,uBA7IsGZ,gBA6ItGY,GAAAA,SAAAA,GAAAA,SAAAA,CAAAA,CAAAA,MAAAA,EAAAA;EAAO;;AAAR;EACdE,IAAAA,EAAAA,MAAAA;EAAsB;;;;;;AAAmI;gBAlI5IF;;;;;;;;kBAQEC;;;;WAIPX,aAAaC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDPE,iBAAiBO,SAASE,uBAAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA+BhDP,kBAAkBM,SAASE,uBAAuBD;;;;;;;;;gBASpDN,gBAAgBK,SAASE,uBAAuBD;;;;;;;;;gBAShDL,gBAAgBI,SAASE,uBAAuBD;;;;;;;;;eASjDJ,eAAeG,SAASE,uBAAuBD;;;;;;;;;eAS/CH,eAAeE,SAASE,uBAAuBD;IAC5DT,gBAAgBQ,SAASC;KACxBC,8CAA8Cd,4CAA4Ca,uBAAuBb,mBAAmBC,sBAAsBY"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.cts","names":["LanguageModelLike","BaseMessage","ServerTool","ClientTool","Runtime","AgentBuiltInState","ModelRequest","Record","TState","TContext"],"sources":["../../../src/agents/nodes/types.d.ts"],"sourcesContent":["import type { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { ServerTool, ClientTool } from \"@langchain/core/tools\";\nimport type { Runtime, AgentBuiltInState } from \"../runtime.js\";\n/**\n * Configuration for modifying a model call at runtime.\n * All fields are optional and only provided fields will override defaults.\n *\n * @template TState - The agent's state type, must extend Record<string, unknown>. Defaults to Record<string, unknown>.\n * @template TContext - The runtime context type for accessing metadata and control flow. Defaults to unknown.\n */\nexport interface ModelRequest<TState extends Record<string, unknown> = Record<string, unknown>, TContext = unknown> {\n /**\n * The model to use for this step.\n */\n model: LanguageModelLike;\n /**\n * The messages to send to the model.\n */\n messages: BaseMessage[];\n /**\n * The system message for this step.\n */\n systemPrompt?: string;\n /**\n * Tool choice configuration (model-specific format).\n * Can be one of:\n * - `\"auto\"`: means the model can pick between generating a message or calling one or more tools.\n * - `\"none\"`: means the model will not call any tool and instead generates a message.\n * - `\"required\"`: means the model must call one or more tools.\n * - `{ type: \"function\", function: { name: string } }`: The model will use the specified function.\n */\n toolChoice?: \"auto\" | \"none\" | \"required\" | {\n type: \"function\";\n function: {\n name: string;\n };\n };\n /**\n * The tools to make available for this step.\n */\n tools: (ServerTool | ClientTool)[];\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 * Additional settings to bind to the model when preparing it for invocation.\n * These settings are applied via `bindTools()` and can include parameters like\n * `headers`, `container`, etc. The model is re-bound on each request,\n * so these settings can vary per invocation.\n *\n * @example\n * ```ts\n * modelSettings: {\n * headers: { \"anthropic-beta\": \"code-execution-2025-08-25\" },\n * container: \"container_abc123\"\n * }\n * ```\n */\n modelSettings?: Record<string, unknown>;\n}\n"],"mappings":";;;;;;;;;AAWA;;;;;AAQcC,UARGK,YAQHL,CAAAA,eAR+BM,MAQ/BN,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GARyDM,MAQzDN,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,WAAAA,OAAAA,CAAAA,CAAAA;EAAW;;;EA0BR,KAAGI,EA9BTL,iBA8BSK;EAAiB;;;EAmBX,QAAA,EA7CZJ,WA6CY,EAAA;;;;;;;;;;;;;;;;;;;;;;UAvBdC,aAAaC;;;;SAIdK,SAASH;;;;WAIPD,QAAQK;;;;;;;;;;;;;;;kBAeDF"}