Class InvocationParameters
java.lang.Object
dev.langchain4j.invocation.InvocationParameters
Represents arbitrary parameters available during a single AI Service invocation.
InvocationParameters can be specified when invoking the AI Service:
interface Assistant {
String chat(@UserMessage String userMessage, InvocationParameters parameters);
}
InvocationParameters parameters = InvocationParameters.from(Map.of("userId", "12345"));
String response = assistant.chat("What is the weather in London?", parameters);
InvocationParameters can be accessed within the Tool-annotated method:
class Tools {
@Tool
String getWeather(String city, InvocationParameters parameters) {
String userId = parameters.get("userId");
UserPreferences preferences = getUserPreferences(userId);
return weatherService.getWeather(city, preferences.temperatureUnits());
}
}
In this case, the LLM is not aware of these parameters; they are only visible to LangChain4j and user code.
InvocationParameters can also be accessed within other AI Service components, such as:
- ToolProvider: inside the ToolProviderRequest - ToolArgumentsErrorHandler and ToolExecutionErrorHandler: inside the ToolErrorContext - RAG components: inside theQuery->Metadata
Parameters are stored in a mutable, thread safe Map.
- Since:
- 1.6.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()booleancontainsKey(String key) booleanstatic InvocationParametersstatic InvocationParameters<T> T<T> TgetOrDefault(String key, T defaultValue) inthashCode()<T> voidtoString()
-
Constructor Details
-
InvocationParameters
public InvocationParameters() -
InvocationParameters
-
-
Method Details
-
asMap
-
get
-
getOrDefault
-
put
-
containsKey
-
equals
-
hashCode
-
toString
-
from
-
from
-