{"version":3,"file":"toolCallLimit.d.cts","names":["z","InferInteropZodInput","ToolCallLimitExceededError","Error","ToolCallLimitOptionsSchema","ZodString","ZodOptional","ZodNumber","ZodEnum","ZodDefault","ZodTypeAny","ZodObject","ToolCallLimitConfig","toolCallLimitMiddleware","__types_js3","AgentMiddleware"],"sources":["../../../src/agents/middleware/toolCallLimit.d.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport type { InferInteropZodInput } from \"@langchain/core/utils/types\";\n/**\n * Exception raised when tool call limits are exceeded.\n *\n * This exception is raised when the configured exit behavior is 'error'\n * and either the thread or run tool call limit has been exceeded.\n */\nexport declare class ToolCallLimitExceededError extends Error {\n    /**\n     * Current thread tool call count.\n     */\n    threadCount: number;\n    /**\n     * Current run tool call count.\n     */\n    runCount: number;\n    /**\n     * Thread tool call limit (if set).\n     */\n    threadLimit: number | undefined;\n    /**\n     * Run tool call limit (if set).\n     */\n    runLimit: number | undefined;\n    /**\n     * Tool name being limited (if specific tool), or undefined for all tools.\n     */\n    toolName: string | undefined;\n    constructor(threadCount: number, runCount: number, threadLimit: number | undefined, runLimit: number | undefined, toolName?: string | undefined);\n}\n/**\n * Options for configuring the Tool Call Limit middleware.\n */\nexport declare const ToolCallLimitOptionsSchema: z.ZodObject<{\n    /**\n     * Name of the specific tool to limit. If undefined, limits apply to all tools.\n     */\n    toolName: z.ZodOptional<z.ZodString>;\n    /**\n     * Maximum number of tool calls allowed per thread.\n     * undefined means no limit.\n     */\n    threadLimit: z.ZodOptional<z.ZodNumber>;\n    /**\n     * Maximum number of tool calls allowed per run.\n     * undefined means no limit.\n     */\n    runLimit: z.ZodOptional<z.ZodNumber>;\n    /**\n     * What to do when limits are exceeded.\n     * - \"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.ZodDefault<z.ZodEnum<[\"end\", \"error\"]>>;\n}, \"strip\", z.ZodTypeAny, {\n    toolName?: string | undefined;\n    threadLimit?: number | undefined;\n    runLimit?: number | undefined;\n    exitBehavior: \"end\" | \"error\";\n}, {\n    toolName?: string | undefined;\n    threadLimit?: number | undefined;\n    runLimit?: number | undefined;\n    exitBehavior?: \"end\" | \"error\" | undefined;\n}>;\nexport type ToolCallLimitConfig = InferInteropZodInput<typeof ToolCallLimitOptionsSchema>;\n/**\n * Middleware that tracks tool call counts and enforces limits.\n *\n * This middleware monitors the number of tool calls made during agent execution\n * and can terminate the agent when specified limits are reached. It supports\n * both thread-level and run-level call counting with configurable exit behaviors.\n *\n * Thread-level: The middleware counts all tool calls in the entire message history\n * and persists this count across multiple runs (invocations) of the agent.\n *\n * Run-level: The middleware counts tool calls made after the last HumanMessage,\n * representing the current run (invocation) of the agent.\n *\n * @param options - Configuration options for the middleware\n * @param options.toolName - Name of the specific tool to limit. If undefined, limits apply to all tools.\n * @param options.threadLimit - Maximum number of tool calls allowed per thread. undefined means no limit.\n * @param options.runLimit - Maximum number of tool calls allowed per run. undefined means no limit.\n * @param options.exitBehavior - What to do when limits are exceeded.\n *   - \"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 declare function toolCallLimitMiddleware(options: ToolCallLimitConfig): import(\"./types.js\").AgentMiddleware<undefined, undefined, any>;\n"],"mappings":";;;;;;;;;AAQA;AA0BA;;AAI4BA,cA9BPE,0BAAAA,SAAmCC,KAAK,CA8B/BE;EAAS;;;EAKT,WAKAE,EAAAA,MAAAA;EAAS;;;EAOT,QAChBG,EAAAA,MAAAA;EAAU;AAtBoC;AAiC5D;EAA+B,WAAA,EAAA,MAAA,GAAA,SAAA;EAAA;;AAAuB;EAmF9BG,QAAAA,EAAAA,MAAAA,GAAAA,SAAuB;EAAA;;;EAAoE,QAAA,EAAA,MAAA,GAAA,SAAA;;;;;;cApH9FT,4BAA4BJ,CAAAA,CAAEW;;;;YAIrCX,CAAAA,CAAEM,YAAYN,CAAAA,CAAEK;;;;;eAKbL,CAAAA,CAAEM,YAAYN,CAAAA,CAAEO;;;;;YAKnBP,CAAAA,CAAEM,YAAYN,CAAAA,CAAEO;;;;;;;gBAOZP,CAAAA,CAAES,WAAWT,CAAAA,CAAEQ;YACrBR,CAAAA,CAAEU;;;;;;;;;;;KAWFE,mBAAAA,GAAsBX,4BAA4BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFtCS,uBAAAA,UAAiCD,sBAAmB"}