crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] sanitize_scope_name maps non-ASCII names to "unknown", so memory scopes collide

Open Tomato-1101 opened this issue 1 month ago • 2 comments

Description

crewai.memory.utils.sanitize_scope_name replaces every character outside [a-z0-9_-] with - and falls back to "unknown" when nothing is left. Crew, agent role and flow names written in Japanese, Chinese, Korean, Russian, etc. therefore all become unknown, and unrelated crews/agents/flows share one memory scope (/crew/unknown, <root>/agent/unknown, /flow/unknown). Names that are only partly ASCII also collapse, e.g. "Agent 東京" and "Agent 大阪" both become agent.

The function is used for the crew root scope (crew.py), the per-agent scope (base_agent_executor.py) and the flow root scope (flow/runtime/__init__.py).

Steps to Reproduce

  1. from crewai.memory.utils import sanitize_scope_name
  2. sanitize_scope_name("東京支社") and sanitize_scope_name("大阪支社") — both return "unknown".

Expected behavior

Distinct names map to distinct scopes, e.g. /crew/東京支社 and /crew/大阪支社. Characters that are unsafe in a scope path (/, quotes, %, whitespace) should still be replaced with -, and names that contain only ASCII should keep their current output.

Screenshots/Code snippets

from crewai.memory.utils import sanitize_scope_name
print(sanitize_scope_name("東京支社"))      # unknown
print(sanitize_scope_name("大阪支社"))      # unknown
print(sanitize_scope_name("프로젝트"))      # unknown
print(sanitize_scope_name("Agent 東京"))    # agent
print(sanitize_scope_name("Agent 大阪"))    # agent

Operating System

macOS

Python Version

3.13.13

crewAI Version

1.15.27

crewAI Tools Version

1.15.27

Virtual Environment

Venv

Evidence

The existing test TestSanitizeScopeName.test_name_with_unicode pins the current behavior (café_worker -> caf-_worker), i.e. non-ASCII letters are dropped. The regex in lib/crewai/src/crewai/memory/utils.py is re.sub(r"[^a-z0-9_-]", "-", name).

Possible Solution

Keep Unicode letters, numbers and combining marks (checked with unicodedata.category, categories L/N/M, plus _ and -), replace everything else with -, and NFC-normalize the lowercased name so composed and decomposed spellings map to the same scope. Python's \w is not enough because it drops combining marks (Devanagari, Thai), which would still merge names such as "काली" and "किली". Output for ASCII-only names stays identical. I have a patch ready and will open a PR if this is acceptable.

Additional context

Names containing non-ASCII characters would map to a different scope than before (e.g. café_worker was caf-_worker), so memories already saved under the old scope would not be returned by default; I'd document the workaround in the PR.

This issue was prepared with AI assistance; I reviewed and tested the reproduction. Could a maintainer please apply the llm-generated label? (I can't set labels as an external contributor.)

Tomato-1101 avatar Oct 11 '26 10:10 Tomato-1101

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 10 '26 12:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 16 '26 12:11 github-actions[bot]