Compare commits

..

2 Commits

Author SHA1 Message Date
Greyson LaLonde
8025f5bb95 fix: use 'db' instead of '.db' for storage directory 2025-09-18 18:27:37 -04:00
Greyson LaLonde
25ba1620cd fix: change default chromadb storage to project-local directory 2025-09-18 18:15:37 -04:00
3 changed files with 23 additions and 83 deletions

View File

@@ -1,8 +1,5 @@
import logging
import os
import uuid
import webbrowser
from pathlib import Path
from rich.console import Console
from rich.panel import Panel
@@ -17,47 +14,6 @@ from crewai.events.listeners.tracing.utils import (
logger = logging.getLogger(__name__)
def _update_or_create_env_file():
"""Update or create .env file with CREWAI_TRACING_ENABLED=true."""
env_path = Path(".env")
env_content = ""
variable_name = "CREWAI_TRACING_ENABLED"
variable_value = "true"
# Read existing content if file exists
if env_path.exists():
with open(env_path, "r") as f:
env_content = f.read()
# Check if CREWAI_TRACING_ENABLED is already set
lines = env_content.splitlines()
variable_exists = False
updated_lines = []
for line in lines:
if line.strip().startswith(f"{variable_name}="):
# Update existing variable
updated_lines.append(f"{variable_name}={variable_value}")
variable_exists = True
else:
updated_lines.append(line)
# Add variable if it doesn't exist
if not variable_exists:
if updated_lines and not updated_lines[-1].strip():
# If last line is empty, replace it
updated_lines[-1] = f"{variable_name}={variable_value}"
else:
# Add new line and then the variable
updated_lines.append(f"{variable_name}={variable_value}")
# Write updated content
with open(env_path, "w") as f:
f.write("\n".join(updated_lines))
if updated_lines: # Add final newline if there's content
f.write("\n")
class FirstTimeTraceHandler:
"""Handles the first-time user trace collection and display flow."""
@@ -92,12 +48,6 @@ class FirstTimeTraceHandler:
if user_wants_traces:
self._initialize_backend_and_send_events()
# Enable tracing for future runs by updating .env file
try:
_update_or_create_env_file()
except Exception as e:
pass
if self.ephemeral_url:
self._display_ephemeral_trace_link()
@@ -158,14 +108,9 @@ class FirstTimeTraceHandler:
self._gracefully_fail(f"Backend initialization failed: {e}")
def _display_ephemeral_trace_link(self):
"""Display the ephemeral trace link to the user and automatically open browser."""
"""Display the ephemeral trace link to the user."""
console = Console()
try:
webbrowser.open(self.ephemeral_url)
except Exception as e:
pass
panel_content = f"""
🎉 Your First CrewAI Execution Trace is Ready!
@@ -178,8 +123,7 @@ This trace shows:
• Tool usage and results
• LLM calls and responses
✅ Tracing has been enabled for future runs! (CREWAI_TRACING_ENABLED=true added to .env)
You can also add tracing=True to your Crew(tracing=True) / Flow(tracing=True) for more control.
To use traces add tracing=True to your Crew(tracing=True) / Flow(tracing=True)
📝 Note: This link will expire in 24 hours.
""".strip()
@@ -214,8 +158,8 @@ Unfortunately, we couldn't upload them to the server right now, but here's what
• Execution duration: {self.batch_manager.calculate_duration("execution")}ms
• Batch ID: {self.batch_manager.trace_batch_id}
Tracing has been enabled for future runs! (CREWAI_TRACING_ENABLED=true added to .env)
The traces include agent decisions, task execution, and tool usage.
Try running with CREWAI_TRACING_ENABLED=true next time for persistent traces.
""".strip()
panel = Panel(

View File

@@ -138,6 +138,13 @@ class TraceBatchManager:
if not use_ephemeral
else response_data["ephemeral_trace_id"]
)
console = Console()
panel = Panel(
f"✅ Trace batch initialized with session ID: {self.trace_batch_id}",
title="Trace Batch Initialization",
border_style="green",
)
console.print(panel)
else:
logger.warning(
f"Trace batch initialization returned status {response.status_code}. Continuing without tracing."
@@ -251,23 +258,12 @@ class TraceBatchManager:
if self.is_current_batch_ephemeral:
self.ephemeral_trace_url = return_link
# Create a properly formatted message with URL on its own line
message_parts = [
f"✅ Trace batch finalized with session ID: {self.trace_batch_id}",
"",
f"🔗 View here: {return_link}",
]
if access_code:
message_parts.append(f"🔑 Access Code: {access_code}")
panel = Panel(
"\n".join(message_parts),
f"✅ Trace batch finalized with session ID: {self.trace_batch_id}. View here: {return_link} {f', Access Code: {access_code}' if access_code else ''}",
title="Trace Batch Finalization",
border_style="green",
)
if not should_auto_collect_first_time_traces():
console.print(panel)
console.print(panel)
else:
logger.error(

View File

@@ -1,9 +1,8 @@
"""Path management utilities for CrewAI storage and configuration."""
import os
from pathlib import Path
import appdirs
"""Path management utilities for CrewAI storage and configuration."""
def db_storage_path() -> str:
"""Returns the path for SQLite database storage.
@@ -11,21 +10,22 @@ def db_storage_path() -> str:
Returns:
str: Full path to the SQLite database file
"""
app_name = get_project_directory_name()
app_author = "CrewAI"
storage_dir = os.environ.get("CREWAI_STORAGE_DIR")
if storage_dir:
data_dir = Path(storage_dir)
else:
data_dir = Path.cwd() / "db"
data_dir = Path(appdirs.user_data_dir(app_name, app_author))
data_dir.mkdir(parents=True, exist_ok=True)
return str(data_dir)
def get_project_directory_name():
def get_project_directory_name() -> str:
"""Returns the current project directory name."""
project_directory_name = os.environ.get("CREWAI_STORAGE_DIR")
if project_directory_name:
return project_directory_name
else:
cwd = Path.cwd()
project_directory_name = cwd.name
return project_directory_name
cwd = Path.cwd()
return cwd.name