Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/content/docs/framework/memory/long-term/index.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ ltm = LongTermMemory(backend="viking", app_name="ltm_demo")
| `index` | `str` | `""` | Index/collection name for storing memories. Falls back to `app_name`, then `default_app`. |
| `app_name` | `str` | `""` | The owning application name; used for data isolation and as the `index` fallback. |
| `user_id` | `str` | `""` | **Deprecated**, kept only for backward compatibility. |
| `recall_strategy` | `str` | `"off"` | Recall judgement: with `decision`, the decision model drops memories unrelated to the request. |
| `recall_relevance_threshold` | `float` | `0.5` | Recall relevance threshold: memories judged below it are not returned. |

<Callout type="info">
Vector backends (`local`, `opensearch`, `redis`) embed memories, which requires `pip install "veadk-python[extensions]"` and an embedding model (env prefix `MODEL_EMBEDDING_`, falling back to `MODEL_AGENT_API_KEY`). `viking`, `mem0`, `openviking`, and `tos_context` are managed services and need no local embedding.
Expand Down Expand Up @@ -173,6 +175,17 @@ agent = Agent(
```

To avoid frequent index re-initialization, VeADK exposes `MIN_MESSAGES_THRESHOLD` and `MIN_TIME_THRESHOLD` env vars to tune the save cadence: by default it saves after 10 accumulated events or a 60-second interval; additionally, when you switch `session_id` and start a new turn, VeADK saves the previous session to long-term memory.

The default is `MEMORY_SAVE_STRATEGY=threshold`, the two thresholds above. With `decision`, the configured decision model decides whether the turn holds something durable (a stated preference, fact, decision, or constraint), thresholded by `MEMORY_SAVE_WORTH_THRESHOLD` (default `0.5`):

| Judgement | Behaviour |
| --- | --- |
| Above the threshold | Saved immediately, without waiting for 10 events or 60 seconds |
| Below the threshold | Skipped, and not saved merely because events accumulated |
| Unavailable | Falls back to `MIN_MESSAGES_THRESHOLD` / `MIN_TIME_THRESHOLD` |

A skipped turn does not advance the save cursor, so the next accepted judgement writes those events together: nothing is lost. See the [environment variable reference](/references/configuration/environment-variables) for the decision model variables.
Recall can be judged the same way: with `MEMORY_RECALL_STRATEGY=decision`, `search_memory` rates every returned memory (irrelevant / related but useless / useful background / required) and drops the ones below `MEMORY_RECALL_RELEVANCE_THRESHOLD` (default `0.5`). One judgement covers at most 20 memories, anything beyond that is returned in backend order, and an unavailable judgement keeps every match.
## Auto-save Memory Policy
Configure `auto_save_memory_policy` on `Agent` to decide which events are persisted by automatic long-term-memory saving. If omitted, it is equivalent to `"default"`.
```python
Expand Down
13 changes: 13 additions & 0 deletions docs/content/docs/framework/memory/long-term/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ ltm = LongTermMemory(backend="viking", app_name="ltm_demo")
| `index` | `str` | `""` | 存储记忆所用的索引/集合名。为空时回退到 `app_name`,再为空则用 `default_app`。 |
| `app_name` | `str` | `""` | 拥有该记忆的应用名,常用作数据隔离与 `index` 的回退值。 |
| `user_id` | `str` | `""` | **已废弃**,仅为向后兼容保留。 |
| `recall_strategy` | `str` | `"off"` | 召回判定策略;`decision` 时由判定模型过滤与本次请求无关的记忆。 |
| `recall_relevance_threshold` | `float` | `0.5` | 召回相关度阈值;判定低于该值的记忆不返回。 |

<Callout type="info">
向量类后端(`local`、`opensearch`、`redis`)会对记忆做向量化(embedding),需要安装扩展依赖:`pip install "veadk-python[extensions]"`,并配置 embedding 模型(环境变量前缀 `MODEL_EMBEDDING_`,缺省时复用 `MODEL_AGENT_API_KEY`)。`viking`、`mem0`、`openviking` 与 `tos_context` 是托管服务,无需本地 embedding。
Expand Down Expand Up @@ -173,6 +175,17 @@ agent = Agent(
```

为避免索引被频繁初始化,VeADK 提供 `MIN_MESSAGES_THRESHOLD` 与 `MIN_TIME_THRESHOLD` 两个环境变量自定义保存周期:默认在累计 10 条 event 或间隔 60 秒时触发保存;此外,当切换 `session_id` 并发起新问答时,VeADK 会自动把上一个会话写入长期记忆。

默认保存策略是 `MEMORY_SAVE_STRATEGY=threshold`,即上面的双阈值规则。设置为 `decision` 后,改由已配置的判定模型判断"这一轮是否包含值得长期记住的内容"(陈述过的偏好、事实、决策、约束等),阈值由 `MEMORY_SAVE_WORTH_THRESHOLD` 控制,默认 `0.5`:

| 判定结果 | 行为 |
| --- | --- |
| 通过阈值 | 立即写入,不必等满 10 条 event 或 60 秒 |
| 未通过阈值 | 跳过,不会仅因为攒够条数就写入 |
| 判定不可用 | 回落到 `MIN_MESSAGES_THRESHOLD` / `MIN_TIME_THRESHOLD` |

被跳过的轮次不会推进保存游标,后续判定通过时会把这批 event 一起写入,因此不会丢数据。判定模型的环境变量见 [环境变量参考](/references/configuration/environment-variables)。
检索侧同样可以交给判定模型:`MEMORY_RECALL_STRATEGY=decision` 时,`search_memory` 返回前会逐条给召回片段打相关度(不相关 / 同主题但用不上 / 有用背景 / 必须遵守),低于 `MEMORY_RECALL_RELEVANCE_THRESHOLD`(默认 `0.5`)的会被丢弃;一次判定最多覆盖 20 条,超出的按后端顺序原样保留,判定不可用时保留全部结果。
## 自动保存记忆策略
开发者在 `Agent` 上配置 `auto_save_memory_policy` 来控制自动保存长期记忆时哪些 event 会被写入;不配置时等价于 `"default"`。
```python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Environment variables"
---

Environment variables are the primary configuration method, supplying secrets, connection details, and service addresses. Names are grouped by domain prefix: Volcengine account, models, built-in tools, databases, and observability. Every variable can also be expressed as the equivalent nested structure in `config.yaml`.
Environment variables are the primary configuration method, supplying secrets, connection details, and service addresses. Names are grouped by domain prefix: Volcengine account, models, built-in tools, Harness Extension, decision model, long-term memory, databases, and observability. Every variable can also be expressed as the equivalent nested structure in `config.yaml`.

<Callout type="info">
Supply secrets through environment variables or `config.yaml`. The tables below list common variables by domain; configure only those for the capabilities actually used.
Expand Down Expand Up @@ -76,9 +76,68 @@ Prefix `HARNESS_`, used to attach optional Harness plugins to HarnessApp Runtime
| `HARNESS_MAX_TOOL_RESULT_CHARS` | Single tool-result compaction threshold, default `4000`. |
| `HARNESS_VERIFIER_MODE` | Final-response verification mode, `observe` or `block`; default `observe`. |
| `HARNESS_STORE_PATH` | Optional JSONL event store path; in-memory store is used when unset. |
| `HARNESS_COMPACTION_STRATEGY` | Compaction candidate strategy, `builtin` or `decision`; default `builtin`. |
| `HARNESS_LONG_RUN_STRATEGY` | Long-run steering strategy, `counter` or `decision`; default `counter`. |
| `HARNESS_MODE_STRATEGY` | Context mode-block strategy, `keywords` or `decision`; default `keywords`. |
| `HARNESS_VERIFIER_STRATEGY` | Final-answer verification, `deterministic` or `decision`; default `deterministic`. |
| `HARNESS_COMPACTION_KEEP_THRESHOLD` | Compaction candidates: a candidate is kept when the judged probability is at or above this value; default `0.5`. |
| `HARNESS_LONG_RUN_READY_THRESHOLD` | Long-run steering: guidance is injected when the judged probability of being ready is at or above this value; default `0.5`. |
| `HARNESS_LONG_RUN_MIN_CONFIDENCE` | Smallest confidence a judged steering action needs; below it the plugin keeps the default wording and only the convergence probability counts; default `0` (off). |
| `HARNESS_MODE_DECISION_THRESHOLD` | Context mode blocks: a block is injected when the judged probability is at or above this value; default `0.5`. |
| `HARNESS_VERIFIER_SUPPORT_THRESHOLD` | Final-answer support: the answer fails when the judged support is below this value; default `0.5`. |
| `HARNESS_VERIFIER_OVERCLAIM_THRESHOLD` | Final-answer support: the answer fails when the judged probability of claiming more than the receipts show is at or above this value, even when the verdict was `supported`; default `0.5`. |
| `HARNESS_VERIFIER_MIN_CONFIDENCE` | Smallest confidence a judged verdict needs; below it the judge gives none and the builtin rules decide; default `0` (off). |
| `HARNESS_SKILL_STRATEGY` | Advertised-skills strategy, `all` or `decision`; default `all`. Requires the `skill_prefilter` component. |
| `HARNESS_SKILL_DECISION_THRESHOLD` | Advertised skills: a skill stays in the request when the judged probability of needing it is at or above this value; default `0.5`. |
| `HARNESS_SKILL_MAX_CANDIDATES` | Advertised skills: a list longer than this is not judged, so every skill stays advertised; default `40`. |
| `HARNESS_ROUTING_STRATEGY` | Sub-agent routing strategy, `model` or `decision`; default `model`. Requires the `agent_routing` component. |
| `HARNESS_ROUTING_DECISION_THRESHOLD` | Routing: the judged agent is transferred to only at or above this probability; default `0.5`. |

The `harness_enhance` block maps to these environment variables when deploying a HarnessApp Runtime. Prefer `harness.yaml` or `veadk agentkit invoke` flags for normal developer workflows; use environment variables for platform integration and container runtimes.

## Decision model

Prefix `DECISION_MODEL_`, for attaching the optional judgement model (Jev). It is fully independent of the agent model and serves a small number of judgement points; when it is unconfigured or a call fails, each caller falls back to its built-in rule. Both `enabled` and `api_key` are required for the model to count as configured.

| Variable | Meaning |
| :- | :- |
| `DECISION_MODEL_ENABLED` | Enable the judgement model; accepts `true` / `false`; default `false`. |
| `DECISION_MODEL_PROVIDER` | Service provider, `typesafe` / `openrouter` / `systemone`; default `typesafe`. An unknown value is treated as `typesafe`. |
| `DECISION_MODEL_NAME` | Model name, default `jev-latest`. |
| `DECISION_MODEL_API_BASE` | Service address; defaults per provider when unset, and `/v1/systemone` is appended when missing. |
| `DECISION_MODEL_API_KEY` | Access key; an empty value counts as unconfigured. |
| `DECISION_MODEL_TIMEOUT` | Budget for one judgement in seconds, retries and backoff included; default `5`, ceiling `5`. |
| `DECISION_MODEL_MAX_RETRIES` | Retries per judgement request, default `3`. |
| `DECISION_MODEL_FAILURE_THRESHOLD` | Consecutive failures that trip the circuit breaker, default `3`; `0` disables it. |
| `DECISION_MODEL_COOLDOWN_SECONDS` | Cooldown length in seconds after tripping, default `30`. |

```yaml title="config.yaml"
model:
decision:
enabled: true
provider: openrouter
name: typesafe/jev-1.13
# api_key:
# timeout: 5
```

`model.decision.*` in `config.yaml` expands to `MODEL_DECISION_*`, which is equivalent to `DECISION_MODEL_*`; when both are set, `DECISION_MODEL_*` wins.

When deploying a HarnessApp Runtime, the top-level `decision_model` block in `harness.yaml` maps to this group.

## Long-term memory

Long-term memory has one optional judgement point for saving and one for recall. Both strategies are read at module import time, so a change requires a process restart; an unconfigured or unavailable judgement falls back to the previous behaviour.

| Kind | Variable | Meaning |
| :- | :- | :- |
| Save | `MEMORY_SAVE_STRATEGY` | `threshold` uses the numeric thresholds only; `decision` lets the judgement model decide; default `threshold`. |
| | `MEMORY_SAVE_WORTH_THRESHOLD` | Probability above which a turn is worth remembering, default `0.5`; below it the save is skipped and the cursor does not advance. |
| | `MIN_MESSAGES_THRESHOLD` | Minimum new messages under the `threshold` strategy, default `10`. |
| | `MIN_TIME_THRESHOLD` | Minimum seconds between saves under the `threshold` strategy, default `60`. |
| Recall | `MEMORY_RECALL_STRATEGY` | `off` returns the backend ranking as-is; `decision` rates each memory and drops the low ones; default `off`. |
| | `MEMORY_RECALL_RELEVANCE_THRESHOLD` | Relevance threshold, default `0.5`; memories below it are dropped. Memories the judgement did not rate, and those beyond the 20-item limit, are kept as-is. |

## Databases

Prefix `DATABASE_`, grouped by storage type. Memory and the knowledge base read the matching config based on the selected backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "环境变量"
---

环境变量是最主要的配置方式,提供密钥、连接信息与服务地址。变量名按领域前缀分组:火山引擎账号、模型、内置工具、数据库、可观测各成一类。每个环境变量都能在 `config.yaml` 中以对应层级结构表达,两者等价。
环境变量是最主要的配置方式,提供密钥、连接信息与服务地址。变量名按领域前缀分组:火山引擎账号、模型、内置工具、Harness Extension、决策模型、长记忆、数据库、可观测各成一类。每个环境变量都能在 `config.yaml` 中以对应层级结构表达,两者等价。

<Callout type="info">
密钥统一通过环境变量或 `config.yaml` 提供。下表按领域列出常用变量,仅需配置实际用到的能力对应项。
Expand Down Expand Up @@ -76,9 +76,68 @@ volcengine:
| `HARNESS_MAX_TOOL_RESULT_CHARS` | 单个工具结果压缩阈值,默认 `4000`。 |
| `HARNESS_VERIFIER_MODE` | 最终回答校验模式,`observe` 或 `block`,默认 `observe`。 |
| `HARNESS_STORE_PATH` | 可选 JSONL 事件存储路径;不设置时使用内存存储。 |
| `HARNESS_COMPACTION_STRATEGY` | 工具结果压缩候选策略,`builtin` 或 `decision`,默认 `builtin`。 |
| `HARNESS_LONG_RUN_STRATEGY` | 长任务收尾引导策略,`counter` 或 `decision`,默认 `counter`。 |
| `HARNESS_MODE_STRATEGY` | 上下文模式块策略,`keywords` 或 `decision`,默认 `keywords`。 |
| `HARNESS_VERIFIER_STRATEGY` | 最终回答校验策略,`deterministic` 或 `decision`,默认 `deterministic`。 |
| `HARNESS_COMPACTION_KEEP_THRESHOLD` | 压缩候选保留阈值,默认 `0.5`;判定保留概率低于该值即压缩。 |
| `HARNESS_LONG_RUN_READY_THRESHOLD` | 长任务收尾阈值,默认 `0.5`;判定可收尾概率高于该值即注入引导。 |
| `HARNESS_LONG_RUN_MIN_CONFIDENCE` | 长任务引导动作的最低置信度,默认 `0`(关闭);判定对该动作没把握时只用默认措辞,保留「还没收敛」的信号。 |
| `HARNESS_MODE_DECISION_THRESHOLD` | 上下文模式块阈值,默认 `0.5`;判定概率高于该值即注入对应模式块。 |
| `HARNESS_VERIFIER_SUPPORT_THRESHOLD` | 最终回答支撑度阈值,默认 `0.5`;判定支撑度低于该值即判为失败。 |
| `HARNESS_VERIFIER_OVERCLAIM_THRESHOLD` | 回答超出回执范围的否决阈值,默认 `0.5`;判定概率不低于该值直接判为失败,即使结论是 `supported`。 |
| `HARNESS_VERIFIER_MIN_CONFIDENCE` | 最终回答判定的最低置信度,默认 `0`(关闭);低于该值时不做判定,回落到内置规则。 |
| `HARNESS_SKILL_STRATEGY` | 技能广告策略,`all` 或 `decision`,默认 `all`;需要 `skill_prefilter` 组件。 |
| `HARNESS_SKILL_DECISION_THRESHOLD` | 技能广告阈值,默认 `0.5`;判定需要该技能的概率不低于该值才继续广告。 |
| `HARNESS_SKILL_MAX_CANDIDATES` | 技能候选上限,默认 `40`;技能数量超过该值时不判定,全部照常广告。 |
| `HARNESS_ROUTING_STRATEGY` | 子 Agent 路由策略,`model` 或 `decision`,默认 `model`;需要 `agent_routing` 组件。 |
| `HARNESS_ROUTING_DECISION_THRESHOLD` | 路由阈值,默认 `0.5`;判定概率不低于该值才直接转移。 |

`harness_enhance` 配置块会在 HarnessApp Runtime 部署时映射为这些环境变量。推荐开发者优先通过 `harness.yaml` 或 `veadk agentkit invoke` 参数启用,环境变量适合平台集成和镜像运行时。

## 决策模型

统一前缀 `DECISION_MODEL_`,用于挂载可选的判定模型(Jev)。判定模型与对话模型完全独立,只服务少数判定点;未配置或调用失败时,各调用方回落到原内置规则。`enabled` 与 `api_key` 同时具备才算配置完成。

| 环境变量 | 释义 |
| :- | :- |
| `DECISION_MODEL_ENABLED` | 是否启用判定模型,支持 `true` / `false`,默认 `false`。 |
| `DECISION_MODEL_PROVIDER` | 服务提供方,`typesafe` / `openrouter` / `systemone`,默认 `typesafe`;未知取值按 `typesafe` 处理。 |
| `DECISION_MODEL_NAME` | 模型名称,默认 `jev-latest`。 |
| `DECISION_MODEL_API_BASE` | 服务地址;不设置时按 provider 取默认值,未以 `/v1/systemone` 结尾会自动补上。 |
| `DECISION_MODEL_API_KEY` | 访问密钥;为空视为未配置。 |
| `DECISION_MODEL_TIMEOUT` | 单次判定预算(秒,含重试与退避),默认 `5`,上限 `5`。 |
| `DECISION_MODEL_MAX_RETRIES` | 判定请求重试次数,默认 `3`。 |
| `DECISION_MODEL_FAILURE_THRESHOLD` | 连续失败多少次后熔断,默认 `3`;`0` 表示不熔断。 |
| `DECISION_MODEL_COOLDOWN_SECONDS` | 熔断后的冷却时长(秒),默认 `30`。 |

```yaml title="config.yaml"
model:
decision:
enabled: true
provider: openrouter
name: typesafe/jev-1.13
# api_key:
# timeout: 5
```

`config.yaml` 的 `model.decision.*` 会被展开为 `MODEL_DECISION_*`,与 `DECISION_MODEL_*` 等价;两者同时设置时 `DECISION_MODEL_*` 优先。

HarnessApp Runtime 部署时,`harness.yaml` 的顶层 `decision_model` 块映射为这组变量。

## 长记忆

长记忆的落库与召回各有一个可选判定点。策略都在模块导入时读取,修改后需重启进程;判定不可用或未配置时,回落原有行为。

| 子类 | 环境变量 | 释义 |
| :- | :- | :- |
| 落库判定 | `MEMORY_SAVE_STRATEGY` | `threshold` 只走数值阈值;`decision` 交判定模型决定,默认 `threshold`。 |
| | `MEMORY_SAVE_WORTH_THRESHOLD` | 值得长期记住的概率阈值,默认 `0.5`;低于该值跳过写入、且不推进游标。 |
| | `MIN_MESSAGES_THRESHOLD` | `threshold` 策略下最少新增消息数,默认 `10`。 |
| | `MIN_TIME_THRESHOLD` | `threshold` 策略下两次写入的最小间隔(秒),默认 `60`。 |
| 召回判定 | `MEMORY_RECALL_STRATEGY` | `off` 直接返回后端排序结果;`decision` 逐条评估相关度并丢弃低分项,默认 `off`。 |
| | `MEMORY_RECALL_RELEVANCE_THRESHOLD` | 相关度阈值,默认 `0.5`;低于该值丢弃。未评估到的记忆、以及超出 20 条判定上限的部分原样保留。 |

## 数据库

统一前缀 `DATABASE_`,按存储类型分组。记忆与知识库按所选后端读取对应配置。
Expand Down
Loading
Loading