类 InMemoryAgentStateStore
- 所有已实现的接口:
AgentStateStore
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
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidclearAll()Wipe everything (useful for testing).voidDelete a session and all its data.voidDelete a single state entry within a session.booleanCheck if a session exists.Get a single state value.Get a list of state values.intTotal number of(userId, sessionId)slots currently stored.listSessionIds(String userId) List session identifiers visible under the given user namespace.voidSave a single state value (full replacement).voidSave a list of state values.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.agentscope.core.state.AgentStateStore
close
-
构造器详细资料
-
InMemoryAgentStateStore
public InMemoryAgentStateStore()
-
-
方法详细资料
-
save
从接口复制的说明:AgentStateStoreSave 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= anonymoussessionId- session identifier; must be non-null and non-blankkey- the state key (e.g.,"agent_state","toolkit_activeGroups")value- the state value to save
-
save
从接口复制的说明:AgentStateStoreSave a list of state values.Different implementations may use different storage strategies:
JsonFileAgentStateStore: incremental append — only new elements are writtenInMemoryAgentStateStore: full replacement — replaces the entire list
Callers should always pass the full list. The implementation decides the storage strategy.
- 指定者:
save在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- 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) 从接口复制的说明:AgentStateStoreGet a single state value.- 指定者:
get在接口中AgentStateStore- 类型参数:
T- the state type- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state keytype- 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) 从接口复制的说明:AgentStateStoreGet a list of state values.- 指定者:
getList在接口中AgentStateStore- 类型参数:
T- the item type- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state keyitemType- the expected item type- 返回:
- the list of state values, or empty list if not found
-
exists
从接口复制的说明:AgentStateStoreCheck if a session exists.- 指定者:
exists在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blank- 返回:
- true if the session has any persisted state
-
delete
从接口复制的说明:AgentStateStoreDelete a session and all its data.- 指定者:
delete在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blank
-
delete
从接口复制的说明:AgentStateStoreDelete a single state entry within a session.- 指定者:
delete在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state key to delete
-
listSessionIds
从接口复制的说明:AgentStateStoreList session identifiers visible under the given user namespace.Use
userId == nullto 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).
-