类 InMemoryAgentStateStore

java.lang.Object
io.agentscope.core.state.InMemoryAgentStateStore
所有已实现的接口:
AgentStateStore

public class InMemoryAgentStateStore extends Object implements AgentStateStore
In-memory implementation of the AgentStateStore interface.

This implementation stores agent state in memory using a ConcurrentHashMap. It is suitable for single-process applications where persistence across restarts is not required.

Slot key: the (userId, sessionId) pair is the storage slot. null userId is mapped to the literal "__anon__" bucket so anonymous sessions don't collide with users actually named "".

Thread Safety: this class is thread-safe.

Limitations:

  • State is lost when the JVM exits
  • Not suitable for distributed environments
  • Memory usage grows with the number of sessions
  • 构造器详细资料

    • InMemoryAgentStateStore

      public InMemoryAgentStateStore()
  • 方法详细资料

    • save

      public void save(String userId, String sessionId, String key, State value)
      从接口复制的说明: AgentStateStore
      Save a single state value (full replacement).

      This method saves a single state object, replacing any existing value with the same key.

      指定者:
      save 在接口中 AgentStateStore
      参数:
      userId - nullable user identifier; null = anonymous
      sessionId - session identifier; must be non-null and non-blank
      key - the state key (e.g., "agent_state", "toolkit_activeGroups")
      value - the state value to save
    • save

      public void save(String userId, String sessionId, String key, List<? extends State> values)
      从接口复制的说明: AgentStateStore
      Save a list of state values.

      Different implementations may use different storage strategies:

      Callers should always pass the full list. The implementation decides the storage strategy.

      指定者:
      save 在接口中 AgentStateStore
      参数:
      userId - nullable user identifier
      sessionId - session identifier; must be non-null and non-blank
      key - the state key (e.g., "memory_messages")
      values - the full list of state values
    • get

      public <T extends State> Optional<T> get(String userId, String sessionId, String key, Class<T> type)
      从接口复制的说明: AgentStateStore
      Get a single state value.
      指定者:
      get 在接口中 AgentStateStore
      类型参数:
      T - the state type
      参数:
      userId - nullable user identifier
      sessionId - session identifier; must be non-null and non-blank
      key - the state key
      type - the expected state type
      返回:
      the state value, or empty if not found
    • getList

      public <T extends State> List<T> getList(String userId, String sessionId, String key, Class<T> itemType)
      从接口复制的说明: AgentStateStore
      Get a list of state values.
      指定者:
      getList 在接口中 AgentStateStore
      类型参数:
      T - the item type
      参数:
      userId - nullable user identifier
      sessionId - session identifier; must be non-null and non-blank
      key - the state key
      itemType - the expected item type
      返回:
      the list of state values, or empty list if not found
    • exists

      public boolean exists(String userId, String sessionId)
      从接口复制的说明: AgentStateStore
      Check if a session exists.
      指定者:
      exists 在接口中 AgentStateStore
      参数:
      userId - nullable user identifier
      sessionId - session identifier; must be non-null and non-blank
      返回:
      true if the session has any persisted state
    • delete

      public void delete(String userId, String sessionId)
      从接口复制的说明: AgentStateStore
      Delete a session and all its data.
      指定者:
      delete 在接口中 AgentStateStore
      参数:
      userId - nullable user identifier
      sessionId - session identifier; must be non-null and non-blank
    • delete

      public void delete(String userId, String sessionId, String key)
      从接口复制的说明: AgentStateStore
      Delete a single state entry within a session.
      指定者:
      delete 在接口中 AgentStateStore
      参数:
      userId - nullable user identifier
      sessionId - session identifier; must be non-null and non-blank
      key - the state key to delete
    • listSessionIds

      public Set<String> listSessionIds(String userId)
      从接口复制的说明: AgentStateStore
      List session identifiers visible under the given user namespace.

      Use userId == null to list anonymous sessions. Pass a concrete user to list only that user's sessions. There is no API to list across users in one call — that is a separate administrative concern (admin starter handles it by iterating known users).

      指定者:
      listSessionIds 在接口中 AgentStateStore
      参数:
      userId - nullable user identifier
      返回:
      set of session identifiers stored under userId
    • getSessionCount

      public int getSessionCount()
      Total number of (userId, sessionId) slots currently stored.
    • clearAll

      public void clearAll()
      Wipe everything (useful for testing).