LangChain4jChatModel
class LangChain4jChatModel(model: ChatModel, streamingModel: StreamingChatModel? = null) : ChatModel
A ChatModel that calls any LangChain4j chat model, so an agent built with toolAgent or toolLoop works with every provider LangChain4j supports.
val openAi = OpenAiChatModel.builder().apiKey(key).modelName("gpt-5").build()
val agent = toolAgent(LangChain4jChatModel(openAi), tools = listOf(forecast))Content copied to clipboard
LangChain4j has a second kind of model for answers that arrive piece by piece. Pass one as streamingModel and stream uses it, so a toolAgent whose run is collected with stream shows the text while the model writes it:
val streaming = OpenAiStreamingChatModel.builder().apiKey(key).modelName("gpt-5").build()
val agent = toolAgent(LangChain4jChatModel(openAi, streaming), tools = listOf(forecast))Content copied to clipboard
LangChain4j calls block on network I/O, so each call runs on Dispatchers.IO. A model's thinking and other details that LangChain4j keeps in its AiMessage travel in ChatMessage.Assistant.providerContent.