chatNode

fun <State> chatNode(model: ChatModel, prompt: suspend (State) -> String, update: suspend (State, String) -> State): NodeAction<State>

Creates a NodeAction that sends a prompt built from the current state to model and merges the text reply back into the state.

node("writer", chatNode(
model = chatModel,
prompt = { state -> "Summarize: ${state.notes}" },
update = { state, reply -> state.copy(summary = reply) },
))

Parameters

model

the LangChain4j chat model to call.

prompt

builds the user message from the current state.

update

returns a new state that includes the model's reply.