Class CapturedContextSupport

java.lang.Object
dev.langchain4j.invocation.CapturedContextSupport

public final class CapturedContextSupport extends Object
Carries the context of the thread that started an AI Service invocation, captured with ExecutorProvider.captureContext(), in the InvocationContext of the invocation, so that every task the invocation offloads runs with it, whichever thread submits the task.
  • Method Details

    • captureInto

      public static InvocationContext.Builder captureInto(InvocationContext.Builder builder)
      Captures the context of the calling thread into the given builder, if an ExecutorProvider that captures context is registered.
      Returns:
      the given builder
    • restoringIn

      public static Executor restoringIn(Executor executor, InvocationContext invocationContext)
      Returns:
      an executor that submits tasks to the given executor, running them with the context captured when the given invocation started; the given executor itself if nothing was captured