{"version":3,"file":"callLimit.d.cts","names":["z","InferInteropZodInput","contextSchema","ZodNumber","ZodOptional","ZodEnum","ZodTypeAny","ZodObject","ModelCallLimitMiddlewareConfig","Partial","modelCallLimitMiddleware","__types_js8","AgentMiddleware"],"sources":["../../../src/agents/middleware/callLimit.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { InferInteropZodInput } from \"@langchain/core/utils/types\";\ndeclare const contextSchema: z.ZodObject<{\n    /**\n     * The maximum number of model calls allowed per thread.\n     */\n    threadLimit: z.ZodOptional<z.ZodNumber>;\n    /**\n     * The maximum number of model calls allowed per run.\n     */\n    runLimit: z.ZodOptional<z.ZodNumber>;\n    /**\n     * The behavior to take when the limit is exceeded.\n     * - \"throw\" will throw an error and stop the agent.\n     * - \"end\" will end the agent.\n     * @default \"end\"\n     */\n    exitBehavior: z.ZodOptional<z.ZodEnum<[\"throw\", \"end\"]>>;\n}, \"strip\", z.ZodTypeAny, {\n    threadLimit?: number | undefined;\n    runLimit?: number | undefined;\n    exitBehavior?: \"end\" | \"throw\" | undefined;\n}, {\n    threadLimit?: number | undefined;\n    runLimit?: number | undefined;\n    exitBehavior?: \"end\" | \"throw\" | undefined;\n}>;\nexport type ModelCallLimitMiddlewareConfig = Partial<InferInteropZodInput<typeof contextSchema>>;\n/**\n * Creates a middleware to limit the number of model calls at both thread and run levels.\n *\n * This middleware helps prevent excessive model API calls by enforcing limits on how many\n * times the model can be invoked. It supports two types of limits:\n *\n * - **Thread-level limit**: Restricts the total number of model calls across an entire conversation thread\n * - **Run-level limit**: Restricts the number of model calls within a single agent run/invocation\n *\n * ## How It Works\n *\n * The middleware intercepts model requests before they are sent and checks the current call counts\n * against the configured limits. If either limit is exceeded, it throws a `ModelCallLimitMiddlewareError`\n * to stop execution and prevent further API calls.\n *\n * ## Use Cases\n *\n * - **Cost Control**: Prevent runaway costs from excessive model calls in production\n * - **Testing**: Ensure agents don't make too many calls during development/testing\n * - **Safety**: Limit potential infinite loops or recursive agent behaviors\n * - **Rate Limiting**: Enforce organizational policies on model usage per conversation\n *\n * @param middlewareOptions - Configuration options for the call limits\n * @param middlewareOptions.threadLimit - Maximum number of model calls allowed per thread (optional)\n * @param middlewareOptions.runLimit - Maximum number of model calls allowed per run (optional)\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @throws {ModelCallLimitMiddlewareError} When either the thread or run limit is exceeded\n *\n * @example\n * ```typescript\n * import { createAgent, modelCallLimitMiddleware } from \"langchain\";\n *\n * // Limit to 10 calls per thread and 3 calls per run\n * const agent = createAgent({\n *   model: \"openai:gpt-4o-mini\",\n *   tools: [myTool],\n *   middleware: [\n *     modelCallLimitMiddleware({\n *       threadLimit: 10,\n *       runLimit: 3\n *     })\n *   ]\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Limits can also be configured at runtime via context\n * const result = await agent.invoke(\n *   { messages: [\"Hello\"] },\n *   {\n *     configurable: {\n *       threadLimit: 5  // Override the default limit for this run\n *     }\n *   }\n * );\n * ```\n */\nexport declare function modelCallLimitMiddleware(middlewareOptions?: ModelCallLimitMiddlewareConfig): import(\"./types.js\").AgentMiddleware<undefined, z.ZodObject<{\n    /**\n     * The maximum number of model calls allowed per thread.\n     */\n    threadLimit: z.ZodOptional<z.ZodNumber>;\n    /**\n     * The maximum number of model calls allowed per run.\n     */\n    runLimit: z.ZodOptional<z.ZodNumber>;\n    /**\n     * The behavior to take when the limit is exceeded.\n     * - \"throw\" will throw an error and stop the agent.\n     * - \"end\" will end the agent.\n     * @default \"end\"\n     */\n    exitBehavior: z.ZodOptional<z.ZodEnum<[\"throw\", \"end\"]>>;\n}, \"strip\", z.ZodTypeAny, {\n    threadLimit?: number | undefined;\n    runLimit?: number | undefined;\n    exitBehavior?: \"end\" | \"throw\" | undefined;\n}, {\n    threadLimit?: number | undefined;\n    runLimit?: number | undefined;\n    exitBehavior?: \"end\" | \"throw\" | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;;cAEcE,eAAeF,CAAAA,CAAEO;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