Memory.getThreadsByResourceId()
.getThreadsByResourceId()
関数は、ストレージから特定のリソース ID に紐づくすべてのスレッドを取得します。スレッドは、作成時刻または更新時刻を基準に、昇順または降順で並べ替えられます。
使用例
await memory?.getThreadsByResourceId({ resourceId: "user-123" });
パラメータ
resourceId:
string
スレッドを取得する対象リソースのID。
orderBy?:
ThreadOrderBy
スレッドの並び替えに使うフィールド。'createdAt' または 'updatedAt' を指定できます。既定値: 'createdAt'
sortDirection?:
ThreadSortDirection
並び順の方向。'ASC' または 'DESC' を指定できます。既定値: 'DESC'
戻り値
StorageThreadType[]:
Promise
指定されたリソースIDに関連付けられたスレッドの配列で解決される Promise。
詳細な使用例
src/test-memory.ts
import { mastra } from "./mastra";
const agent = mastra.getAgent("agent");
const memory = await agent.getMemory();
const thread = await memory?.getThreadsByResourceId({
resourceId: "user-123",
orderBy: "updatedAt",
sortDirection: "ASC"
});
console.log(thread);
関連
- Memory クラスリファレンス
- getThreadsByResourceIdPaginated - ページネーション対応版
- Memory の始め方(スレッド/リソースの概念を解説)
- createThread
- getThreadById