MCPcopy Create free account
hub / github.com/dashscope/dashscope-sdk-java / AgentStudioMemoryStores

Class AgentStudioMemoryStores

samples/AgentStudioMemoryStores.java:18–94  ·  view source on GitHub ↗

Memory store example: seed a store, read it back, audit versions, cleanup. Set DASHSCOPE_API_KEY and DASHSCOPE_WORKSPACE before running.

Source from the content-addressed store, hash-verified

16 * <p>Set DASHSCOPE_API_KEY and DASHSCOPE_WORKSPACE before running.
17 */
18public class AgentStudioMemoryStores {
19
20 public static void main(String[] args) {
21 try (AgentStudioClient client = new AgentStudioClient()) {
22 // 1. Create a store; description is read by the agent - write it for
23 // the model, not for humans.
24 MemoryStore store =
25 client
26 .memoryStores()
27 .create(
28 MemoryStoreCreateParam.builder()
29 .name("demo-preferences")
30 .description("Per-user preferences and project context.")
31 .build());
32 System.out.printf("store: %s%n", store.getId());
33
34 // 2. Seed reference material before any session runs.
35 Memory memory =
36 client
37 .memoryStores()
38 .memories()
39 .create(
40 store.getId(),
41 MemoryCreateParam.builder()
42 .path("/formatting_standards.md")
43 .content("All reports use GAAP formatting.")
44 .build());
45 System.out.printf(
46 "memory: %s %s (%d bytes)%n",
47 memory.getId(), memory.getPath(), memory.getContentSizeBytes());
48
49 // 3. Read back with content (view=full; the default basic is metadata
50 // only). Print prefixes before iterating: the loop auto-paginates
51 // and prefixes are per page.
52 com.alibaba.dashscope.agentstudio.pagination.CursorPage<Memory> page =
53 client
54 .memoryStores()
55 .memories()
56 .list(store.getId(), MemoryListParam.builder().view("full").build());
57 System.out.printf("prefixes: %s%n", page.getPrefixes());
58 for (Memory item : page) {
59 System.out.printf("%s -> %s%n", item.getPath(), item.getContent());
60 }
61
62 // 4. Update with the optimistic lock (contentSha256 from step 2).
63 Memory updated =
64 client
65 .memoryStores()
66 .memories()
67 .update(
68 store.getId(),
69 memory.getId(),
70 MemoryUpdateParam.builder()
71 .content("All reports use GAAP formatting. ISO-8601 dates.")
72 .contentSha256(memory.getContentSha256())
73 .build());
74 System.out.printf("updated sha: %s%n", updated.getContentSha256());
75

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected