docs: make English the default docs language and fix link paths

This commit is contained in:
zhayujie
2026-05-31 17:52:22 +08:00
parent 126649f70f
commit 7bf4ef3d05
231 changed files with 8999 additions and 8974 deletions

View File

@@ -1,81 +1,81 @@
---
title: 短期记忆
description: 对话上下文 — 消息管理、压缩策略和上下文操作
title: Short-term Memory
description: Conversation context — message management, compression strategies, and context operations
---
对话上下文是 Agent 的短期记忆包含当前会话中的所有消息用户输入、Agent 回复、工具调用及结果)。合理管理上下文对于 Agent 的推理质量和成本控制至关重要。
Conversation context is the Agent's short-term memory, containing all messages in the current session (user input, Agent replies, tool calls and results). Proper context management is critical for the Agent's reasoning quality and cost control.
## 上下文结构
## Context Structure
每一轮对话由以下消息组成:
Each conversation turn consists of:
```
用户消息 → Agent 思考 → 工具调用 → 工具结果 → ... → Agent 最终回复
User message → Agent thinking → Tool call → Tool result → ... → Agent final reply
```
一轮中可能包含多次工具调用Agent 的决策步数由 `agent_max_steps` 控制),所有工具调用和结果都会保留在上下文中,直到被压缩或裁剪。
A single turn may include multiple tool calls (controlled by `agent_max_steps`). All tool calls and results are retained in context until compressed or trimmed.
## 关键配置
## Key Configuration
| 参数 | 说明 | 默认值 |
| Parameter | Description | Default |
| --- | --- | --- |
| `agent_max_context_tokens` | 上下文最大 token 预算 | `50000` |
| `agent_max_context_turns` | 上下文最大对话轮次 | `20` |
| `agent_max_steps` | 单轮对话最大决策步数(工具调用次数) | `15` |
| `agent_max_context_tokens` | Maximum context token budget | `50000` |
| `agent_max_context_turns` | Maximum conversation turns in context | `20` |
| `agent_max_steps` | Maximum decision steps per turn (tool call count) | `15` |
可通过 `config.json` 或对话中的 `/config` 命令修改。
Configurable via `config.json` or the `/config` chat command.
## 压缩策略
## Compression Strategy
当上下文超出限制时,系统会自动执行压缩以释放空间。整个过程分为多个阶段:
When context exceeds limits, the system automatically compresses to free space. The process has multiple stages:
### 1. 工具结果截断
### 1. Tool Result Truncation
在每次决策循环开始前,系统会检查历史轮次中的工具调用结果。超过 **20000 字符** 的工具结果会被截断,仅保留首尾内容和截断说明。当前轮次的工具结果不受影响。
Before each decision loop, the system checks tool call results in historical turns. Results exceeding **20,000 characters** are truncated, keeping only the beginning and end with a truncation notice. Current turn results are not affected.
### 2. 轮次裁剪
### 2. Turn Trimming
当对话轮次超过 `agent_max_context_turns` 时:
When conversation turns exceed `agent_max_context_turns`:
- 裁剪 **最早一半** 的完整轮次(保证工具调用链的完整性)
- 被裁剪的消息会通过 LLM 总结后**写入当天的日级记忆文件**
- LLM 摘要完成后,同时将摘要**注入到保留消息的第一条用户消息开头**,帮助模型在后续对话中保持上下文连贯性
- 摘要注入在后台异步完成,不阻塞当前回复;注入的摘要在下一轮对话时生效
- The **oldest half** of complete turns is trimmed (preserving tool call chain integrity)
- Trimmed messages are summarized by LLM and **written to the daily memory file**
- Once the LLM summary is ready, it is also **injected into the first user message** of the retained context, helping the model maintain conversational continuity
- Summary injection runs asynchronously in the background and takes effect from the next turn onward
### 3. Token 预算裁剪
### 3. Token Budget Trimming
裁剪轮次后,如果 token 数仍超出预算:
After turn trimming, if tokens still exceed the budget:
- **轮次 < 5 时**:对所有轮次进行**文本压缩** — 每轮只保留第一条用户文本和最后一条 Agent 回复,去掉中间的工具调用链
- **轮次 ≥ 5 时**:再次裁剪**前半轮次**,被丢弃内容同样写入记忆并注入上下文摘要
- **Fewer than 5 turns**: All turns undergo **text compression** — each turn keeps only the first user text and last Agent reply, removing intermediate tool call chains
- **5 or more turns**: The **first half** of turns is trimmed again, with discarded content written to memory and a context summary injected
### 4. 溢出应急处理
### 4. Overflow Emergency Handling
当模型 API 返回上下文溢出错误时:
When the model API returns a context overflow error:
1. 先将当前所有消息总结写入记忆
2. 执行激进裁剪(工具结果限制 10K 字符、用户文本限制 10K、最多保留 5 轮)
3. 如果仍然溢出,清空整个对话上下文
1. All current messages are summarized and written to memory
2. Aggressive trimming is applied (tool results limited to 10K chars, user text to 10K, max 5 turns)
3. If still overflowing, the entire conversation context is cleared
## 会话持久化
## Session Persistence
对话消息会持久化到本地数据库,服务重启后自动恢复。恢复策略:
Conversation messages are persisted to a local database, automatically restored after service restart. Restore strategy:
- 恢复最近的 **`max(3, max_context_turns / 6)`** 轮对话
- 只保留每轮的**用户文本和 Agent 最终回复**,不恢复中间工具调用链
- 超过 **30 天**的历史会话自动清理
- Restores the most recent **`max(3, max_context_turns / 6)`** turns
- Only retains each turn's **user text and Agent final reply**, not intermediate tool call chains
- Sessions older than **30 days** are automatically cleaned up
## 操作命令
## Commands
在对话中可以使用以下命令管理上下文:
Use these commands in chat to manage context:
| 命令 | 说明 |
| Command | Description |
| --- | --- |
| `/context` | 查看当前上下文统计(消息数、角色分布、总字符数) |
| `/context clear` | 清空当前会话上下文 |
| `/config agent_max_context_tokens 80000` | 调整上下文 token 预算 |
| `/config agent_max_context_turns 30` | 调整上下文轮次上限 |
| `/context` | View current context statistics (message count, role distribution, total characters) |
| `/context clear` | Clear current session context |
| `/config agent_max_context_tokens 80000` | Adjust context token budget |
| `/config agent_max_context_turns 30` | Adjust context turn limit |
<Tip>
清空上下文后Agent 会"忘记"之前的对话内容。被裁剪和清空的内容如果已经写入长期记忆,仍可通过记忆检索找回。
After clearing context, the Agent "forgets" previous conversation content. Content that was already written to long-term memory can still be retrieved via memory search.
</Tip>

View File

@@ -1,94 +1,90 @@
---
title: 梦境蒸馏
description: Deep Dream — 从对话到永久记忆的自动蒸馏机制
title: Deep Dream
description: Deep Dream — automatic distillation from conversations to permanent memory
---
梦境蒸馏(Deep Dream)是 CowAgent 记忆系统的核心整理机制,负责将分散的天级记忆蒸馏为精炼的长期记忆,并生成梦境日记。
Deep Dream is the core consolidation mechanism of CowAgent's memory system, responsible for distilling scattered daily memories into refined long-term memory and generating dream diaries.
## 记忆流转
## Memory Flow
CowAgent 的记忆从短期到长期经历三个阶段:
CowAgent's memory progresses through three stages from short-term to long-term:
```
对话上下文(短期)→ 天级记忆(中期)→ MEMORY.md长期
Conversation context (short-term) → Daily memory (mid-term) → MEMORY.md (long-term)
```
### 1. 对话 → 天级记忆
### 1. Conversation → Daily Memory
当对话上下文被裁剪或每日定时总结时,系统使用 LLM 将对话内容摘要为关键事件,写入当天的天级记忆文件 `memory/YYYY-MM-DD.md`
When conversation context is trimmed or during the daily scheduled summary, the system uses LLM to summarize conversation content into key events, writing them to the daily memory file `memory/YYYY-MM-DD.md`.
触发时机:
- **上下文裁剪** — 轮次或 token 超限时,裁剪的内容被总结写入
- **每日定时** — 23:55 自动触发全量总结
- **API 溢出** — 紧急保存当前对话摘要
Triggers:
- **Context trimming** — Trimmed content is summarized when turn or token limits are exceeded
- **Daily schedule** — Automatically triggered at 23:55
- **API overflow** — Emergency save of current conversation summary
### 2. 天级记忆 → MEMORY.md蒸馏
### 2. Daily Memory → MEMORY.md (Distillation)
每日总结完成后Deep Dream 自动执行蒸馏:
After the daily summary completes, Deep Dream automatically runs distillation:
1. **读取材料** — 当前 `MEMORY.md` + 当天的天级记忆
2. **LLM 蒸馏** — 去重、合并、修剪、提取新信息
3. **覆写 MEMORY.md** — 输出精炼后的长期记忆
4. **生成梦境日记** — 记录整理过程的发现和洞察
1. **Read materials** — Current `MEMORY.md` + today's daily memory
2. **LLM distillation** — Deduplicate, merge, prune, extract new information
3. **Overwrite MEMORY.md** — Output the refined long-term memory
4. **Generate dream diary** — Record discoveries and insights from the consolidation
### 3. MEMORY.md 的作用
### 3. Role of MEMORY.md
`MEMORY.md` 会被注入到每次对话的系统提示词中,让 Agent 始终了解用户的偏好、决策和关键事实。因此它必须保持精炼——Deep Dream 会控制在约 30 条以内。
`MEMORY.md` is injected into the system prompt for every conversation, keeping the Agent aware of user preferences, decisions, and key facts. Therefore it must stay concise — Deep Dream targets approximately 30 entries or fewer.
## 蒸馏规则
## Distillation Rules
Deep Dream 遵循以下整理规则:
Deep Dream follows these consolidation rules:
| 操作 | 说明 |
| Operation | Description |
| --- | --- |
| **合并提炼** | 含义相近的多条合并为一条高密度表述 |
| **新增萃取** | 从天级记忆中提取偏好、决策、人物、经验等 |
| **冲突更新** | 新信息与旧条目矛盾时,以新信息为准 |
| **清理无效** | 删除临时性记录、空白条目、格式残留 |
| **删除冗余** | 已被更精炼表述涵盖的旧条目删除 |
| **Merge & refine** | Combine similar entries into single high-density statements |
| **Extract new** | Pull preferences, decisions, people, experiences from daily memory |
| **Conflict update** | When new info contradicts old entries, newer info takes precedence |
| **Clean invalid** | Remove temporary records, blank entries, formatting artifacts |
| **Remove redundancy** | Delete old entries already covered by more refined statements |
## 梦境日记
## Dream Diary
每次蒸馏会生成一篇梦境日记,保存在 `memory/dreams/YYYY-MM-DD.md`,用叙事风格记录:
Each distillation generates a dream diary saved at `memory/dreams/YYYY-MM-DD.md`, written in a narrative style recording:
- 发现了哪些重复或矛盾
- 从天级记忆中提取了什么新洞察
- 做了哪些清理和优化
- 整体感受和观察
- Duplications or contradictions found
- New insights extracted from daily memory
- Cleanups and optimizations performed
- Overall observations
梦境日记可在 Web 控制台的「记忆管理 → 梦境日记」tab 中查看。
Dream diaries can be viewed in the Web console under "Memory → Dream Diary" tab.
<Frame>
<img src="https://cdn.link-ai.tech/doc/20260414110032.png" width="800" />
</Frame>
## 手动触发
## Manual Trigger
除了每日自动执行外,也可以在对话中手动触发:
In addition to the automatic daily run, you can manually trigger distillation in chat:
```text
/memory dream [N]
```
- `N`:整理近 N 天的记忆(默认 3 天,最大 30 天)
- 蒸馏在后台异步执行,完成后在对话中通知结果
- Web 端通知包含可点击链接,直接跳转查看 MEMORY.md 和梦境日记
- 无需 Agent 初始化,首次对话前即可使用
<Frame>
<img src="https://cdn.link-ai.tech/doc/20260414120158.png" width="800" />
</Frame>
- `N`: Consolidate the last N days of memory (default 3, max 30)
- Runs asynchronously in the background; you'll be notified in chat when complete
- Web notifications include clickable links to view MEMORY.md and dream diary
- Works without Agent initialization — can be used before the first conversation
<Tip>
首次部署后可以手动执行一次 `/memory dream 30`,将历史天级记忆全量蒸馏到 MEMORY.md
After first deployment, it's recommended to run `/memory dream 30` once to distill all historical daily memories into MEMORY.md.
</Tip>
## 安全机制
## Safety Mechanisms
| 机制 | 说明 |
| Mechanism | Description |
| --- | --- |
| **无新内容跳过** | 没有天级记忆时不执行蒸馏,避免空覆写 |
| **输入去重** | 定时任务中,输入材料未变化时自动跳过 |
| **异步执行** | 蒸馏在后台线程运行,不阻塞对话 |
| **顺序保证** | 定时任务中,天级 flush 全部完成后才启动蒸馏 |
| **禁止编造** | 提示词明确约束只能基于已有材料整理,不得推测或添加 |
| **Skip on no content** | Distillation skipped when no daily memory exists, avoiding empty overwrites |
| **Input dedup** | In scheduled tasks, automatically skipped when input materials haven't changed |
| **Async execution** | Distillation runs in a background thread, never blocking conversation |
| **Sequential guarantee** | In scheduled tasks, daily flush completes before distillation starts |
| **No fabrication** | Prompt explicitly constrains consolidation to existing materials only |

View File

@@ -1,71 +1,71 @@
---
title: 长期记忆
description: CowAgent 的长期记忆系统 — 文件持久化、自动写入与混合检索
title: Long-term Memory
description: CowAgent long-term memory system — file persistence, automatic writing, and hybrid retrieval
---
长期记忆保存在工作空间文件中跨会话持久存在。Agent 在对话中通过检索工具按需加载历史记忆,也会在上下文裁剪时自动将对话摘要写入长期记忆。
Long-term memory is stored in workspace files, persisting across sessions. The Agent loads historical memory on demand via retrieval tools during conversation, and automatically writes conversation summaries to long-term memory when context is trimmed.
<img src="https://cdn.link-ai.tech/doc/memory-architecture-zh.jpeg" alt="Memory Architecture" />
<img src="https://cdn.link-ai.tech/doc/memory-architecture-en.jpg" alt="Memory Architecture" />
## 记忆类型
## Memory Types
### 核心记忆(MEMORY.md
### Core Memory (MEMORY.md)
存储在 `~/cow/MEMORY.md`包含用户的长期偏好、重要决策、关键事实等不会随时间淡化的信息。Agent 可通过工具读写此文件来维护长期知识。
Stored in `~/cow/MEMORY.md`, containing long-term user preferences, important decisions, key facts, and other information that doesn't fade over time. The Agent reads and writes this file via tools to maintain long-term knowledge.
### 日级记忆(memory/YYYY-MM-DD.md
### Daily Memory (memory/YYYY-MM-DD.md)
存储在 `~/cow/memory/` 目录下,按日期命名(如 `2026-03-08.md`),记录每天的对话摘要和关键事件。仅在首次写入时创建,避免生成空文件。
Stored in `~/cow/memory/` directory, named by date (e.g., `2026-03-08.md`), recording daily conversation summaries and key events. Files are only created on first write to avoid generating empty files.
### 梦境日记(memory/dreams/YYYY-MM-DD.md
### Dream Diary (memory/dreams/YYYY-MM-DD.md)
Deep Dream记忆蒸馏过程的副产物记录每次整理的发现、去重合并操作和新洞察。存储在 `~/cow/memory/dreams/` 目录下,按日期命名。
A byproduct of the Deep Dream (memory distillation) process, recording discoveries, deduplication operations, and new insights from each consolidation. Stored in `~/cow/memory/dreams/` directory, named by date.
## 自动写入
## Automatic Writing
Agent 通过以下机制自动将对话内容持久化为长期记忆:
The Agent automatically persists conversation content to long-term memory through the following mechanisms:
- **上下文裁剪时** — 当对话轮次或 token 超出配置上限时,裁剪最早一半的上下文,使用 LLM 将被裁剪的内容总结为关键信息写入当天记忆文件,并将摘要异步注入到保留的上下文中,帮助模型保持对话连贯性
- **每日定时总结** — 每天 23:55 自动触发一次全量总结,防止低活跃日无记忆留存(内容无变化时自动跳过)
- [梦境蒸馏(Deep Dream](/memory/deep-dream) — 每日总结完成后自动执行,将天级记忆蒸馏合并到 MEMORY.md并生成梦境日记
- **API 上下文溢出时** — 当模型 API 返回上下文溢出错误时,紧急保存当前对话摘要
- **On context trimming** — When conversation turns or tokens exceed the configured limit, the oldest half of the context is trimmed, and the discarded content is summarized by LLM into key information and written to the daily memory file. The summary is also asynchronously injected into the retained context for conversational continuity
- **Daily scheduled summary** — A full summary is automatically triggered at 23:55 every day, ensuring memory is preserved even on low-activity days (skipped if content hasn't changed)
- [Deep Dream (memory distillation)](/memory/deep-dream) — Runs automatically after the daily summary, distilling daily memories into MEMORY.md and generating a dream diary
- **On API context overflow** — When the model API returns a context overflow error, the current conversation summary is saved as an emergency measure
所有记忆写入均在后台异步执行LLM 总结 + 文件写入),不阻塞正常对话回复。
All memory writes run asynchronously in a background thread (LLM summarization + file writing), never blocking normal conversation replies.
## 记忆检索
## Memory Retrieval
记忆系统支持混合检索模式:
The memory system supports hybrid retrieval modes:
- **关键词检索** — 基于 FTS5 全文索引匹配历史记忆,支持 BM25 排序
- **向量检索** — 基于 embedding 语义相似度搜索,即使表述不同也能找到相关记忆
- **Keyword retrieval** — FTS5 full-text index matching with BM25 ranking
- **Vector retrieval** — Embedding-based semantic similarity search, finds relevant memory even with different wording
Agent 会在对话中根据需要自动触发记忆检索,将相关历史信息纳入上下文。检索结果按混合评分排序(默认向量权重 0.7、关键词权重 0.3),日级记忆会随时间衰减(半衰期 30 天),核心记忆不衰减。
The Agent automatically triggers memory retrieval during conversation as needed, incorporating relevant historical information into context. Results are ranked by a combined score (default: 0.7 vector weight + 0.3 keyword weight). Daily memory scores decay over time (30-day half-life), while core memory does not decay.
## 相关文件
## Related Files
工作空间(默认 `~/cow`)中与记忆相关的文件:
Files related to memory in the workspace (default `~/cow`):
| 文件 | 说明 |
| File | Description |
| --- | --- |
| `AGENT.md` | Agent 的人格和行为设定 |
| `USER.md` | 用户身份信息和偏好 |
| `RULE.md` | 自定义规则和约束 |
| `MEMORY.md` | 核心记忆(长期) |
| `memory/YYYY-MM-DD.md` | 日级记忆(按需创建) |
| `memory/dreams/YYYY-MM-DD.md` | 梦境日记(Deep Dream 自动生成) |
| `AGENT.md` | Agent personality and behavior settings |
| `USER.md` | User identity information and preferences |
| `RULE.md` | Custom rules and constraints |
| `MEMORY.md` | Core memory (long-term) |
| `memory/YYYY-MM-DD.md` | Daily memory (created on demand) |
| `memory/dreams/YYYY-MM-DD.md` | Dream diary (auto-generated by Deep Dream) |
## Web 控制台
## Web Console
在 Web 控制台的记忆管理页面中,可浏览记忆文件和梦境日记,支持通过 Tab 切换查看:
The memory management page in the Web console allows browsing memory files and dream diaries, with tab switching support:
<Frame>
<img src="https://cdn.link-ai.tech/doc/20260414171014.png" width="800" />
</Frame>
## 相关配置
## Configuration
| 参数 | 说明 | 默认值 |
| Parameter | Description | Default |
| --- | --- | --- |
| `agent_workspace` | 工作空间路径,记忆文件存储在此目录下 | `~/cow` |
| `agent_max_context_tokens` | 最大上下文 token 数,超出时裁剪并总结写入记忆 | `50000` |
| `agent_max_context_turns` | 最大上下文轮次,超出时裁剪并总结写入记忆 | `20` |
| `agent_workspace` | Workspace path, memory files stored under this directory | `~/cow` |
| `agent_max_context_tokens` | Max context tokens; when exceeded, content is trimmed and summarized into memory | `50000` |
| `agent_max_context_turns` | Max context turns; when exceeded, content is trimmed and summarized into memory | `20` |