langchain 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/agents/ReactAgent.cjs +21 -41
- package/dist/agents/ReactAgent.cjs.map +1 -1
- package/dist/agents/ReactAgent.js +21 -41
- package/dist/agents/ReactAgent.js.map +1 -1
- package/dist/agents/annotation.cjs +1 -0
- package/dist/agents/annotation.cjs.map +1 -1
- package/dist/agents/annotation.js +1 -0
- package/dist/agents/annotation.js.map +1 -1
- package/dist/agents/middleware/callLimit.d.cts.map +1 -1
- package/dist/agents/middleware/callLimit.d.ts.map +1 -1
- package/dist/agents/middleware/contextEditing.d.cts.map +1 -1
- package/dist/agents/middleware/contextEditing.d.ts.map +1 -1
- package/dist/agents/middleware/dynamicSystemPrompt.d.cts.map +1 -1
- package/dist/agents/middleware/dynamicSystemPrompt.d.ts.map +1 -1
- package/dist/agents/middleware/hitl.cjs +7 -2
- package/dist/agents/middleware/hitl.cjs.map +1 -1
- package/dist/agents/middleware/hitl.d.cts.map +1 -1
- package/dist/agents/middleware/hitl.d.ts.map +1 -1
- package/dist/agents/middleware/hitl.js +7 -2
- package/dist/agents/middleware/hitl.js.map +1 -1
- package/dist/agents/middleware/index.cjs +2 -1
- package/dist/agents/middleware/index.d.cts +15 -0
- package/dist/agents/middleware/index.d.ts +14 -0
- package/dist/agents/middleware/index.js +2 -1
- package/dist/agents/middleware/modelCallLimit.cjs +145 -0
- package/dist/agents/middleware/modelCallLimit.cjs.map +1 -0
- package/dist/agents/middleware/modelCallLimit.d.cts +128 -0
- package/dist/agents/middleware/modelCallLimit.d.cts.map +1 -0
- package/dist/agents/middleware/modelCallLimit.d.ts +128 -0
- package/dist/agents/middleware/modelCallLimit.d.ts.map +1 -0
- package/dist/agents/middleware/modelCallLimit.js +144 -0
- package/dist/agents/middleware/modelCallLimit.js.map +1 -0
- package/dist/agents/middleware/promptCaching.d.cts.map +1 -1
- package/dist/agents/middleware/promptCaching.d.ts.map +1 -1
- package/dist/agents/middleware/summarization.cjs +4 -2
- package/dist/agents/middleware/summarization.cjs.map +1 -1
- package/dist/agents/middleware/summarization.d.cts +7 -6
- package/dist/agents/middleware/summarization.d.cts.map +1 -1
- package/dist/agents/middleware/summarization.d.ts +7 -6
- package/dist/agents/middleware/summarization.d.ts.map +1 -1
- package/dist/agents/middleware/summarization.js +4 -2
- package/dist/agents/middleware/summarization.js.map +1 -1
- package/dist/agents/middleware/todoListMiddleware.d.ts.map +1 -1
- package/dist/agents/middleware/toolCallLimit.cjs +205 -92
- package/dist/agents/middleware/toolCallLimit.cjs.map +1 -1
- package/dist/agents/middleware/toolCallLimit.d.cts +46 -37
- package/dist/agents/middleware/toolCallLimit.d.cts.map +1 -1
- package/dist/agents/middleware/toolCallLimit.d.ts +46 -37
- package/dist/agents/middleware/toolCallLimit.d.ts.map +1 -1
- package/dist/agents/middleware/toolCallLimit.js +206 -93
- package/dist/agents/middleware/toolCallLimit.js.map +1 -1
- package/dist/agents/middleware/toolRetry.cjs +224 -0
- package/dist/agents/middleware/toolRetry.cjs.map +1 -0
- package/dist/agents/middleware/toolRetry.d.cts +179 -0
- package/dist/agents/middleware/toolRetry.d.cts.map +1 -0
- package/dist/agents/middleware/toolRetry.d.ts +179 -0
- package/dist/agents/middleware/toolRetry.d.ts.map +1 -0
- package/dist/agents/middleware/toolRetry.js +223 -0
- package/dist/agents/middleware/toolRetry.js.map +1 -0
- package/dist/agents/middleware/types.d.cts +21 -19
- package/dist/agents/middleware/types.d.cts.map +1 -1
- package/dist/agents/middleware/types.d.ts +21 -19
- package/dist/agents/middleware/types.d.ts.map +1 -1
- package/dist/agents/middleware/utils.cjs +7 -0
- package/dist/agents/middleware/utils.cjs.map +1 -1
- package/dist/agents/middleware/utils.d.cts.map +1 -1
- package/dist/agents/middleware/utils.d.ts.map +1 -1
- package/dist/agents/middleware/utils.js +7 -1
- package/dist/agents/middleware/utils.js.map +1 -1
- package/dist/agents/middleware.cjs.map +1 -1
- package/dist/agents/middleware.d.cts +4 -4
- package/dist/agents/middleware.d.cts.map +1 -1
- package/dist/agents/middleware.d.ts +4 -4
- package/dist/agents/middleware.d.ts.map +1 -1
- package/dist/agents/middleware.js.map +1 -1
- package/dist/agents/nodes/AgentNode.cjs +21 -47
- package/dist/agents/nodes/AgentNode.cjs.map +1 -1
- package/dist/agents/nodes/AgentNode.js +22 -48
- package/dist/agents/nodes/AgentNode.js.map +1 -1
- package/dist/agents/nodes/ToolNode.cjs +12 -18
- package/dist/agents/nodes/ToolNode.cjs.map +1 -1
- package/dist/agents/nodes/ToolNode.js +12 -18
- package/dist/agents/nodes/ToolNode.js.map +1 -1
- package/dist/agents/nodes/middleware.cjs +9 -7
- package/dist/agents/nodes/middleware.cjs.map +1 -1
- package/dist/agents/nodes/middleware.js +10 -8
- package/dist/agents/nodes/middleware.js.map +1 -1
- package/dist/agents/nodes/types.d.cts +1 -1
- package/dist/agents/nodes/types.d.cts.map +1 -1
- package/dist/agents/nodes/types.d.ts +1 -1
- package/dist/agents/nodes/types.d.ts.map +1 -1
- package/dist/agents/nodes/utils.cjs +5 -1
- package/dist/agents/nodes/utils.cjs.map +1 -1
- package/dist/agents/nodes/utils.js +5 -1
- package/dist/agents/nodes/utils.js.map +1 -1
- package/dist/agents/runtime.d.cts +11 -27
- package/dist/agents/runtime.d.cts.map +1 -1
- package/dist/agents/runtime.d.ts +11 -27
- package/dist/agents/runtime.d.ts.map +1 -1
- package/dist/agents/state.cjs +45 -0
- package/dist/agents/state.cjs.map +1 -0
- package/dist/agents/state.js +44 -0
- package/dist/agents/state.js.map +1 -0
- package/dist/agents/types.d.cts +1 -1
- package/dist/agents/types.d.cts.map +1 -1
- package/dist/agents/types.d.ts +1 -1
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/utils.cjs +10 -2
- package/dist/agents/utils.cjs.map +1 -1
- package/dist/agents/utils.js +10 -2
- package/dist/agents/utils.js.map +1 -1
- package/dist/chat_models/universal.cjs +2 -2
- package/dist/chat_models/universal.cjs.map +1 -1
- package/dist/chat_models/universal.js +2 -2
- package/dist/chat_models/universal.js.map +1 -1
- package/dist/embeddings/cache_backed.cjs +140 -0
- package/dist/embeddings/cache_backed.cjs.map +1 -0
- package/dist/embeddings/cache_backed.d.cts +107 -0
- package/dist/embeddings/cache_backed.d.cts.map +1 -0
- package/dist/embeddings/cache_backed.d.ts +107 -0
- package/dist/embeddings/cache_backed.d.ts.map +1 -0
- package/dist/embeddings/cache_backed.js +134 -0
- package/dist/embeddings/cache_backed.js.map +1 -0
- package/dist/embeddings/fake.cjs +22 -0
- package/dist/embeddings/fake.cjs.map +1 -0
- package/dist/embeddings/fake.d.cts +1 -0
- package/dist/embeddings/fake.d.ts +1 -0
- package/dist/embeddings/fake.js +12 -0
- package/dist/embeddings/fake.js.map +1 -0
- package/dist/index.cjs +6 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.cjs +248 -0
- package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js +244 -0
- package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.cjs +3096 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.js +3095 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.cjs +12 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.js +12 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.cjs +71 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.js +38 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.cjs +221 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.js +221 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.cjs +11 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.js +11 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.cjs +703 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.js +702 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.cjs +7 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.js +6 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.cjs +29 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.js +28 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.cjs +115 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.js +113 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.cjs +14 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.js +13 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.cjs +95 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.js +95 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.cjs +136 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.js +131 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.cjs +102 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.js +99 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.cjs +140 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js +140 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.cjs +18 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.js +16 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.cjs +10 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.js +10 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.cjs +30 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.js +30 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.cjs +13 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.cjs.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.js +12 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.js.map +1 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/index.cjs +6 -0
- package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/index.js +6 -0
- package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.cjs +27 -0
- package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.js +23 -0
- package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.js.map +1 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.cjs +267 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js +263 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.cjs +32 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.js +28 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.js.map +1 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.cjs +49 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.js +45 -0
- package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.js.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.cjs +83 -0
- package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js +79 -0
- package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js.map +1 -0
- package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.cjs +52 -0
- package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.js +48 -0
- package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.js.map +1 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.cjs +16 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js +13 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js.map +1 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.cjs +77 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.cjs.map +1 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js +74 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js.map +1 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.cjs +115 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.cjs.map +1 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js +112 -0
- package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.cjs +90 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.js +86 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.cjs +294 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.js +290 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.cjs +191 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.js +187 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.cjs +24 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.js +20 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.cjs +51 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.js +47 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.cjs +48 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.js +44 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.cjs +25 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.js +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.cjs +43 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.js +39 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.cjs +32 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.js +28 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.cjs +29 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.js +25 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.cjs +24 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.js +20 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.cjs +28 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.js +24 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.cjs +24 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.js +20 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.cjs +146 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.js +142 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.cjs +41 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.js +37 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.cjs +19 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.js +15 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.cjs +32 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.js +28 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.cjs +47 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.js +43 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.cjs +25 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.js +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.cjs +94 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.js +90 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.cjs +25 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.js +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.cjs +41 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.js +37 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.cjs +41 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.js +37 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.cjs +55 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.js +51 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.cjs +74 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.js +70 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.cjs +48 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.js +44 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.cjs +112 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.js +108 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.cjs +21 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.js +17 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.js.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.cjs +27 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.cjs.map +1 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.js +23 -0
- package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.js.map +1 -0
- package/package.json +6 -6
|
@@ -1,62 +1,53 @@
|
|
|
1
1
|
import { createMiddleware } from "../middleware.js";
|
|
2
|
-
import { AIMessage,
|
|
2
|
+
import { AIMessage, ToolMessage } from "@langchain/core/messages";
|
|
3
3
|
import { z } from "zod/v3";
|
|
4
4
|
|
|
5
5
|
//#region src/agents/middleware/toolCallLimit.ts
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Build the error message content for ToolMessage when limit is exceeded.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* If undefined, count all tool calls.
|
|
12
|
-
* @returns The total number of tool calls (optionally filtered by toolName).
|
|
13
|
-
*/
|
|
14
|
-
function countToolCallsInMessages(messages, toolName) {
|
|
15
|
-
let count = 0;
|
|
16
|
-
for (const message of messages) if (AIMessage.isInstance(message) && message.tool_calls) if (toolName === void 0) count += message.tool_calls.length;
|
|
17
|
-
else count += message.tool_calls.filter((tc) => tc.name === toolName).length;
|
|
18
|
-
return count;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get messages from the current run (after the last HumanMessage).
|
|
9
|
+
* This message is sent to the model, so it should not reference thread/run concepts
|
|
10
|
+
* that the model has no notion of.
|
|
22
11
|
*
|
|
23
|
-
* @param
|
|
24
|
-
* @
|
|
12
|
+
* @param toolName - Tool name being limited (if specific tool), or undefined for all tools.
|
|
13
|
+
* @param threadCount - Current thread tool call count.
|
|
14
|
+
* @param runCount - Current run tool call count.
|
|
15
|
+
* @param threadLimit - Thread tool call limit (if set).
|
|
16
|
+
* @param runLimit - Run tool call limit (if set).
|
|
17
|
+
* @returns A concise message. If only run limit is exceeded (not thread limit),
|
|
18
|
+
* returns a simple "limit exceeded" message without instructing model to stop.
|
|
19
|
+
* If thread limit is exceeded, includes instruction not to call again.
|
|
25
20
|
*/
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
lastHumanIndex = i;
|
|
33
|
-
break;
|
|
21
|
+
function buildToolMessageContent(toolName, threadCount, runCount, threadLimit, runLimit) {
|
|
22
|
+
const threadExceeded = threadLimit !== void 0 && threadCount > threadLimit;
|
|
23
|
+
const onlyRunExceeded = runLimit !== void 0 && runCount > runLimit && !threadExceeded;
|
|
24
|
+
if (onlyRunExceeded) {
|
|
25
|
+
if (toolName) return `Tool call limit exceeded for '${toolName}'.`;
|
|
26
|
+
return "Tool call limit exceeded.";
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
if (lastHumanIndex === -1) return messages;
|
|
39
|
-
/**
|
|
40
|
-
* Return messages after the last HumanMessage
|
|
41
|
-
*/
|
|
42
|
-
return messages.slice(lastHumanIndex + 1);
|
|
28
|
+
if (toolName) return `Tool call limit exceeded. Do not call '${toolName}' again.`;
|
|
29
|
+
return "Tool call limit exceeded. Do not make additional tool calls.";
|
|
43
30
|
}
|
|
44
31
|
/**
|
|
45
|
-
* Build
|
|
32
|
+
* Build the final AI message content for 'end' behavior.
|
|
33
|
+
*
|
|
34
|
+
* This message is displayed to the user, so it should include detailed information
|
|
35
|
+
* about which limits were exceeded.
|
|
46
36
|
*
|
|
47
37
|
* @param threadCount - Current thread tool call count.
|
|
48
38
|
* @param runCount - Current run tool call count.
|
|
49
39
|
* @param threadLimit - Thread tool call limit (if set).
|
|
50
40
|
* @param runLimit - Run tool call limit (if set).
|
|
51
41
|
* @param toolName - Tool name being limited (if specific tool), or undefined for all tools.
|
|
52
|
-
* @returns A formatted message describing which limits were
|
|
42
|
+
* @returns A formatted message describing which limits were exceeded.
|
|
53
43
|
*/
|
|
54
|
-
function
|
|
55
|
-
const toolDesc = toolName ? `'${toolName}' tool
|
|
44
|
+
function buildFinalAIMessageContent(threadCount, runCount, threadLimit, runLimit, toolName) {
|
|
45
|
+
const toolDesc = toolName ? `'${toolName}' tool` : "Tool";
|
|
56
46
|
const exceededLimits = [];
|
|
57
|
-
if (threadLimit !== void 0 && threadCount
|
|
58
|
-
if (runLimit !== void 0 && runCount
|
|
59
|
-
|
|
47
|
+
if (threadLimit !== void 0 && threadCount > threadLimit) exceededLimits.push(`thread limit exceeded (${threadCount}/${threadLimit} calls)`);
|
|
48
|
+
if (runLimit !== void 0 && runCount > runLimit) exceededLimits.push(`run limit exceeded (${runCount}/${runLimit} calls)`);
|
|
49
|
+
const limitsText = exceededLimits.join(" and ");
|
|
50
|
+
return `${toolDesc} call limit reached: ${limitsText}.`;
|
|
60
51
|
}
|
|
61
52
|
/**
|
|
62
53
|
* Exception raised when tool call limits are exceeded.
|
|
@@ -86,7 +77,7 @@ var ToolCallLimitExceededError = class extends Error {
|
|
|
86
77
|
*/
|
|
87
78
|
toolName;
|
|
88
79
|
constructor(threadCount, runCount, threadLimit, runLimit, toolName = void 0) {
|
|
89
|
-
const message =
|
|
80
|
+
const message = buildFinalAIMessageContent(threadCount, runCount, threadLimit, runLimit, toolName);
|
|
90
81
|
super(message);
|
|
91
82
|
this.name = "ToolCallLimitExceededError";
|
|
92
83
|
this.threadCount = threadCount;
|
|
@@ -103,8 +94,20 @@ const ToolCallLimitOptionsSchema = z.object({
|
|
|
103
94
|
toolName: z.string().optional(),
|
|
104
95
|
threadLimit: z.number().optional(),
|
|
105
96
|
runLimit: z.number().optional(),
|
|
106
|
-
exitBehavior: z.enum([
|
|
97
|
+
exitBehavior: z.enum([
|
|
98
|
+
"continue",
|
|
99
|
+
"error",
|
|
100
|
+
"end"
|
|
101
|
+
]).default("continue")
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Middleware state schema to track the number of model calls made at the thread and run level.
|
|
105
|
+
*/
|
|
106
|
+
const stateSchema = z.object({
|
|
107
|
+
threadToolCallCount: z.record(z.string(), z.number()).default({}),
|
|
108
|
+
runToolCallCount: z.record(z.string(), z.number()).default({})
|
|
107
109
|
});
|
|
110
|
+
const DEFAULT_TOOL_COUNT_KEY = "__all__";
|
|
108
111
|
/**
|
|
109
112
|
* Middleware that tracks tool call counts and enforces limits.
|
|
110
113
|
*
|
|
@@ -123,68 +126,66 @@ const ToolCallLimitOptionsSchema = z.object({
|
|
|
123
126
|
* @param options.threadLimit - Maximum number of tool calls allowed per thread. undefined means no limit.
|
|
124
127
|
* @param options.runLimit - Maximum number of tool calls allowed per run. undefined means no limit.
|
|
125
128
|
* @param options.exitBehavior - What to do when limits are exceeded.
|
|
126
|
-
* - "
|
|
127
|
-
* - "error":
|
|
129
|
+
* - "continue": Block exceeded tools with error messages, let other tools continue. Model decides when to end. (default)
|
|
130
|
+
* - "error": Raise a ToolCallLimitExceededError exception
|
|
131
|
+
* - "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.
|
|
128
132
|
*
|
|
129
|
-
* @throws {Error} If both limits are undefined
|
|
133
|
+
* @throws {Error} If both limits are undefined.
|
|
134
|
+
* @throws {NotImplementedError} If exitBehavior is "end" and there are multiple tool calls.
|
|
130
135
|
*
|
|
131
|
-
* @example
|
|
136
|
+
* @example Continue execution with blocked tools (default)
|
|
132
137
|
* ```ts
|
|
133
138
|
* import { toolCallLimitMiddleware } from "@langchain/langchain/agents/middleware";
|
|
134
139
|
* import { createAgent } from "@langchain/langchain/agents";
|
|
135
140
|
*
|
|
136
|
-
*
|
|
141
|
+
* // Block exceeded tools but let other tools and model continue
|
|
142
|
+
* const limiter = toolCallLimitMiddleware({
|
|
137
143
|
* threadLimit: 20,
|
|
138
144
|
* runLimit: 10,
|
|
139
|
-
* exitBehavior: "
|
|
145
|
+
* exitBehavior: "continue", // default
|
|
140
146
|
* });
|
|
141
147
|
*
|
|
142
148
|
* const agent = createAgent({
|
|
143
149
|
* model: "openai:gpt-4o",
|
|
144
|
-
* middleware: [
|
|
150
|
+
* middleware: [limiter]
|
|
145
151
|
* });
|
|
146
152
|
* ```
|
|
147
153
|
*
|
|
148
|
-
* @example
|
|
154
|
+
* @example Stop immediately when limit exceeded
|
|
149
155
|
* ```ts
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* const searchLimiter = toolCallLimitMiddleware({
|
|
154
|
-
* toolName: "search",
|
|
155
|
-
* threadLimit: 5,
|
|
156
|
-
* runLimit: 3,
|
|
156
|
+
* // End execution immediately with an AI message
|
|
157
|
+
* const limiter = toolCallLimitMiddleware({
|
|
158
|
+
* runLimit: 5,
|
|
157
159
|
* exitBehavior: "end"
|
|
158
160
|
* });
|
|
159
161
|
*
|
|
160
162
|
* const agent = createAgent({
|
|
161
163
|
* model: "openai:gpt-4o",
|
|
162
|
-
* middleware: [
|
|
164
|
+
* middleware: [limiter]
|
|
163
165
|
* });
|
|
164
166
|
* ```
|
|
165
167
|
*
|
|
166
|
-
* @example
|
|
168
|
+
* @example Raise exception on limit
|
|
167
169
|
* ```ts
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* const globalLimiter = toolCallLimitMiddleware({
|
|
172
|
-
* threadLimit: 20,
|
|
173
|
-
* runLimit: 10,
|
|
174
|
-
* exitBehavior: "end"
|
|
175
|
-
* });
|
|
176
|
-
*
|
|
177
|
-
* const searchLimiter = toolCallLimitMiddleware({
|
|
170
|
+
* // Strict limit with exception handling
|
|
171
|
+
* const limiter = toolCallLimitMiddleware({
|
|
178
172
|
* toolName: "search",
|
|
179
173
|
* threadLimit: 5,
|
|
180
|
-
*
|
|
181
|
-
* exitBehavior: "end"
|
|
174
|
+
* exitBehavior: "error"
|
|
182
175
|
* });
|
|
183
176
|
*
|
|
184
177
|
* const agent = createAgent({
|
|
185
178
|
* model: "openai:gpt-4o",
|
|
186
|
-
* middleware: [
|
|
179
|
+
* middleware: [limiter]
|
|
187
180
|
* });
|
|
181
|
+
*
|
|
182
|
+
* try {
|
|
183
|
+
* const result = await agent.invoke({ messages: [new HumanMessage("Task")] });
|
|
184
|
+
* } catch (error) {
|
|
185
|
+
* if (error instanceof ToolCallLimitExceededError) {
|
|
186
|
+
* console.log(`Search limit exceeded: ${error}`);
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
188
189
|
* ```
|
|
189
190
|
*/
|
|
190
191
|
function toolCallLimitMiddleware(options) {
|
|
@@ -193,47 +194,159 @@ function toolCallLimitMiddleware(options) {
|
|
|
193
194
|
*/
|
|
194
195
|
if (options.threadLimit === void 0 && options.runLimit === void 0) throw new Error("At least one limit must be specified (threadLimit or runLimit)");
|
|
195
196
|
/**
|
|
196
|
-
* Apply default for exitBehavior
|
|
197
|
+
* Apply default for exitBehavior
|
|
197
198
|
*/
|
|
198
|
-
const exitBehavior = options.exitBehavior ?? "
|
|
199
|
-
if (exitBehavior !== "end" && exitBehavior !== "error") throw new Error(`Invalid exit behavior: ${exitBehavior}. Must be 'end' or 'error'`);
|
|
199
|
+
const exitBehavior = options.exitBehavior ?? "continue";
|
|
200
200
|
/**
|
|
201
201
|
* Generate the middleware name based on the tool name
|
|
202
202
|
*/
|
|
203
203
|
const middlewareName = options.toolName ? `ToolCallLimitMiddleware[${options.toolName}]` : "ToolCallLimitMiddleware";
|
|
204
204
|
return createMiddleware({
|
|
205
205
|
name: middlewareName,
|
|
206
|
-
|
|
206
|
+
stateSchema,
|
|
207
|
+
afterModel: {
|
|
207
208
|
canJumpTo: ["end"],
|
|
208
209
|
hook: (state) => {
|
|
209
|
-
const messages = state.messages;
|
|
210
210
|
/**
|
|
211
|
-
*
|
|
211
|
+
* Get the last AI message to check for tool calls
|
|
212
|
+
*/
|
|
213
|
+
const lastAIMessage = [...state.messages].reverse().find(AIMessage.isInstance);
|
|
214
|
+
if (!lastAIMessage || !lastAIMessage.tool_calls) return void 0;
|
|
215
|
+
/**
|
|
216
|
+
* Helper to check if limit would be exceeded by one more call
|
|
217
|
+
*/
|
|
218
|
+
const wouldExceedLimit = (threadCount, runCount) => {
|
|
219
|
+
return options.threadLimit !== void 0 && threadCount + 1 > options.threadLimit || options.runLimit !== void 0 && runCount + 1 > options.runLimit;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Helper to check if a tool call matches our filter
|
|
223
|
+
*/
|
|
224
|
+
const matchesToolFilter = (toolCall) => {
|
|
225
|
+
return options.toolName === void 0 || toolCall.name === options.toolName;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Separate tool calls into allowed and blocked based on limits
|
|
229
|
+
*/
|
|
230
|
+
const separateToolCalls = (toolCalls, threadCount, runCount) => {
|
|
231
|
+
const allowed$1 = [];
|
|
232
|
+
const blocked$1 = [];
|
|
233
|
+
let tempThreadCount = threadCount;
|
|
234
|
+
let tempRunCount = runCount;
|
|
235
|
+
for (const toolCall of toolCalls) {
|
|
236
|
+
if (!matchesToolFilter(toolCall)) continue;
|
|
237
|
+
if (wouldExceedLimit(tempThreadCount, tempRunCount)) blocked$1.push(toolCall);
|
|
238
|
+
else {
|
|
239
|
+
allowed$1.push(toolCall);
|
|
240
|
+
tempThreadCount += 1;
|
|
241
|
+
tempRunCount += 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
allowed: allowed$1,
|
|
246
|
+
blocked: blocked$1,
|
|
247
|
+
finalThreadCount: tempThreadCount + blocked$1.length,
|
|
248
|
+
finalRunCount: tempRunCount + blocked$1.length
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Get the count key for this middleware instance
|
|
253
|
+
*/
|
|
254
|
+
const countKey = options.toolName ?? DEFAULT_TOOL_COUNT_KEY;
|
|
255
|
+
/**
|
|
256
|
+
* Get current counts
|
|
257
|
+
*/
|
|
258
|
+
const threadCounts = { ...state.threadToolCallCount ?? {} };
|
|
259
|
+
const runCounts = { ...state.runToolCallCount ?? {} };
|
|
260
|
+
const currentThreadCount = threadCounts[countKey] ?? 0;
|
|
261
|
+
const currentRunCount = runCounts[countKey] ?? 0;
|
|
262
|
+
/**
|
|
263
|
+
* Separate tool calls into allowed and blocked
|
|
264
|
+
*/
|
|
265
|
+
const { allowed, blocked, finalThreadCount, finalRunCount } = separateToolCalls(lastAIMessage.tool_calls, currentThreadCount, currentRunCount);
|
|
266
|
+
/**
|
|
267
|
+
* Update counts to include ALL tool call attempts (both allowed and blocked)
|
|
268
|
+
*/
|
|
269
|
+
threadCounts[countKey] = finalThreadCount;
|
|
270
|
+
runCounts[countKey] = finalRunCount;
|
|
271
|
+
/**
|
|
272
|
+
* If no tool calls are blocked, just update counts
|
|
273
|
+
*/
|
|
274
|
+
if (blocked.length === 0) {
|
|
275
|
+
if (allowed.length > 0) return {
|
|
276
|
+
threadToolCallCount: threadCounts,
|
|
277
|
+
runToolCallCount: runCounts
|
|
278
|
+
};
|
|
279
|
+
return void 0;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Handle different exit behaviors
|
|
212
283
|
*/
|
|
213
|
-
|
|
284
|
+
if (exitBehavior === "error") throw new ToolCallLimitExceededError(finalThreadCount, finalRunCount, options.threadLimit, options.runLimit, options.toolName);
|
|
214
285
|
/**
|
|
215
|
-
*
|
|
286
|
+
* Build tool message content (sent to model - no thread/run details)
|
|
216
287
|
*/
|
|
217
|
-
const
|
|
218
|
-
const runCount = countToolCallsInMessages(runMessages, options.toolName);
|
|
288
|
+
const toolMsgContent = buildToolMessageContent(options.toolName, finalThreadCount, finalRunCount, options.threadLimit, options.runLimit);
|
|
219
289
|
/**
|
|
220
|
-
*
|
|
290
|
+
* Inject artificial error ToolMessages for blocked tool calls
|
|
221
291
|
*/
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
292
|
+
const artificialMessages = blocked.map((toolCall) => new ToolMessage({
|
|
293
|
+
content: toolMsgContent,
|
|
294
|
+
tool_call_id: toolCall.id,
|
|
295
|
+
name: toolCall.name,
|
|
296
|
+
status: "error"
|
|
297
|
+
}));
|
|
298
|
+
if (exitBehavior === "end") {
|
|
299
|
+
/**
|
|
300
|
+
* Check if there are tool calls to other tools that would continue executing
|
|
301
|
+
* For tool-specific limiters: check for calls to other tools
|
|
302
|
+
* For global limiters: check if there are multiple different tool types
|
|
303
|
+
*/
|
|
304
|
+
let otherTools = [];
|
|
305
|
+
if (options.toolName !== void 0)
|
|
306
|
+
/**
|
|
307
|
+
* Tool-specific limiter: check for calls to other tools
|
|
308
|
+
*/
|
|
309
|
+
otherTools = lastAIMessage.tool_calls.filter((tc) => tc.name !== options.toolName);
|
|
310
|
+
else {
|
|
311
|
+
/**
|
|
312
|
+
* Global limiter: check if there are multiple different tool types
|
|
313
|
+
* If there are allowed calls, those would execute
|
|
314
|
+
* But even if all are blocked, we can't handle multiple tool types with "end"
|
|
315
|
+
*/
|
|
316
|
+
const uniqueToolNames = new Set(lastAIMessage.tool_calls.map((tc) => tc.name).filter(Boolean));
|
|
317
|
+
if (uniqueToolNames.size > 1)
|
|
318
|
+
/**
|
|
319
|
+
* Multiple different tool types - use allowed calls to show which ones
|
|
320
|
+
*/
|
|
321
|
+
otherTools = allowed.length > 0 ? allowed : lastAIMessage.tool_calls;
|
|
322
|
+
}
|
|
323
|
+
if (otherTools.length > 0) {
|
|
324
|
+
const toolNames = Array.from(new Set(otherTools.map((tc) => tc.name).filter(Boolean))).join(", ");
|
|
325
|
+
throw new Error(`Cannot end execution with other tool calls pending. Found calls to: ${toolNames}. Use 'continue' or 'error' behavior instead.`);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Build final AI message content (displayed to user - includes thread/run details)
|
|
329
|
+
*/
|
|
330
|
+
const finalMsgContent = buildFinalAIMessageContent(finalThreadCount, finalRunCount, options.threadLimit, options.runLimit, options.toolName);
|
|
331
|
+
artificialMessages.push(new AIMessage(finalMsgContent));
|
|
332
|
+
return {
|
|
333
|
+
threadToolCallCount: threadCounts,
|
|
334
|
+
runToolCallCount: runCounts,
|
|
335
|
+
jumpTo: "end",
|
|
336
|
+
messages: artificialMessages
|
|
337
|
+
};
|
|
338
|
+
}
|
|
226
339
|
/**
|
|
227
|
-
*
|
|
340
|
+
* For exit_behavior="continue", return error messages to block exceeded tools
|
|
228
341
|
*/
|
|
229
|
-
const limitMessage = buildToolLimitExceededMessage(threadCount, runCount, options.threadLimit, options.runLimit, options.toolName);
|
|
230
|
-
const limitAiMessage = new AIMessage(limitMessage);
|
|
231
342
|
return {
|
|
232
|
-
|
|
233
|
-
|
|
343
|
+
threadToolCallCount: threadCounts,
|
|
344
|
+
runToolCallCount: runCounts,
|
|
345
|
+
messages: artificialMessages
|
|
234
346
|
};
|
|
235
347
|
}
|
|
236
|
-
}
|
|
348
|
+
},
|
|
349
|
+
afterAgent: () => ({ runToolCallCount: {} })
|
|
237
350
|
});
|
|
238
351
|
}
|
|
239
352
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolCallLimit.js","names":["messages: BaseMessage[]","toolName?: string","threadCount: number","runCount: number","threadLimit: number | undefined","runLimit: number | undefined","toolName: string | undefined","exceededLimits: string[]","options: ToolCallLimitConfig"],"sources":["../../../src/agents/middleware/toolCallLimit.ts"],"sourcesContent":["/**\n * Tool call limit middleware for agents.\n */\n\nimport { AIMessage, BaseMessage, HumanMessage } from \"@langchain/core/messages\";\nimport { z } from \"zod/v3\";\nimport type { InferInteropZodInput } from \"@langchain/core/utils/types\";\n\nimport { createMiddleware } from \"../middleware.js\";\n\n/**\n * Count tool calls in a list of messages.\n *\n * @param messages - List of messages to count tool calls in.\n * @param toolName - If specified, only count calls to this specific tool.\n * If undefined, count all tool calls.\n * @returns The total number of tool calls (optionally filtered by toolName).\n */\nfunction countToolCallsInMessages(\n messages: BaseMessage[],\n toolName?: string\n): number {\n let count = 0;\n for (const message of messages) {\n if (AIMessage.isInstance(message) && message.tool_calls) {\n if (toolName === undefined) {\n // Count all tool calls\n count += message.tool_calls.length;\n } else {\n // Count only calls to the specified tool\n count += message.tool_calls.filter((tc) => tc.name === toolName).length;\n }\n }\n }\n return count;\n}\n\n/**\n * Get messages from the current run (after the last HumanMessage).\n *\n * @param messages - Full list of messages.\n * @returns Messages from the current run (after last HumanMessage).\n */\nfunction getRunMessages(messages: BaseMessage[]): BaseMessage[] {\n /**\n * Find the last HumanMessage\n */\n let lastHumanIndex = -1;\n for (let i = messages.length - 1; i >= 0; i--) {\n if (HumanMessage.isInstance(messages[i])) {\n lastHumanIndex = i;\n break;\n }\n }\n\n /**\n * If no HumanMessage found, return all messages\n */\n if (lastHumanIndex === -1) {\n return messages;\n }\n\n /**\n * Return messages after the last HumanMessage\n */\n return messages.slice(lastHumanIndex + 1);\n}\n\n/**\n * Build a message indicating which tool call limits were reached.\n *\n * @param threadCount - Current thread tool call count.\n * @param runCount - Current run tool call count.\n * @param threadLimit - Thread tool call limit (if set).\n * @param runLimit - Run tool call limit (if set).\n * @param toolName - Tool name being limited (if specific tool), or undefined for all tools.\n * @returns A formatted message describing which limits were reached.\n */\nfunction buildToolLimitExceededMessage(\n threadCount: number,\n runCount: number,\n threadLimit: number | undefined,\n runLimit: number | undefined,\n toolName: string | undefined\n): string {\n const toolDesc = toolName ? `'${toolName}' tool call` : \"Tool call\";\n const exceededLimits: string[] = [];\n\n if (threadLimit !== undefined && threadCount >= threadLimit) {\n exceededLimits.push(`thread limit reached (${threadCount}/${threadLimit})`);\n }\n if (runLimit !== undefined && runCount >= runLimit) {\n exceededLimits.push(`run limit reached (${runCount}/${runLimit})`);\n }\n\n return `${toolDesc} limit${\n exceededLimits.length > 1 ? \"s\" : \"\"\n }: ${exceededLimits.join(\", \")}. Stopping to prevent further tool calls.`;\n}\n\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 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\n constructor(\n threadCount: number,\n runCount: number,\n threadLimit: number | undefined,\n runLimit: number | undefined,\n toolName: string | undefined = undefined\n ) {\n const message = buildToolLimitExceededMessage(\n threadCount,\n runCount,\n threadLimit,\n runLimit,\n toolName\n );\n super(message);\n\n this.name = \"ToolCallLimitExceededError\";\n this.threadCount = threadCount;\n this.runCount = runCount;\n this.threadLimit = threadLimit;\n this.runLimit = runLimit;\n this.toolName = toolName;\n }\n}\n\n/**\n * Options for configuring the Tool Call Limit middleware.\n */\nexport const ToolCallLimitOptionsSchema = z.object({\n /**\n * Name of the specific tool to limit. If undefined, limits apply to all tools.\n */\n toolName: z.string().optional(),\n /**\n * Maximum number of tool calls allowed per thread.\n * undefined means no limit.\n */\n threadLimit: z.number().optional(),\n /**\n * Maximum number of tool calls allowed per run.\n * undefined means no limit.\n */\n runLimit: z.number().optional(),\n /**\n * What to do when limits are exceeded.\n * - \"end\": Jump to the end of the agent execution and inject an artificial\n * AI message indicating that the limit was exceeded.\n * - \"error\": throws a ToolCallLimitExceededError\n */\n exitBehavior: z.enum([\"end\", \"error\"]).default(\"end\"),\n});\n\nexport type ToolCallLimitConfig = InferInteropZodInput<\n typeof ToolCallLimitOptionsSchema\n>;\n\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 * - \"end\": Jump to the end of the agent execution and inject an artificial AI message indicating that the limit was exceeded.\n * - \"error\": throws a ToolCallLimitExceededError\n *\n * @throws {Error} If both limits are undefined or if exitBehavior is invalid.\n *\n * @example Limit all tool calls globally\n * ```ts\n * import { toolCallLimitMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * const globalLimiter = toolCallLimitMiddleware({\n * threadLimit: 20,\n * runLimit: 10,\n * exitBehavior: \"end\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [globalLimiter]\n * });\n * ```\n *\n * @example Limit a specific tool\n * ```ts\n * import { toolCallLimitMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * const searchLimiter = toolCallLimitMiddleware({\n * toolName: \"search\",\n * threadLimit: 5,\n * runLimit: 3,\n * exitBehavior: \"end\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [searchLimiter]\n * });\n * ```\n *\n * @example Use both in the same agent\n * ```ts\n * import { toolCallLimitMiddleware } from \"@langchain/langchain/agents/middleware\";\n * import { createAgent } from \"@langchain/langchain/agents\";\n *\n * const globalLimiter = toolCallLimitMiddleware({\n * threadLimit: 20,\n * runLimit: 10,\n * exitBehavior: \"end\"\n * });\n *\n * const searchLimiter = toolCallLimitMiddleware({\n * toolName: \"search\",\n * threadLimit: 5,\n * runLimit: 3,\n * exitBehavior: \"end\"\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * middleware: [globalLimiter, searchLimiter]\n * });\n * ```\n */\nexport function toolCallLimitMiddleware(options: ToolCallLimitConfig) {\n /**\n * Validate that at least one limit is specified\n */\n if (options.threadLimit === undefined && options.runLimit === undefined) {\n throw new Error(\n \"At least one limit must be specified (threadLimit or runLimit)\"\n );\n }\n\n /**\n * Apply default for exitBehavior and validate\n */\n const exitBehavior = options.exitBehavior ?? \"end\";\n if (exitBehavior !== \"end\" && exitBehavior !== \"error\") {\n throw new Error(\n `Invalid exit behavior: ${exitBehavior}. Must be 'end' or 'error'`\n );\n }\n\n /**\n * Generate the middleware name based on the tool name\n */\n const middlewareName = options.toolName\n ? `ToolCallLimitMiddleware[${options.toolName}]`\n : \"ToolCallLimitMiddleware\";\n\n return createMiddleware({\n name: middlewareName,\n beforeModel: {\n canJumpTo: [\"end\"],\n hook: (state) => {\n const messages = state.messages;\n\n /**\n * Count tool calls in entire thread\n */\n const threadCount = countToolCallsInMessages(\n messages,\n options.toolName\n );\n\n /**\n * Count tool calls in current run (after last HumanMessage)\n */\n const runMessages = getRunMessages(messages);\n const runCount = countToolCallsInMessages(\n runMessages,\n options.toolName\n );\n\n /**\n * Check if any limits are exceeded\n */\n const threadLimitExceeded =\n options.threadLimit !== undefined &&\n threadCount >= options.threadLimit;\n const runLimitExceeded =\n options.runLimit !== undefined && runCount >= options.runLimit;\n\n if (!threadLimitExceeded && !runLimitExceeded) {\n return undefined;\n }\n\n if (exitBehavior === \"error\") {\n throw new ToolCallLimitExceededError(\n threadCount,\n runCount,\n options.threadLimit,\n options.runLimit,\n options.toolName\n );\n }\n\n /**\n * Create a message indicating the limit was exceeded\n */\n const limitMessage = buildToolLimitExceededMessage(\n threadCount,\n runCount,\n options.threadLimit,\n options.runLimit,\n options.toolName\n );\n const limitAiMessage = new AIMessage(limitMessage);\n\n return {\n jumpTo: \"end\",\n messages: [limitAiMessage],\n };\n },\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,yBACPA,UACAC,UACQ;CACR,IAAI,QAAQ;AACZ,MAAK,MAAM,WAAW,SACpB,KAAI,UAAU,WAAW,QAAQ,IAAI,QAAQ,WAC3C,KAAI,aAAa,QAEf,SAAS,QAAQ,WAAW;MAG5B,SAAS,QAAQ,WAAW,OAAO,CAAC,OAAO,GAAG,SAAS,SAAS,CAAC;AAIvE,QAAO;AACR;;;;;;;AAQD,SAAS,eAAeD,UAAwC;;;;CAI9D,IAAI,iBAAiB;AACrB,MAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,IACxC,KAAI,aAAa,WAAW,SAAS,GAAG,EAAE;EACxC,iBAAiB;AACjB;CACD;;;;AAMH,KAAI,mBAAmB,GACrB,QAAO;;;;AAMT,QAAO,SAAS,MAAM,iBAAiB,EAAE;AAC1C;;;;;;;;;;;AAYD,SAAS,8BACPE,aACAC,UACAC,aACAC,UACAC,UACQ;CACR,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,SAAS,WAAW,CAAC,GAAG;CACxD,MAAMC,iBAA2B,CAAE;AAEnC,KAAI,gBAAgB,UAAa,eAAe,aAC9C,eAAe,KAAK,CAAC,sBAAsB,EAAE,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;AAE7E,KAAI,aAAa,UAAa,YAAY,UACxC,eAAe,KAAK,CAAC,mBAAmB,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;AAGpE,QAAO,GAAG,SAAS,MAAM,EACvB,eAAe,SAAS,IAAI,MAAM,GACnC,EAAE,EAAE,eAAe,KAAK,KAAK,CAAC,yCAAyC,CAAC;AAC1E;;;;;;;AAQD,IAAa,6BAAb,cAAgD,MAAM;;;;CAIpD;;;;CAIA;;;;CAIA;;;;CAIA;;;;CAIA;CAEA,YACEL,aACAC,UACAC,aACAC,UACAC,WAA+B,QAC/B;EACA,MAAM,UAAU,8BACd,aACA,UACA,aACA,UACA,SACD;EACD,MAAM,QAAQ;EAEd,KAAK,OAAO;EACZ,KAAK,cAAc;EACnB,KAAK,WAAW;EAChB,KAAK,cAAc;EACnB,KAAK,WAAW;EAChB,KAAK,WAAW;CACjB;AACF;;;;AAKD,MAAa,6BAA6B,EAAE,OAAO;CAIjD,UAAU,EAAE,QAAQ,CAAC,UAAU;CAK/B,aAAa,EAAE,QAAQ,CAAC,UAAU;CAKlC,UAAU,EAAE,QAAQ,CAAC,UAAU;CAO/B,cAAc,EAAE,KAAK,CAAC,OAAO,OAAQ,EAAC,CAAC,QAAQ,MAAM;AACtD,EAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwFF,SAAgB,wBAAwBE,SAA8B;;;;AAIpE,KAAI,QAAQ,gBAAgB,UAAa,QAAQ,aAAa,OAC5D,OAAM,IAAI,MACR;;;;CAOJ,MAAM,eAAe,QAAQ,gBAAgB;AAC7C,KAAI,iBAAiB,SAAS,iBAAiB,QAC7C,OAAM,IAAI,MACR,CAAC,uBAAuB,EAAE,aAAa,0BAA0B,CAAC;;;;CAOtE,MAAM,iBAAiB,QAAQ,WAC3B,CAAC,wBAAwB,EAAE,QAAQ,SAAS,CAAC,CAAC,GAC9C;AAEJ,QAAO,iBAAiB;EACtB,MAAM;EACN,aAAa;GACX,WAAW,CAAC,KAAM;GAClB,MAAM,CAAC,UAAU;IACf,MAAM,WAAW,MAAM;;;;IAKvB,MAAM,cAAc,yBAClB,UACA,QAAQ,SACT;;;;IAKD,MAAM,cAAc,eAAe,SAAS;IAC5C,MAAM,WAAW,yBACf,aACA,QAAQ,SACT;;;;IAKD,MAAM,sBACJ,QAAQ,gBAAgB,UACxB,eAAe,QAAQ;IACzB,MAAM,mBACJ,QAAQ,aAAa,UAAa,YAAY,QAAQ;AAExD,QAAI,CAAC,uBAAuB,CAAC,iBAC3B,QAAO;AAGT,QAAI,iBAAiB,QACnB,OAAM,IAAI,2BACR,aACA,UACA,QAAQ,aACR,QAAQ,UACR,QAAQ;;;;IAOZ,MAAM,eAAe,8BACnB,aACA,UACA,QAAQ,aACR,QAAQ,UACR,QAAQ,SACT;IACD,MAAM,iBAAiB,IAAI,UAAU;AAErC,WAAO;KACL,QAAQ;KACR,UAAU,CAAC,cAAe;IAC3B;GACF;EACF;CACF,EAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"toolCallLimit.js","names":["toolName: string | undefined","threadCount: number","runCount: number","threadLimit: number | undefined","runLimit: number | undefined","exceededLimits: string[]","options: ToolCallLimitConfig","toolCall: { name?: string }","toolCalls: ToolCall[]","allowed: ToolCall[]","blocked: ToolCall[]","blocked","allowed","artificialMessages: Array<ToolMessage | AIMessage>","otherTools: ToolCall[]"],"sources":["../../../src/agents/middleware/toolCallLimit.ts"],"sourcesContent":["import { AIMessage, ToolMessage } from \"@langchain/core/messages\";\nimport { z } from \"zod/v3\";\nimport type { InferInteropZodInput } from \"@langchain/core/utils/types\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\n\nimport { createMiddleware } from \"../middleware.js\";\n\n/**\n * Build the error message content for ToolMessage when limit is exceeded.\n *\n * This message is sent to the model, so it should not reference thread/run concepts\n * that the model has no notion of.\n *\n * @param toolName - Tool name being limited (if specific tool), or undefined for all tools.\n * @param threadCount - Current thread tool call count.\n * @param runCount - Current run tool call count.\n * @param threadLimit - Thread tool call limit (if set).\n * @param runLimit - Run tool call limit (if set).\n * @returns A concise message. If only run limit is exceeded (not thread limit),\n * returns a simple \"limit exceeded\" message without instructing model to stop.\n * If thread limit is exceeded, includes instruction not to call again.\n */\nfunction buildToolMessageContent(\n toolName: string | undefined,\n threadCount: number,\n runCount: number,\n threadLimit: number | undefined,\n runLimit: number | undefined\n): string {\n // Check if thread limit is exceeded\n const threadExceeded = threadLimit !== undefined && threadCount > threadLimit;\n // Check if only run limit is exceeded (not thread limit)\n const onlyRunExceeded =\n runLimit !== undefined && runCount > runLimit && !threadExceeded;\n\n if (onlyRunExceeded) {\n // Run limit exceeded but thread limit not exceeded - simpler message\n if (toolName) {\n return `Tool call limit exceeded for '${toolName}'.`;\n }\n return \"Tool call limit exceeded.\";\n }\n\n // Thread limit exceeded (or both) - include instruction not to call again\n if (toolName) {\n return `Tool call limit exceeded. Do not call '${toolName}' again.`;\n }\n return \"Tool call limit exceeded. Do not make additional tool calls.\";\n}\n\n/**\n * Build the final AI message content for 'end' behavior.\n *\n * This message is displayed to the user, so it should include detailed information\n * about which limits were exceeded.\n *\n * @param threadCount - Current thread tool call count.\n * @param runCount - Current run tool call count.\n * @param threadLimit - Thread tool call limit (if set).\n * @param runLimit - Run tool call limit (if set).\n * @param toolName - Tool name being limited (if specific tool), or undefined for all tools.\n * @returns A formatted message describing which limits were exceeded.\n */\nfunction buildFinalAIMessageContent(\n threadCount: number,\n runCount: number,\n threadLimit: number | undefined,\n runLimit: number | undefined,\n toolName: string | undefined\n): string {\n const toolDesc = toolName ? `'${toolName}' tool` : \"Tool\";\n const exceededLimits: string[] = [];\n\n if (threadLimit !== undefined && threadCount > threadLimit) {\n exceededLimits.push(\n `thread limit exceeded (${threadCount}/${threadLimit} calls)`\n );\n }\n if (runLimit !== undefined && runCount > runLimit) {\n exceededLimits.push(`run limit exceeded (${runCount}/${runLimit} calls)`);\n }\n\n const limitsText = exceededLimits.join(\" and \");\n return `${toolDesc} call limit reached: ${limitsText}.`;\n}\n\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 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\n constructor(\n threadCount: number,\n runCount: number,\n threadLimit: number | undefined,\n runLimit: number | undefined,\n toolName: string | undefined = undefined\n ) {\n const message = buildFinalAIMessageContent(\n threadCount,\n runCount,\n threadLimit,\n runLimit,\n toolName\n );\n super(message);\n\n this.name = \"ToolCallLimitExceededError\";\n this.threadCount = threadCount;\n this.runCount = runCount;\n this.threadLimit = threadLimit;\n this.runLimit = runLimit;\n this.toolName = toolName;\n }\n}\n\n/**\n * Options for configuring the Tool Call Limit middleware.\n */\nexport const ToolCallLimitOptionsSchema = z.object({\n /**\n * Name of the specific tool to limit. If undefined, limits apply to all tools.\n */\n toolName: z.string().optional(),\n /**\n * Maximum number of tool calls allowed per thread.\n * undefined means no limit.\n */\n threadLimit: z.number().optional(),\n /**\n * Maximum number of tool calls allowed per run.\n * undefined means no limit.\n */\n runLimit: z.number().optional(),\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 exitBehavior: z.enum([\"continue\", \"error\", \"end\"]).default(\"continue\"),\n});\n\nexport type ToolCallLimitConfig = InferInteropZodInput<\n typeof ToolCallLimitOptionsSchema\n>;\n\n/**\n * Middleware state schema to track the number of model calls made at the thread and run level.\n */\nconst stateSchema = z.object({\n threadToolCallCount: z.record(z.string(), z.number()).default({}),\n runToolCallCount: z.record(z.string(), z.number()).default({}),\n});\n\nconst DEFAULT_TOOL_COUNT_KEY = \"__all__\";\n\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.\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 function toolCallLimitMiddleware(options: ToolCallLimitConfig) {\n /**\n * Validate that at least one limit is specified\n */\n if (options.threadLimit === undefined && options.runLimit === undefined) {\n throw new Error(\n \"At least one limit must be specified (threadLimit or runLimit)\"\n );\n }\n\n /**\n * Apply default for exitBehavior\n */\n const exitBehavior = options.exitBehavior ?? \"continue\";\n\n /**\n * Generate the middleware name based on the tool name\n */\n const middlewareName = options.toolName\n ? `ToolCallLimitMiddleware[${options.toolName}]`\n : \"ToolCallLimitMiddleware\";\n\n return createMiddleware({\n name: middlewareName,\n stateSchema,\n afterModel: {\n canJumpTo: [\"end\"],\n hook: (state) => {\n /**\n * Get the last AI message to check for tool calls\n */\n const lastAIMessage = [...state.messages]\n .reverse()\n .find(AIMessage.isInstance);\n\n if (!lastAIMessage || !lastAIMessage.tool_calls) {\n return undefined;\n }\n\n /**\n * Helper to check if limit would be exceeded by one more call\n */\n const wouldExceedLimit = (\n threadCount: number,\n runCount: number\n ): boolean => {\n return (\n (options.threadLimit !== undefined &&\n threadCount + 1 > options.threadLimit) ||\n (options.runLimit !== undefined && runCount + 1 > options.runLimit)\n );\n };\n\n /**\n * Helper to check if a tool call matches our filter\n */\n const matchesToolFilter = (toolCall: { name?: string }): boolean => {\n return (\n options.toolName === undefined || toolCall.name === options.toolName\n );\n };\n\n /**\n * Separate tool calls into allowed and blocked based on limits\n */\n const separateToolCalls = (\n toolCalls: ToolCall[],\n threadCount: number,\n runCount: number\n ): {\n allowed: ToolCall[];\n blocked: ToolCall[];\n finalThreadCount: number;\n finalRunCount: number;\n } => {\n const allowed: ToolCall[] = [];\n const blocked: ToolCall[] = [];\n let tempThreadCount = threadCount;\n let tempRunCount = runCount;\n\n for (const toolCall of toolCalls) {\n if (!matchesToolFilter(toolCall)) {\n // Tool call doesn't match our filter, skip it\n continue;\n }\n\n if (wouldExceedLimit(tempThreadCount, tempRunCount)) {\n blocked.push(toolCall);\n } else {\n allowed.push(toolCall);\n tempThreadCount += 1;\n tempRunCount += 1;\n }\n }\n\n return {\n allowed,\n blocked,\n finalThreadCount: tempThreadCount + blocked.length,\n finalRunCount: tempRunCount + blocked.length,\n };\n };\n\n /**\n * Get the count key for this middleware instance\n */\n const countKey = options.toolName ?? DEFAULT_TOOL_COUNT_KEY;\n\n /**\n * Get current counts\n */\n const threadCounts = { ...(state.threadToolCallCount ?? {}) };\n const runCounts = { ...(state.runToolCallCount ?? {}) };\n const currentThreadCount = threadCounts[countKey] ?? 0;\n const currentRunCount = runCounts[countKey] ?? 0;\n\n /**\n * Separate tool calls into allowed and blocked\n */\n const { allowed, blocked, finalThreadCount, finalRunCount } =\n separateToolCalls(\n lastAIMessage.tool_calls,\n currentThreadCount,\n currentRunCount\n );\n\n /**\n * Update counts to include ALL tool call attempts (both allowed and blocked)\n */\n threadCounts[countKey] = finalThreadCount;\n runCounts[countKey] = finalRunCount;\n\n /**\n * If no tool calls are blocked, just update counts\n */\n if (blocked.length === 0) {\n if (allowed.length > 0) {\n return {\n threadToolCallCount: threadCounts,\n runToolCallCount: runCounts,\n };\n }\n return undefined;\n }\n\n /**\n * Handle different exit behaviors\n */\n if (exitBehavior === \"error\") {\n throw new ToolCallLimitExceededError(\n finalThreadCount,\n finalRunCount,\n options.threadLimit,\n options.runLimit,\n options.toolName\n );\n }\n\n /**\n * Build tool message content (sent to model - no thread/run details)\n */\n const toolMsgContent = buildToolMessageContent(\n options.toolName,\n finalThreadCount,\n finalRunCount,\n options.threadLimit,\n options.runLimit\n );\n\n /**\n * Inject artificial error ToolMessages for blocked tool calls\n */\n const artificialMessages: Array<ToolMessage | AIMessage> = blocked.map(\n (toolCall) =>\n new ToolMessage({\n content: toolMsgContent,\n tool_call_id: toolCall.id!,\n name: toolCall.name,\n status: \"error\",\n })\n );\n\n if (exitBehavior === \"end\") {\n /**\n * Check if there are tool calls to other tools that would continue executing\n * For tool-specific limiters: check for calls to other tools\n * For global limiters: check if there are multiple different tool types\n */\n let otherTools: ToolCall[] = [];\n if (options.toolName !== undefined) {\n /**\n * Tool-specific limiter: check for calls to other tools\n */\n otherTools = lastAIMessage.tool_calls.filter(\n (tc) => tc.name !== options.toolName\n );\n } else {\n /**\n * Global limiter: check if there are multiple different tool types\n * If there are allowed calls, those would execute\n * But even if all are blocked, we can't handle multiple tool types with \"end\"\n */\n const uniqueToolNames = new Set(\n lastAIMessage.tool_calls.map((tc) => tc.name).filter(Boolean)\n );\n if (uniqueToolNames.size > 1) {\n /**\n * Multiple different tool types - use allowed calls to show which ones\n */\n otherTools =\n allowed.length > 0 ? allowed : lastAIMessage.tool_calls;\n }\n }\n\n if (otherTools.length > 0) {\n const toolNames = Array.from(\n new Set(otherTools.map((tc) => tc.name).filter(Boolean))\n ).join(\", \");\n throw new Error(\n `Cannot end execution with other tool calls pending. Found calls to: ${toolNames}. Use 'continue' or 'error' behavior instead.`\n );\n }\n\n /**\n * Build final AI message content (displayed to user - includes thread/run details)\n */\n const finalMsgContent = buildFinalAIMessageContent(\n finalThreadCount,\n finalRunCount,\n options.threadLimit,\n options.runLimit,\n options.toolName\n );\n artificialMessages.push(new AIMessage(finalMsgContent));\n\n return {\n threadToolCallCount: threadCounts,\n runToolCallCount: runCounts,\n jumpTo: \"end\" as const,\n messages: artificialMessages,\n };\n }\n\n /**\n * For exit_behavior=\"continue\", return error messages to block exceeded tools\n */\n return {\n threadToolCallCount: threadCounts,\n runToolCallCount: runCounts,\n messages: artificialMessages,\n };\n },\n },\n /**\n * reset the run tool call count after the agent execution completes\n */\n afterAgent: () => ({\n runToolCallCount: {},\n }),\n });\n}\n"],"mappings":"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"}
|