Skip to content

Commit

Permalink
Sanitize agent roles to ensure valid directory names (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
JH427 authored Aug 10, 2024
1 parent dbce944 commit 638a8f0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/crewai/memory/storage/rag_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, type, allow_reset=True, embedder_config=None, crew=None):
os.environ["OPENAI_API_KEY"] = "fake"

agents = crew.agents if crew else []
agents = [agent.role for agent in agents]
agents = [self._sanitize_role(agent.role) for agent in agents]
agents = "_".join(agents)

config = {
Expand Down Expand Up @@ -77,6 +77,12 @@ def __init__(self, type, allow_reset=True, embedder_config=None, crew=None):
self.app.llm = FakeLLM()
if allow_reset:
self.app.reset()

def _sanitize_role(self, role: str) -> str:
"""
Sanitizes agent roles to ensure valid directory names.
"""
return role.replace('\n', '').replace(' ', '_').replace('/', '_')

def save(self, value: Any, metadata: Dict[str, Any]) -> None:
self._generate_embedding(value, metadata)
Expand Down

0 comments on commit 638a8f0

Please sign in to comment.