Class AgentChatMemoryStore

java.lang.Object
org.cibseven.connect.ai.agent.impl.AgentChatMemoryStore

public final class AgentChatMemoryStore extends Object
Decides and holds the one ChatMemoryStore the agent connector uses. Every connector invocation with chat memory active looks its conversation up by memoryId in that store, which is how a BPMN process carries history across service-task invocations — typically across a human-feedback user task in between.

The reference here is per-JVM; where the conversations themselves live is the store's business. With the default store they are process variables in the engine database, shared by every replica, and this class holds nothing but the choice.

Which store is used by default is decided here, once, from "cibseven.connect.ai-agent.chatMemoryVariable.enabled": a ProcessVariableChatMemoryStore that persists the conversation as a process variable — surviving an engine restart and visible to every node of a clustered deployment, with a memoryId scoped to one process instance — or, when the flag is false, a JVM-local InMemoryChatMemoryStore.

Deployments needing different semantics — e.g. memory shared across process instances — can replace the store at startup via setStore(ChatMemoryStore), which takes precedence over the default. Mind that a store outside the engine (Redis, …) does not take part in the job transaction, so a failed and retried agent task can append the same turn twice. And only the process-variable store (ProcessVariableChatMemoryStore, chosen when "cibseven.connect.ai-agent.chatMemoryVariable.enabled" is true) keeps the conversation of the agent that drives an agentic ad hoc sub process out of its tools' reach (CIB7-2408).

The memory is keyed by an arbitrary Object (in practice a String) — typically the process instance id or a UUID generated by the connector on the first call.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    clear(Object memoryId)
    Forgets the chat history for a given memory id — mirrors ChatMemoryStore.deleteMessages(Object) on the current store.
    static dev.langchain4j.store.memory.chat.ChatMemoryStore
    Returns the currently configured shared ChatMemoryStore.
    static void
    setStore(dev.langchain4j.store.memory.chat.ChatMemoryStore newStore)
    Replaces the shared ChatMemoryStore and takes precedence over the default.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getStore

      public static dev.langchain4j.store.memory.chat.ChatMemoryStore getStore()
      Returns the currently configured shared ChatMemoryStore.
    • setStore

      public static void setStore(dev.langchain4j.store.memory.chat.ChatMemoryStore newStore)
      Replaces the shared ChatMemoryStore and takes precedence over the default. Intended for application startup wiring (e.g. a store shared across process instances) and for tests that need to isolate state.

      The store set here receives the calls of the agent that drives an agentic ad hoc sub process like any other, so that agent's conversation is no longer kept apart from its tools: a tool, a JavaDelegate or an execution listener that uses the agent's memoryId can read, rewrite or clear it. Only the process-variable store (ProcessVariableChatMemoryStore, chosen when "cibseven.connect.ai-agent.chatMemoryVariable.enabled" is true) keeps it out of their reach (CIB7-2408). Do not replace the store where agentic ad hoc sub processes run tools that must not see the agent's conversation.

    • clear

      public static void clear(Object memoryId)
      Forgets the chat history for a given memory id — mirrors ChatMemoryStore.deleteMessages(Object) on the current store. Rarely needed with the default store, where the memory variable dies with the process instance anyway.

      Contract: with the default ProcessVariableChatMemoryStore the conversation lives in a process variable, which is only reachable from a thread that carries a BpmnExecutionContext — that is, from inside an engine command. Called from an administration or application thread it would reach only the store's internal fallback buffer and leave the variable in the database. Rather than reporting success in that case, this method throws.

      With the process-variable store, one conversation it does not reach, and does not report: that of the agent driving an agentic ad hoc sub process. Only the turn runner's own call reaches it, so that the scope's tools can neither read, rewrite nor clear it (CIB7-2232). Called with that agent's memoryId from anywhere else — a tool, a JavaDelegate, an execution listener, on the scope itself too — this method clears only the process level, where that conversation is not, and returns normally. The agent's conversation ends with the scope (perEntry) or with the scope enclosing it (perActivity).

      Only the process-variable store keeps it apart (CIB7-2408). With "cibseven.connect.ai-agent.chatMemoryVariable.enabled" set to false, or a store set with setStore(ChatMemoryStore), this method clears the driving agent's conversation like any other.

      Throws:
      AgentConnectorException - when the current thread cannot reach the persisted conversation. Call it from within an engine command (for example a JavaDelegate or an execution listener), or delete the process instance, which removes the variable with it.