Skip to content

fix(memos-local-plugin): add maxTokens to LlmSchema & SkillEvolverSchema#1896

Open
chouti wants to merge 12 commits into
MemTensor:dev-20260604-v2.0.19from
chouti:fix/llm-schema-add-max-tokens
Open

fix(memos-local-plugin): add maxTokens to LlmSchema & SkillEvolverSchema#1896
chouti wants to merge 12 commits into
MemTensor:dev-20260604-v2.0.19from
chouti:fix/llm-schema-add-max-tokens

Conversation

@chouti

@chouti chouti commented Jun 8, 2026

Copy link
Copy Markdown

Problem

Reasoning models (e.g. deepseek-reasoner, o1*, gpt-5-thinking) consume hundreds of tokens on chain-of-thought before emitting JSON content. When llm.json reflection / skillEvolver.crystallize is called with the legacy hard-coded max_tokens: 1024, the response is truncated mid-JSON and the bridge logs llm.json malformed 73+ times in a single reflection cycle.

Result: episodes never close, recoveryReason: "dirty_reward_rescore" piles up, and the MemOS viewer reports bridge.status: disconnected even though the daemon is alive.

Reproduction

llm:
  provider: openai_compatible
  endpoint: https://api.deepseek.com/v1
  model: deepseek-reasoner       # or any reasoning model
  apiKey: sk-...
algorithm:
  lightweightMemory:
    enabled: false               # full self-evolution ON

Start bridge with no override of max_tokens. After ~1 episode:

[bridge] llm.json malformed at 2026-06-08T...Z (attempt 1)
[bridge] llm.json malformed at 2026-06-08T...Z (attempt 2)
... × 73

Direct curl confirms root cause: API returns finish_reason: "length" with truncated content.

Fix

Add maxTokens (default 4_000) to LlmSchema and SkillEvolverSchema. Reasonable budget for reasoning models while still clamping below OpenAI's 32k ceiling.

  • LlmSchema.maxTokens: NumberInRange(4000, 1024, 32768)
  • SkillEvolverSchema.maxTokens: NumberInRange(4000, 1024, 32768)
  • Corresponding defaults in defaults.ts for old configs

TypeBox's Value.Default already preserves user-supplied fields, so the change is backward compatible — old configs without maxTokens get the 4_000 default; new configs can override.

Verification

Before patch:

  • 73 malformed per reflection cycle
  • bridge.status: disconnected

After patch (config unchanged, schema updated):

Files changed

  • apps/memos-local-plugin/core/config/schema.ts (+15 lines, 2 field defs)
  • apps/memos-local-plugin/core/config/defaults.ts (+2 lines, 2 default values)
 apps/memos-local-plugin/core/config/defaults.ts |  2 ++
 apps/memos-local-plugin/core/config/schema.ts   | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

hijzy and others added 12 commits May 25, 2026 15:02
## Summary
- add an OpenClaw runtime lock to block duplicate plugin instances
before tools/hooks register
- fail startup on viewer port conflicts and clean up partial runtime
state
- keep lightweight local memories searchable/listable without an LLM
final filter, while preserving full-mode self-evolution boundaries
- cover runtime locking, duplicate startup, lightweight retrieval,
delayed agent_end recovery, and partial migration behavior

## Tests
- npm test -- --run tests/unit
- npm run lint
- npm run build
- git diff --check --cached
MemTensor#1807)

Automated PR from mem-agent-0520-niu to mem-agent-0520.
…r#1762)

* docs: translate openai_memory_locomo_eval_guide to Chinese

* docs: translate evaluation overview to Chinese
…emTensor#1793)

* fix(mcp): handle empty filter dict in search_memories tool

MCP clients such as Cherry Studio always pass filter:{} in conversation
mode. FastMCP rejects unknown or invalid parameters, returning HTTP 400
"Invalid request parameters". Accept the filter parameter and normalise
an empty dict to None so the call succeeds.

Fixes MemTensor#1718

* docs: translate core API reference docs to English (MemTensor#1693)

* fix: resolve ruff lint/format issues in test_mcp_serve.py
* fix(mcp): handle empty filter dict in search_memories tool

MCP clients such as Cherry Studio always pass filter:{} in conversation
mode. FastMCP rejects unknown or invalid parameters, returning HTTP 400
"Invalid request parameters". Accept the filter parameter and normalise
an empty dict to None so the call succeeds.

Fixes MemTensor#1718

* docs: translate module docs to Chinese (MemTensor#1691)

* fix: resolve ruff lint/format issues in test_mcp_serve.py

---------

Co-authored-by: Jiang <33757498+hijzy@users.noreply.github.com>
## Description

Please include a summary of the change, the problem it solves, the
implementation approach, and relevant context. List any dependencies
required for this change.

Related Issue (Required):  Fixes #issue_number

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (does not change functionality, e.g. code style
improvements, linting)
- [ ] Documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration

- [ ] Unit Test
- [ ] Test Script Or Test Steps (please provide)
- [ ] Pipeline Automated API Test (please provide)

## Checklist

- [ ] I have performed a self-review of my own code | 我已自行检查了自己的代码
- [ ] I have commented my code in hard-to-understand areas |
我已在难以理解的地方对代码进行了注释
- [ ] I have added tests that prove my fix is effective or that my
feature works | 我已添加测试以证明我的修复有效或功能正常
- [ ] I have created related documentation issue/PR in
[MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) (if applicable) |
我已在 [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) 中创建了相关的文档
issue/PR(如果适用)
- [ ] I have linked the issue to this PR (if applicable) | 我已将 issue
链接到此 PR(如果适用)
- [ ] I have mentioned the person who will review this PR | 我已提及将审查此 PR
的人

## Reviewer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed
- [ ] Tests have been provided
## Description

Please include a summary of the change, the problem it solves, the
implementation approach, and relevant context. List any dependencies
required for this change.

Related Issue (Required):  Fixes #issue_number

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (does not change functionality, e.g. code style
improvements, linting)
- [ ] Documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration

- [ ] Unit Test
- [ ] Test Script Or Test Steps (please provide)
- [ ] Pipeline Automated API Test (please provide)

## Checklist

- [ ] I have performed a self-review of my own code | 我已自行检查了自己的代码
- [ ] I have commented my code in hard-to-understand areas |
我已在难以理解的地方对代码进行了注释
- [ ] I have added tests that prove my fix is effective or that my
feature works | 我已添加测试以证明我的修复有效或功能正常
- [ ] I have created related documentation issue/PR in
[MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) (if applicable) |
我已在 [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) 中创建了相关的文档
issue/PR(如果适用)
- [ ] I have linked the issue to this PR (if applicable) | 我已将 issue
链接到此 PR(如果适用)
- [ ] I have mentioned the person who will review this PR | 我已提及将审查此 PR
的人

## Reviewer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed
- [ ] Tests have been provided
Reasoning models (deepseek-reasoner, o1*, gpt-5-thinking) consume
hundreds of tokens on chain-of-thought. The hard-coded 1024 cap on
LLM JSON reflection caused 73+ 'llm.json malformed' errors per
episode, blocking episode closure and disconnecting the bridge.

- Add maxTokens: NumberInRange(4000, 1024, 32768) to LlmSchema
- Add maxTokens: NumberInRange(4000, 1024, 32768) to SkillEvolverSchema
- Add corresponding defaults in defaults.ts (backward compat)

TypeBox's Value.Default preserves user-supplied fields, so old
configs without maxTokens get the 4000 default; new configs can
override.
@Memtensor-AI Memtensor-AI changed the base branch from main to dev-20260604-v2.0.19 June 10, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants