接口 StateModule
- 所有已知子接口:
Memory
- 所有已知实现类:
AgentBase,InMemoryMemory,PlanNotebook,ReActAgent,SkillBox,StructuredOutputCapableAgent,UserAgent
public interface StateModule
Interface for all stateful components in AgentScope.
This interface provides state serialization and deserialization capabilities for components that need to persist and restore their internal state. Components that implement this interface can have their state saved to and restored from external storage through the session management system.
Use saveTo(Session, String) and loadFrom(Session, String) for direct session
interaction with simple string session IDs.
Example usage:
Session session = new JsonSession(Path.of("sessions"));
// Load state if exists
agent.loadIfExists(session, "user_123");
// ... use agent ...
// Save state
agent.saveTo(session, "user_123");
-
方法概要
修饰符和类型方法说明default voidloadFrom(Session session, SessionKey sessionKey) Load state from the session.default voidLoad state from the session using a string session ID.default booleanloadIfExists(Session session, SessionKey sessionKey) Load state from the session if it exists.default booleanloadIfExists(Session session, String sessionId) Load state from the session if it exists using a string session ID.default voidsaveTo(Session session, SessionKey sessionKey) Save state to the session.default voidSave state to the session using a string session ID.
-
方法详细资料
-
saveTo
Save state to the session.Components should implement this method to persist their state using the Session's save methods.
- 参数:
session- the session to save state tosessionKey- the session identifier
-
saveTo
Save state to the session using a string session ID.- 参数:
session- the session to save state tosessionId- the session identifier as a string
-
loadFrom
Load state from the session.Components should implement this method to restore their state using the Session's get methods.
- 参数:
session- the session to load state fromsessionKey- the session identifier
-
loadFrom
Load state from the session using a string session ID.- 参数:
session- the session to load state fromsessionId- the session identifier as a string
-
loadIfExists
Load state from the session if it exists.- 参数:
session- the session to load state fromsessionKey- the session identifier- 返回:
- true if the session existed and state was loaded, false otherwise
-
loadIfExists
Load state from the session if it exists using a string session ID.- 参数:
session- the session to load state fromsessionId- the session identifier as a string- 返回:
- true if the session existed and state was loaded, false otherwise
-