Class InvocationParameters

java.lang.Object
dev.langchain4j.invocation.InvocationParameters

public class InvocationParameters extends Object
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 the Query -> Metadata

Parameters are stored in a mutable, thread safe Map.

Since:
1.6.0