Class OssAgentStateStore

java.lang.Object
io.agentscope.extensions.oss.OssAgentStateStore
All Implemented Interfaces:
io.agentscope.core.state.AgentStateStore

public class OssAgentStateStore extends Object implements io.agentscope.core.state.AgentStateStore
Alibaba Cloud OSS backed AgentStateStore.

State objects are stored as JSON files in an OSS bucket with the following key layout:

 {keyPrefix}{userId}/{sessionId}/{stateKey}.json       — single State value
 {keyPrefix}{userId}/{sessionId}/{stateKey}.list.json  — List<State> as JSON array
 {keyPrefix}{userId}/{sessionId}/{stateKey}.list.hash  — hash for incremental append detection
 

Usage:


 OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

 AgentStateStore store = OssAgentStateStore.builder()
     .ossClient(ossClient)
     .bucketName("my-agentscope-bucket")
     .keyPrefix("agentscope/state/")
     .build();

 HarnessAgent agent = HarnessAgent.builder()
     .stateStore(store)
     .build();
 
  • Method Details

    • builder

      public static OssAgentStateStore.Builder builder()
    • save

      public void save(String userId, String sessionId, String key, io.agentscope.core.state.State value)
      Specified by:
      save in interface io.agentscope.core.state.AgentStateStore
    • save

      public void save(String userId, String sessionId, String key, List<? extends io.agentscope.core.state.State> values)
      Specified by:
      save in interface io.agentscope.core.state.AgentStateStore
    • get

      public <T extends io.agentscope.core.state.State> Optional<T> get(String userId, String sessionId, String key, Class<T> type)
      Specified by:
      get in interface io.agentscope.core.state.AgentStateStore
    • getList

      public <T extends io.agentscope.core.state.State> List<T> getList(String userId, String sessionId, String key, Class<T> itemType)
      Specified by:
      getList in interface io.agentscope.core.state.AgentStateStore
    • exists

      public boolean exists(String userId, String sessionId)
      Specified by:
      exists in interface io.agentscope.core.state.AgentStateStore
    • delete

      public void delete(String userId, String sessionId)
      Specified by:
      delete in interface io.agentscope.core.state.AgentStateStore
    • delete

      public void delete(String userId, String sessionId, String key)
      Specified by:
      delete in interface io.agentscope.core.state.AgentStateStore
    • listSessionIds

      public Set<String> listSessionIds(String userId)
      Specified by:
      listSessionIds in interface io.agentscope.core.state.AgentStateStore
    • close

      public void close()
      Specified by:
      close in interface io.agentscope.core.state.AgentStateStore