langchain.js
    Preparing search index...

    Class ThreadsClient<TStateType, TUpdateType>

    Type Parameters

    Hierarchy

    • BaseClient
      • ThreadsClient
    Index

    Constructors

    Properties

    apiUrl: string
    asyncCaller: AsyncCaller
    defaultHeaders: Record<string, HeaderValue>
    onRequest?: RequestHook
    timeoutMs: undefined | number

    Methods

    • Copy an existing thread

      Parameters

      • threadId: string

        ID of the thread to be copied

      Returns Promise<Thread<TStateType>>

      Newly copied thread

    • Count threads matching filters.

      Type Parameters

      Parameters

      Returns Promise<number>

      Number of threads matching the criteria.

    • Create a new thread.

      Parameters

      • Optionalpayload: {
            graphId?: string;
            ifExists?: OnConflictBehavior;
            metadata?: Metadata;
            supersteps?: {
                updates: { asNode: string; command?: Command; values: unknown }[];
            }[];
            threadId?: string;
            ttl?: number
            | { strategy?: "delete"; ttl: number };
        }

        Payload for creating a thread.

        • OptionalgraphId?: string

          Graph ID to associate with the thread.

        • OptionalifExists?: OnConflictBehavior

          How to handle duplicate creation.

          "raise"
          
        • Optionalmetadata?: Metadata

          Metadata for the thread.

        • Optionalsupersteps?: { updates: { asNode: string; command?: Command; values: unknown }[] }[]

          Apply a list of supersteps when creating a thread, each containing a sequence of updates.

          Used for copying a thread between deployments.

        • OptionalthreadId?: string

          ID of the thread to create.

          If not provided, a random UUID will be generated.

        • Optionalttl?: number | { strategy?: "delete"; ttl: number }

          Optional time-to-live in minutes for the thread. If a number is provided, it is treated as minutes and defaults to strategy "delete". You may also provide an object { ttl: number, strategy?: "delete" }.

      Returns Promise<Thread<TStateType>>

      The created thread.

    • Delete a thread.

      Parameters

      • threadId: string

        ID of the thread.

      Returns Promise<void>

    • Type Parameters

      • T

      Parameters

      • path: string
      • options: RequestInit & {
            json?: unknown;
            params?: Record<string, unknown>;
            signal?: AbortSignal;
            timeoutMs?: null | number;
            withResponse: true;
        }

      Returns Promise<[T, Response]>

    • Type Parameters

      • T

      Parameters

      • path: string
      • Optionaloptions: RequestInit & {
            json?: unknown;
            params?: Record<string, unknown>;
            signal?: AbortSignal;
            timeoutMs?: null | number;
            withResponse?: false;
        }

      Returns Promise<T>

    • Get all past states for a thread.

      Type Parameters

      Parameters

      • threadId: string

        ID of the thread.

      • Optionaloptions: {
            before?: Config;
            checkpoint?: Partial<Omit<Checkpoint, "thread_id">>;
            limit?: number;
            metadata?: Metadata;
        }

        Additional options.

      Returns Promise<ThreadState<ValuesType>[]>

      List of thread states.

    • Parameters

      • threadId: string
      • Optionaloptions: { lastEventId?: string; streamMode?: ThreadStreamMode | ThreadStreamMode[] }

      Returns AsyncGenerator<{ data: any; event: StreamEvent; id?: string }>

    • Patch the metadata of a thread.

      Parameters

      • threadIdOrConfig: string | Config

        Thread ID or config to patch the state of.

      • metadata: Metadata

        Metadata to patch the state with.

      Returns Promise<void>

    • Parameters

      • path: string
      • Optionaloptions: RequestInit & {
            json?: unknown;
            params?: Record<string, unknown>;
            timeoutMs?: null | number;
            withResponse?: boolean;
        }

      Returns [url: URL, init: RequestInit]

    • List threads

      Type Parameters

      Parameters

      • Optionalquery: {
            ids?: string[];
            limit?: number;
            metadata?: Metadata;
            offset?: number;
            select?: ThreadSelectField[];
            sortBy?: ThreadSortBy;
            sortOrder?: SortOrder;
            status?: ThreadStatus;
        }

        Query options

        • Optionalids?: string[]

          Filter by specific thread IDs.

        • Optionallimit?: number

          Maximum number of threads to return. Defaults to 10

        • Optionalmetadata?: Metadata

          Metadata to filter threads by.

        • Optionaloffset?: number

          Offset to start from.

        • Optionalselect?: ThreadSelectField[]
        • OptionalsortBy?: ThreadSortBy

          Sort by.

        • OptionalsortOrder?: SortOrder

          Sort order. Must be one of 'asc' or 'desc'.

        • Optionalstatus?: ThreadStatus

          Thread status to filter on.

      Returns Promise<Thread<ValuesType>[]>

      List of threads

    • Update a thread.

      Parameters

      • threadId: string

        ID of the thread.

      • Optionalpayload: { metadata?: Metadata; ttl?: number | { strategy?: "delete"; ttl: number } }

        Payload for updating the thread.

        • Optionalmetadata?: Metadata

          Metadata for the thread.

        • Optionalttl?: number | { strategy?: "delete"; ttl: number }

          Optional time-to-live in minutes for the thread. If a number is provided, it is treated as minutes and defaults to strategy "delete". You may also provide an object { ttl: number, strategy?: "delete" }.

      Returns Promise<Thread<DefaultValues>>

      The updated thread.

    • Add state to a thread.

      Type Parameters

      Parameters

      • threadId: string

        The ID of the thread.

      • options: {
            asNode?: string;
            checkpoint?: Checkpoint;
            checkpointId?: string;
            values: ValuesType;
        }

      Returns Promise<Pick<Config, "configurable">>