Class DefaultInvocationContext
- All Implemented Interfaces:
InvocationContext
InvocationContext built by LangChain4j.
Besides its values, it holds whether the invocation has already reported its end (see InvocationEnd).
Copies made with InvocationContext.toBuilder() that keep the same invocationId() share this state, so the
invocation reports its end only once, whichever copy is used. A copy with another invocation id, or a context
built from scratch, starts as not ended.
- Since:
- 1.6.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface InvocationContext
InvocationContext.Builder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe chat memory id parameter of the methodReturns the defaultChatRequestParametersof the chat model configured on the AI service.booleaninthashCode()The fully-qualified name of the AI Service interface where the invocation was initiated fromUnique identifier for an entire AI Service invocation.The invocation parametersMap<Class<? extends LangChain4jManaged>, LangChain4jManaged> LangChain4j managed parametersThe arguments passed into the AI Service methodThe method name onInvocationContext.interfaceName()where the invocation was initiated fromThe declared return type of the AI Service method, including its type arguments (for exampleList<String>orTokenStream).Returns theModelProviderof the chat model configured on the AI service.TheUserMessagecreated from the AI Service method and its prompt template, before any transformation (RAG augmentation, content injection, input guardrails, output format instructions).TheInvocationContext.invocationId()of the parent invocation: the AI Service invocation whose own work started this invocation.Retrieves the point in time when the invocation occurred.toString()TheUserMessageto be sent to the LLM.Methods inherited from interface InvocationContext
toBuilder
-
Constructor Details
-
DefaultInvocationContext
-
-
Method Details
-
invocationId
Description copied from interface:InvocationContextUnique identifier for an entire AI Service invocation. AI Services created withAiServicestreat each subscription to a publisher returned by an AI Service method as a separate invocation, with its own identifier.- Specified by:
invocationIdin interfaceInvocationContext
-
parentInvocationId
Description copied from interface:InvocationContextTheInvocationContext.invocationId()of the parent invocation: the AI Service invocation whose own work started this invocation. This is the case when one of these parts of an AI Service calls another AI Service:- a tool, a tool error handler or the strategy for hallucinated tool names
- a tool provider
- an input or output guardrail
- a component of the retrieval augmentor (for example a query transformer or a content retriever)
- the system or user message provider, or the system message transformer
- the chat memory (including its
ChatMemoryStore) or the chat memory provider - the moderation model
- the
chatRequestTransformer - the chat model itself (for example your own
ChatModelimplementation)
It is
nullwhen the AI Service is called from your own code (for example from a handler of aTokenStreamor from a listener, also from those of an AI Service that itself has a parent), when there is no parent, or when thisInvocationContextimplementation does not track it.The parent is also known when LangChain4j itself runs that part on another thread (for example tools executed concurrently, or a blocking content retriever offloaded to an executor). But if your own code in that part hands the call to another thread (for example with
CompletableFuture.supplyAsync(..., executor)), it isnull. In rare cases, when futures are shared between invocations, it can even name another invocation. So treat it as best effort.It is filled by the AI Service implementation that LangChain4j provides. Frameworks that replace that implementation (for example through
AiServicesFactory) returnnulluntil they add support for it, also for AI Services they create throughAiServices.builder(...).It is set when the AI Service method is called: later runs of the same
TokenStreamkeep it.Agents run by an agentic workflow (sequence, parallel, loop, conditional) or by a supervisor currently have no parent. An agent called from a tool of another agent has one.
- Specified by:
parentInvocationIdin interfaceInvocationContext- Returns:
- the id of the parent invocation, or
nullif there is none or it is not known
-
interfaceName
Description copied from interface:InvocationContextThe fully-qualified name of the AI Service interface where the invocation was initiated from- Specified by:
interfaceNamein interfaceInvocationContext- See Also:
-
methodName
Description copied from interface:InvocationContextThe method name onInvocationContext.interfaceName()where the invocation was initiated from- Specified by:
methodNamein interfaceInvocationContext
-
methodReturnType
Description copied from interface:InvocationContextThe declared return type of the AI Service method, including its type arguments (for exampleList<String>orTokenStream).Frameworks that create the context with their own AI Service implementation return
nulluntil they add support for it.- Specified by:
methodReturnTypein interfaceInvocationContext- Returns:
- the return type of the AI Service method, or
nullif it is not known
-
methodArguments
Description copied from interface:InvocationContextThe arguments passed into the AI Service method- Specified by:
methodArgumentsin interfaceInvocationContext
-
userMessage
Description copied from interface:InvocationContextTheUserMessageto be sent to the LLM. This is the message after all transformations (RAG augmentation, content injection, input guardrails, output format instructions).- Specified by:
userMessagein interfaceInvocationContext
-
originalUserMessage
Description copied from interface:InvocationContextTheUserMessagecreated from the AI Service method and its prompt template, before any transformation (RAG augmentation, content injection, input guardrails, output format instructions). It is what the user asked, without the retrieved content, for example to decide which tools or models are relevant to the question.- Specified by:
originalUserMessagein interfaceInvocationContext
-
chatMemoryId
Description copied from interface:InvocationContextThe chat memory id parameter of the method- Specified by:
chatMemoryIdin interfaceInvocationContext
-
defaultRequestParameters
Description copied from interface:InvocationContextReturns the defaultChatRequestParametersof the chat model configured on the AI service.- Specified by:
defaultRequestParametersin interfaceInvocationContext
-
modelProvider
Description copied from interface:InvocationContextReturns theModelProviderof the chat model configured on the AI service.- Specified by:
modelProviderin interfaceInvocationContext
-
invocationParameters
Description copied from interface:InvocationContextThe invocation parameters- Specified by:
invocationParametersin interfaceInvocationContext
-
managedParameters
Description copied from interface:InvocationContextLangChain4j managed parameters- Specified by:
managedParametersin interfaceInvocationContext
-
timestamp
Description copied from interface:InvocationContextRetrieves the point in time when the invocation occurred.- Specified by:
timestampin interfaceInvocationContext
-
equals
-
hashCode
-
toString
-