api.memory

list()

api.memory.list({ limit }) → Promise<Memory[]>

账户上的每个便条, 最近先更改了内容 。 这是您显示用户的屏幕 。

GET /api/ai/memoriesfreean array
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

参数

limitinteger

多少个。 默认值 200,这也是账户可以持有的上限和上限。

由于上限和上限是同数,默认返回所有信息。没有页数,因为没有页数。

返回值

[
  {
    id: "…",
    name: "tone-of-voice",
    description: "How this user wants to be written to",
    content: "Prefers short, direct answers in French.",
    type: "preference",
    source: "user",
    createdAt: "…",
    updatedAt: "…"
  }
]
[
    {
        "id": "…",
        "name": "tone-of-voice",
        "description": "How this user wants to be written to",
        "content": "Prefers short, direct answers in French.",
        "type": "preference",
        "source": "user",
        "createdAt": "…",
        "updatedAt": "…",
    }
]

直截了当的数组,而不是信封。一个没有注释的账户给出空数组。

内容随内容而来

与代理人获得什么不同——仅是索引——这就代表了一切,包括内容,而是指一个人看人们所记得的。

const notes = await api.memory.list();

for (const n of notes) {
  console.log(`${n.name} · ${n.type} · by ${n.source}`);
  console.log(`  ${n.description}`);
  console.log(`  ${n.content}`);
}
notes = api.memory.list()

for n in notes:
    print(f"{n['name']} · {n['type']} · by {n['source']}")
    print(f"  {n['description']}")
    print(f"  {n['content']}")

按类型分组

类型类型类型含义
优先用户希望如何完成
项目 项目项目项目有关手头的工作
事实事实稳定且可核查的东西
更正更正探员出了点问题 被告诉了
其他其它东西都不符合时的默认 。
const byType = new Map();
for (const n of await api.memory.list()) {
  byType.set(n.type, [...(byType.get(n.type) || []), n]);
}

// Corrections are the ones worth reviewing: each is something that went wrong once.
byType.get("correction")?.forEach((n) => console.log(n.name, "·", n.content));
from collections import defaultdict

by_type = defaultdict(list)
for n in api.memory.list():
    by_type[n["type"]].append(n)

# Corrections are the ones worth reviewing: each is something that went wrong once.
for n in by_type["correction"]:
    print(n["name"], "·", n["content"])

值得审查的正在运行

内存的功用衰减, 大小衰减: 有关结束的项目的注释仍然被读入上下文。 观察一下长期没有变化的是廉价的修剪版本 。

const notes = await api.memory.list();
const quarter = Date.now() - 90 * 24 * 60 * 60 * 1000;

const old = notes.filter((n) => Date.parse(n.updatedAt) < quarter && n.type === "project");

for (const n of old) {
  console.log(`still remembered, last touched ${n.updatedAt}: ${n.name} — ${n.description}`);
}
from datetime import datetime, timedelta, timezone

notes = api.memory.list()
quarter = datetime.now(timezone.utc) - timedelta(days=90)

old = [n for n in notes
       if n["type"] == "project" and datetime.fromisoformat(n["updatedAt"].replace("Z", "+00:00")) < quarter]

for n in old:
    print(f"still remembered, last touched {n['updatedAt']}: {n['name']} — {n['description']}")
手工或让用户自己动手

便条是关于账户持有人的, 所以删除代表账户持有人的便条是决定, 不是内部管理。 向他们展示列表通常比较好 。