@apeira/仓库
持久性 AgentStorage 关于阿皮拉的执行.
安装
pnpm add @apeira/storage
贾森
将完整的条目数组存储在 JSON 文件。 每个附件重写文件.
import { createAgent } from '@apeira/core'
import { json } from '@apeira/storage/json'
const agent = createAgent({
instructions: 'You are a helpful assistant.',
runner,
storage: json({ path: './data/agent.json' }),
})
当人可读文件有用且历史为时使用 JSON 存储 相对小.
贾森勒
每行存储一个条目并附加新条目而不重写现有条目 内容.
import { createAgent } from '@apeira/core'
import { jsonl } from '@apeira/storage/jsonl'
const agent = createAgent({
instructions: 'You are a helpful assistant.',
runner,
storage: jsonl({ path: './data/agent.jsonl' }),
})
JSONL是长期运行,附件重的代理更好的文件格式.
密钥值存储
适应网络存储或同步等字符串键值后端 存储 API. 条目被分割成块来避免存储完整日志 在一个钥匙下.
import type { StorageLike } from '@apeira/storage/kv'
import { createAgent } from '@apeira/core'
import { kv } from '@apeira/storage/kv'
declare const backend: StorageLike
const agent = createAgent({
instructions: 'You are a helpful assistant.',
runner,
storage: kv({
backend,
prefix: 'assistant',
segmentSize: 100,
}),
})
后端必须执行:
import type { MaybePromise } from '@apeira/core'
interface StorageLike {
getItem: (key: string) => MaybePromise<null | string | undefined>
removeItem: (key: string) => MaybePromise<void>
setItem: (key: string, value: string) => MaybePromise<void>
}
prefix 默认为 apeira 财务报告和审定财务报表 segmentSize 默认为 100。 。 。 .
储存寿命周期
所有实施都提供标准 AgentStorage 操作 :
import type { MaybePromise } from '@apeira/core'
interface AgentStorage<T> {
append: (...items: T[]) => MaybePromise<void>
clear: () => MaybePromise<void>
read: () => MaybePromise<Readonly<T[]>>
}
仅管理持续存在的条目 。 代理初始化和重置 基准属于核心:
const agent = createAgent({
initialInput: [user('Existing context')],
initialState: { userId: 'user-123' },
instructions: 'You are a helpful assistant.',
runner,
storage: jsonl({ path: './data/agent.jsonl' }),
})
在初始化期间,核心写 initialInput 仅当存储包含无
输入条目. agent.reset() 清除存储并恢复 initialInput 财务报告和审定财务报表
initialState。 。 。 .
一般存储
存储函数默认为 AgentEntry但可以存储另一个
JSON 序列大小类型 :
const store = jsonl<string>({ path: './data/items.jsonl' })
await store.append('first', 'second')
const items = await store.read()
JSON和JSONL的存储需要节点.js. 任何运行时间的密钥值存储工作 提供了兼容的后端.