接口 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 void
    loadFrom(Session session, SessionKey sessionKey)
    Load state from the session.
    default void
    loadFrom(Session session, String sessionId)
    Load state from the session using a string session ID.
    default boolean
    loadIfExists(Session session, SessionKey sessionKey)
    Load state from the session if it exists.
    default boolean
    loadIfExists(Session session, String sessionId)
    Load state from the session if it exists using a string session ID.
    default void
    saveTo(Session session, SessionKey sessionKey)
    Save state to the session.
    default void
    saveTo(Session session, String sessionId)
    Save state to the session using a string session ID.
  • 方法详细资料

    • saveTo

      default void saveTo(Session session, SessionKey sessionKey)
      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 to
      sessionKey - the session identifier
    • saveTo

      default void saveTo(Session session, String sessionId)
      Save state to the session using a string session ID.
      参数:
      session - the session to save state to
      sessionId - the session identifier as a string
    • loadFrom

      default void loadFrom(Session session, SessionKey sessionKey)
      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 from
      sessionKey - the session identifier
    • loadFrom

      default void loadFrom(Session session, String sessionId)
      Load state from the session using a string session ID.
      参数:
      session - the session to load state from
      sessionId - the session identifier as a string
    • loadIfExists

      default boolean loadIfExists(Session session, SessionKey sessionKey)
      Load state from the session if it exists.
      参数:
      session - the session to load state from
      sessionKey - the session identifier
      返回:
      true if the session existed and state was loaded, false otherwise
    • loadIfExists

      default boolean loadIfExists(Session session, String sessionId)
      Load state from the session if it exists using a string session ID.
      参数:
      session - the session to load state from
      sessionId - the session identifier as a string
      返回:
      true if the session existed and state was loaded, false otherwise