Class CurrentInvocation
java.lang.Object
dev.langchain4j.internal.CurrentInvocation
Holds the
InvocationContext.invocationId() of the AI Service invocation that is doing its own work on the
current thread (for example running a tool, a guardrail, retrieval or the chatRequestTransformer), so that an AI Service
invoked by that work can record it as its parent invocation.
It is set only around that work, not around code of the caller (the handlers of a TokenStream, the
subscriber of a returned publisher, the continuations of a returned future), so an AI Service invoked by the
caller's code normally has no parent invocation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcallWith(InvocationContext invocationContext, Supplier<T> action) Calls the given action with the id of the given invocation context as the current one, then restores the previous one.static <T> TcallWithId(UUID invocationId, Supplier<T> action) Calls the given action with the given invocation id as the current one, then restores the previous one.static <T> TcallWithIdOrWithout(UUID invocationId, Supplier<T> action) Calls the given action with the given invocation id as the current one, or with no current invocation when the id isnull, then restores the previous one.static <T> TcallWithout(Supplier<T> action) Calls the given action with no current invocation, then restores the previous one.static UUIDstatic UUIDinvocationId(ChatRequestOptions options) static voidrunWith(InvocationContext invocationContext, Runnable action) Runs the given action with the id of the given invocation context as the current one, then restores the previous one.static voidrunWithIdOrWithout(UUID invocationId, Runnable action) Runs the given action likecallWithIdOrWithout(UUID, Supplier).static voidrunWithout(Runnable action) Runs the given action with no current invocation, then restores the previous one.
-
Method Details
-
invocationId
-
invocationId
- Returns:
- the invocation id that the listeners of a chat model call get: the one in the given options (which can
be
null) if any, otherwise the current one, otherwisenull.
-
runWith
Runs the given action with the id of the given invocation context as the current one, then restores the previous one. Does nothing special when the invocation context isnull. -
callWith
Calls the given action with the id of the given invocation context as the current one, then restores the previous one. Does nothing special when the invocation context isnull. -
callWithId
-
callWithIdOrWithout
Calls the given action with the given invocation id as the current one, or with no current invocation when the id isnull, then restores the previous one. Used where an id captured earlier must apply exactly, also when it isnull. -
runWithIdOrWithout
Runs the given action likecallWithIdOrWithout(UUID, Supplier). -
runWithout
Runs the given action with no current invocation, then restores the previous one. Used to notify listeners: their code is not part of the work of the invocation. -
callWithout
Calls the given action with no current invocation, then restores the previous one. Used when an AI Service is invoked during the work of another invocation: its listeners and callbacks are not part of that work.
-