bytedance/deer-flow · error · ValueError
mem0 max_injection_chars must be positive
Error message
mem0 max_injection_chars must be positive
What it means
Raised by Mem0Config.from_backend_config when memory.backend_config.max_injection_chars is <= 0 after int() coercion. This is a hard cap on the injection text returned by get_context; memories that do not fit whole are skipped (truncation happens on entry boundaries). Zero or negative would disable injection in an undocumented way, so it is rejected.
Solutions
- Set max_injection_chars to a positive budget (default 12000)
- To stop injecting memory text, use memory.injection_enabled: false
- If reducing prompt size, pick a small positive value (e.g. 2000) and let whole-entry truncation shed the rest
Example fix
# before (config.yaml)
memory:
backend_config:
max_injection_chars: 0 # must be positive
# after
memory:
injection_enabled: false # or a positive cap:
backend_config:
max_injection_chars: 4000 Defensive patterns
Strategy: validation
Validate before calling
def max_injection_chars_ok(backend_config: dict) -> bool:
try:
return int((backend_config or {}).get("max_injection_chars", 12000)) > 0
except (TypeError, ValueError):
return False Type guard
def is_positive_int(v: object) -> bool:
return isinstance(v, int) and not isinstance(v, bool) and v > 0 Prevention
- Use memory.injection_enabled: false to disable injection, never a zero budget
- Truncation happens on whole-entry boundaries, so small positive budgets degrade gracefully
When it happens
Trigger: max_injection_chars: 0 (attempting to disable injection via the cap), a negative value, or a templated empty default coercing to 0.
Common situations: Trying to turn off memory injection by zeroing the budget instead of memory.injection_enabled: false; decreasing the cap aggressively to save tokens and overshooting to 0.
Related errors
- mem0 score_threshold must be in [0, 1]
- mem0 top_k must be in [1, 1000]
- mem0 allow_insecure_http must be a boolean
- mem0 api_key_env must be a non-empty env var name
- mem0 backend_config has unknown keys
AI-assisted analysis of bytedance/deer-flow@1dd6ba1acb (2026-08-14).
Data as JSON: /api/errors/632cb0df77397541.
Report an issue: GitHub.
Appendix: source
Thrown at backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py:107
score_threshold=float(cfg.get("score_threshold", 0.1)),
max_injection_chars=int(cfg.get("max_injection_chars", 12000)),
timeout_seconds=float(cfg.get("timeout_seconds", 10.0)),
startup_policy=str(cfg.get("startup_policy", "fail_fast")),
read_policy=str(failure_policy.get("read", "fail_open")),
write_policy=str(failure_policy.get("write", "log_and_drop")),
)
if config.startup_policy not in _STARTUP_POLICIES:
raise ValueError(f"mem0 startup_policy must be one of {sorted(_STARTUP_POLICIES)}")
if config.read_policy not in _READ_POLICIES:
raise ValueError(f"mem0 failure_policy.read must be one of {sorted(_READ_POLICIES)}")
if config.write_policy not in _WRITE_POLICIES:
raise ValueError(f"mem0 failure_policy.write must be one of {sorted(_WRITE_POLICIES)}")
if not 1 <= config.top_k <= 1000:
raise ValueError("mem0 top_k must be in [1, 1000]")
if not 0.0 <= config.score_threshold <= 1.0:
raise ValueError("mem0 score_threshold must be in [0, 1]")
if config.max_injection_chars <= 0:
raise ValueError("mem0 max_injection_chars must be positive")
if config.timeout_seconds <= 0:
raise ValueError("mem0 timeout_seconds must be positive")
if not config.api_key_env.strip():
raise ValueError("mem0 api_key_env must be a non-empty env var name")
parsed_base_url = urlsplit(config.base_url)
if parsed_base_url.scheme not in {"http", "https"} or not parsed_base_url.netloc:
raise ValueError("mem0 base_url must be an absolute http:// or https:// URL")
if parsed_base_url.scheme == "http" and not config.allow_insecure_http:
raise ValueError("mem0 base_url must use https:// because it carries the API key; set allow_insecure_http: true only for trusted local development")
return config
def resolve_api_key(self) -> str:
"""Read the API key from the configured environment variable."""
key = os.environ.get(self.api_key_env, "").strip()
if not key:
raise ValueError(f"mem0 API key missing: environment variable {self.api_key_env} is unset or empty")
return key
View on GitHub (pinned to 1dd6ba1acb)