Uses of Interface
dev.langchain4j.memory.ChatMemory
Packages that use ChatMemory
Package
Description
-
Uses of ChatMemory in dev.langchain4j.agentic.agent
Methods in dev.langchain4j.agentic.agent with parameters of type ChatMemoryModifier and TypeMethodDescriptionAgentBuilder.chatMemory(ChatMemory chatMemory) Sets theChatMemoryused to maintain conversation history for this agent. -
Uses of ChatMemory in dev.langchain4j.chain
Methods in dev.langchain4j.chain with parameters of type ChatMemoryModifier and TypeMethodDescriptionConversationalChain.ConversationalChainBuilder.chatMemory(ChatMemory chatMemory) ConversationalRetrievalChain.Builder.chatMemory(ChatMemory chatMemory) Constructors in dev.langchain4j.chain with parameters of type ChatMemoryModifierConstructorDescriptionConversationalRetrievalChain(ChatModel chatModel, ChatMemory chatMemory, ContentRetriever contentRetriever) ConversationalRetrievalChain(ChatModel chatModel, ChatMemory chatMemory, RetrievalAugmentor retrievalAugmentor) -
Uses of ChatMemory in dev.langchain4j.guardrail
Methods in dev.langchain4j.guardrail that return ChatMemoryMethods in dev.langchain4j.guardrail with parameters of type ChatMemoryModifier and TypeMethodDescriptionGuardrailRequestParams.Builder.chatMemory(ChatMemory chatMemory) Sets the chat memory. -
Uses of ChatMemory in dev.langchain4j.memory.chat
Classes in dev.langchain4j.memory.chat that implement ChatMemoryModifier and TypeClassDescriptionclassThis chat memory operates as a sliding window whose size is controlled by aMessageWindowChatMemory.maxMessagesProvider.classThis chat memory operates as a sliding window whose size is controlled by aTokenWindowChatMemory.maxTokensProvider.Methods in dev.langchain4j.memory.chat that return ChatMemory -
Uses of ChatMemory in dev.langchain4j.service
Methods in dev.langchain4j.service with parameters of type ChatMemoryModifier and TypeMethodDescriptionAiServices.chatMemory(ChatMemory chatMemory) Configures the chat memory that will be used to preserve conversation history between method calls.voidAiServiceContext.initChatMemories(ChatMemory chatMemory) -
Uses of ChatMemory in dev.langchain4j.service.memory
Methods in dev.langchain4j.service.memory that return ChatMemoryModifier and TypeMethodDescriptionChatMemoryService.evictChatMemory(Object memoryId) ChatMemoryAccess.getChatMemory(Object memoryId) Returns theChatMemorywith the given id for this AI service or null if such memory doesn't exist.ChatMemoryService.getChatMemory(Object memoryId) ChatMemoryService.getOrCreateChatMemory(Object memoryId) ChatMemoryService.getOrCreateInvocationChatMemory(InvocationContext invocationContext) Returns the chat memory of the given invocation, wrapped so that every call to it (and so to itsChatMemoryStore) runs as work of that invocation: an AI Service invoked from there gets it as its parent invocation.static ChatMemoryChatMemoryService.unwrap(ChatMemory chatMemory) Returns the chat memory as configured by the user, without the wrapper added byChatMemoryService.getOrCreateInvocationChatMemory(InvocationContext).Methods in dev.langchain4j.service.memory that return types with arguments of type ChatMemoryMethods in dev.langchain4j.service.memory with parameters of type ChatMemoryModifier and TypeMethodDescriptionstatic ChatMemoryChatMemoryService.unwrap(ChatMemory chatMemory) Returns the chat memory as configured by the user, without the wrapper added byChatMemoryService.getOrCreateInvocationChatMemory(InvocationContext).Constructors in dev.langchain4j.service.memory with parameters of type ChatMemory -
Uses of ChatMemory in dev.langchain4j.service.tool
Methods in dev.langchain4j.service.tool with parameters of type ChatMemoryModifier and TypeMethodDescriptionvoidToolService.compensateIfNeeded(List<ToolExecutionRequest> toolExecutionRequests, Map<ToolExecutionRequest, ToolExecutionResult> toolResults, List<ToolExecutionResultMessage> resultMessages, List<ToolService.CompensableToolExecution> compensableExecutions, boolean anyToolErrored, ChatMemory chatMemory, List<ChatMessage> messages, InvocationContext invocationContext, AiServiceListenerRegistrar listenerRegistrar) Synchronous tool compensation, used by the synchronous /TokenStreammodes.ToolService.compensateIfNeededAsync(List<ToolExecutionRequest> toolExecutionRequests, Map<ToolExecutionRequest, ToolExecutionResult> toolResults, List<ToolExecutionResultMessage> resultMessages, List<ToolService.CompensableToolExecution> compensableExecutions, boolean anyToolErrored, @Nullable ChatMemory chatMemory, @Nullable List<ChatMessage> messages, InvocationContext invocationContext, AiServiceListenerRegistrar listenerRegistrar, @Nullable Consumer<AiServiceStreamingEvent.ToolCompensatedEvent> streamEventEmitter, boolean alreadyCollected, @Nullable String preCollectedFailedToolName, @Nullable Throwable invocationError) Non-blocking counterpart ofToolService.compensateIfNeeded(List, Map, List, List, boolean, ChatMemory, List, InvocationContext, AiServiceListenerRegistrar), used by theCompletableFutureand reactive modes.voidToolService.compensateOnCancellation(Map<ToolExecutionRequest, ToolExecutionResult> currentRoundResults, @Nullable List<ToolExecutionRequest> unsavedRequests, @Nullable List<ToolService.CompensableToolExecution> compensableExecutions, @Nullable ChatMemory chatMemory, InvocationContext invocationContext, AiServiceListenerRegistrar listenerRegistrar) Blocking counterpart ofToolService.compensateOnCancellationAsync(List, Map, List, List, ChatMemory, List, InvocationContext, AiServiceListenerRegistrar), used by theTokenStreammode, which uses the chat memory synchronously: rolls back, on cancellation, every compensable tool that had already executed successfully, across all rounds, on the calling thread.ToolService.compensateOnCancellationAsync(@Nullable List<ToolExecutionRequest> currentRoundRequests, @Nullable Map<ToolExecutionRequest, ToolExecutionResult> currentRoundResults, @Nullable List<ToolExecutionRequest> unsavedRequests, @Nullable List<ToolService.CompensableToolExecution> compensableExecutions, @Nullable ChatMemory chatMemory, @Nullable List<ChatMessage> messages, InvocationContext invocationContext, AiServiceListenerRegistrar listenerRegistrar) Rolls back, on cancellation, every compensable tool that had already executed successfully - across all rounds - implementing the "drain the round, then roll back" contract for the asynchronous and reactive modes.ToolService.executeInferenceAndToolsLoop(AiServiceContext context, Object memoryId, ChatResponse chatResponse, ChatRequestParameters parameters, List<ChatMessage> messages, ChatMemory chatMemory, InvocationContext invocationContext, ToolServiceContext toolServiceContext, boolean isReturnTypeResult) ToolService.executeInferenceAndToolsLoop(AiServiceContext context, Object memoryId, ChatResponse chatResponse, ChatRequestParameters parameters, List<ChatMessage> messages, ChatMemory chatMemory, InvocationContext invocationContext, ToolServiceContext toolServiceContext, Function<ChatRequest, ChatResponse> chatModelInvoker) ToolService.executeInferenceAndToolsLoopAsync(AiServiceContext context, Object memoryId, ChatResponse chatResponse, ChatRequestParameters parameters, List<ChatMessage> messages, ChatMemory chatMemory, InvocationContext invocationContext, ToolServiceContext toolServiceContext, CompletableFuture<?> cancellation) ToolService.executeInferenceAndToolsLoopAsync(AiServiceContext context, Object memoryId, ChatResponse chatResponse, ChatRequestParameters parameters, List<ChatMessage> messages, ChatMemory chatMemory, InvocationContext invocationContext, ToolServiceContext toolServiceContext, CompletableFuture<?> cancellation, Function<ChatRequest, CompletableFuture<ChatResponse>> chatModelInvoker) AsToolService.executeInferenceAndToolsLoopAsync(AiServiceContext, Object, ChatResponse, ChatRequestParameters, List, ChatMemory, InvocationContext, ToolServiceContext, CompletableFuture), but with a caller-supplied asynchronous model invoker.voidToolService.failRoundBeforeRethrow(List<ToolExecutionRequest> toolRequests, Map<ToolExecutionRequest, ToolExecutionResult> results, Map<ToolExecutionRequest, Throwable> errors, Throwable errorToRethrow, @Nullable List<ToolService.CompensableToolExecution> compensableExecutions, @Nullable ChatMemory chatMemory, @Nullable List<ChatMessage> messages, InvocationContext invocationContext, AiServiceListenerRegistrar listenerRegistrar) Fails a tool-calling round in the synchronous andTokenStreammodes, right before the caller rethrowserrorToRethrow, the way the non-blocking modes do before they fail the invocation: fires aToolExecutedEventfor each tool of the round that has terminated (seeToolService.fireToolExecutedEventsOfFailedRound(InvocationContext, List, Map, Map, AiServiceListenerRegistrar)); when cross-agent compensation is enabled, reports the tools of the round that succeeded and have a compensating action to it, and then tells it that a tool failed, so it rolls back the compensable tools of the agentic system right away, as for any other tool error; when compensation on tool errors is enabled, rolls back the tools with a compensating action that succeeded in this round and in the earlier rounds: their compensating actions run, their results in the chat memory are rewritten, and aToolCompensatedEventis fired for each of them. A failure of a listener of theToolExecutedEvents is added as suppressed to the first error inerrors.ToolService.persistToolResultsAndResolveMessages(AiServiceContext context, @Nullable ChatMemory chatMemory, List<ChatMessage> accumulator, List<ToolExecutionResultMessage> resultMessages, InvocationContext invocationContext, Runnable onSaved) LikeToolService.persistToolResultsAndResolveMessages(AiServiceContext, ChatMemory, List, List, InvocationContext), and runsonSavedas soon as the result messages are saved, before the messages are read back, so that a caller knows that they are saved even when reading the messages back fails.ToolService.persistToolResultsAndResolveMessages(AiServiceContext context, ChatMemory chatMemory, List<ChatMessage> accumulator, List<ToolExecutionResultMessage> resultMessages, InvocationContext invocationContext) Persists the tool-result messages and resolves the messages to send in the next request — the memory-touching counterpart toToolService.processToolResults(AiServiceContext, List, Map, List, InvocationContext, ToolServiceContext), kept out of that shared bookkeeping so that each AI Service mode can perform the memory I/O on the appropriate thread (synchronously for the sync/TokenStreammodes, composed for theCompletableFuture/reactive modes).ToolService.persistToolResultsAndResolveMessagesSync(AiServiceContext context, ChatMemory chatMemory, List<ChatMessage> accumulator, List<ToolExecutionResultMessage> resultMessages, InvocationContext invocationContext) Blocking counterpart ofToolService.persistToolResultsAndResolveMessages(AiServiceContext, ChatMemory, List, List, InvocationContext)for the synchronous andTokenStreamAI Service modes, which use the synchronousChatMemorymethods (so a memory backed by a blocking store that only implements the synchronous methods keeps working).