Fix Windows path length issue in memory storage

- Replace agent.role with agent.id (UUID) in RAGStorage directory naming
- UUIDs are guaranteed short (36 chars) and filesystem-safe
- Remove unused _sanitize_role method since UUIDs don't need sanitization
- Add comprehensive tests for Windows path length scenarios
- Add test case for long agent roles in existing memory tests
- Maintains backward compatibility while fixing Windows 260-char limit

Fixes #3236

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-07-29 23:00:35 +00:00
parent cb522cf500
commit f0949f90dd
3 changed files with 229 additions and 6 deletions

View File

@@ -160,3 +160,41 @@ def test_save_and_search(short_term_memory):
find = short_term_memory.search("test value", score_threshold=0.01)[0]
assert find["context"] == memory.data, "Data value mismatch."
assert find["metadata"]["agent"] == "test_agent", "Agent value mismatch."
def test_memory_with_long_agent_role():
"""Test that memory works correctly with very long agent roles."""
very_long_role = (
"Senior Equity Research Analyst specializing in corporate fundamentals and industry dynamics "
"with expertise in financial modeling, valuation techniques, and market analysis for "
"technology, healthcare, and consumer discretionary sectors, responsible for generating "
"comprehensive investment recommendations and detailed research reports"
)
agent = Agent(
role=very_long_role,
goal="Search relevant data and provide results",
backstory="You are a researcher at a leading tech think tank.",
tools=[],
verbose=True,
)
task = Task(
description="Perform a search on specific topics.",
expected_output="A list of relevant URLs based on the search query.",
agent=agent,
)
memory = ShortTermMemory(crew=Crew(agents=[agent], tasks=[task]))
test_data = "Test memory data for long role agent"
test_metadata = {"task": "test_task"}
memory.save(
value=test_data,
metadata=test_metadata,
agent=very_long_role,
)
results = memory.search("Test memory", score_threshold=0.01)
assert isinstance(results, list), "Search should return a list even with long agent roles"