UNPKG

langchain

Version:
41 lines (40 loc) • 1.62 kB
import { getRetryable } from "@langchain/core/errors"; import { z } from "zod/v3"; // src/agents/middleware/constants.ts /** LangGraph's messages handlers skip runs tagged with this, keeping middleware-internal model calls out of the messages stream. */ const INTERNAL_CALL_TAG = "nostream"; const RetrySchema = z.object({ /** * Maximum number of retry attempts after the initial call. * Default is 2 retries (3 total attempts). Must be >= 0. */ maxRetries: z.number().min(0).default(2), /** * Either an array of error constructors to retry on, or a function * that takes an error and returns `true` if it should be retried. * Default is to retry unless the error is marked non-retryable. */ retryOn: z.union([z.function().args(z.instanceof(Error)).returns(z.boolean()), z.array(z.custom())]).default(() => (error) => getRetryable(error) ?? true), /** * Multiplier for exponential backoff. Each retry waits * `initialDelayMs * (backoffFactor ** retryNumber)` milliseconds. * Set to 0.0 for constant delay. Default is 2.0. */ backoffFactor: z.number().min(0).default(2), /** * Initial delay in milliseconds before first retry. Default is 1000 (1 second). */ initialDelayMs: z.number().min(0).default(1e3), /** * Maximum delay in milliseconds between retries. Caps exponential * backoff growth. Default is 60000 (60 seconds). */ maxDelayMs: z.number().min(0).default(6e4), /** * Whether to add random jitter (±25%) to delay to avoid thundering herd. * Default is `true`. */ jitter: z.boolean().default(true) }); export { INTERNAL_CALL_TAG, RetrySchema }; //# sourceMappingURL=constants.js.map