translation/translated/documents/course/03-agent-memory/09-using-memory-in-applicat...

20 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 在你的应用程序中使用内存
当在你自己应用程序中使用内存playground 之外)时,你需要为每个智能体调用提供 `resourceId``threadId`
```typescript
// 在你的应用程序中使用内存的示例
const response = await memoryAgent.stream("Hello, my name is Alice.", {
resourceId: "user_alice",
threadId: "conversation_123",
});
```
**重要提示:**没有这些 ID即使内存配置正确你的智能体也不会使用内存。playground 为你处理这一点,但在应用程序中使用内存时,你需要自己添加 ID。
`resourceId` 应该是拥有对话的用户或实体的唯一标识符。这可以是你的认证系统中的用户 ID、电子邮件地址或任何其他唯一标识符。
`threadId` 应该是特定对话的唯一标识符。这允许单个用户与你的智能体进行多个单独的对话,每个对话都有自己的内存线程。
在实际应用中,当用户开始新对话时,你可能会生成这些 ID并将它们存储在数据库或客户端存储中以便在后续请求中重复使用。