crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
18.81k stars 2.59k forks source link

Read-only file system: '/function/trained_agents_data.pkl' #858

Open lugfug opened 2 months ago

lugfug commented 2 months ago

I'm running crewAI in a Docker container on an AWS Lambda Function, where the only writable directory path is /tmp.

Since the update of crewAI, I'm now getting the following error. OSError: [Errno 30] Read-only file system: '/function/trained_agents_data.pkl'

Is there an official method to set an environment variable for crewAI to define where it should save the trained_agents_data.pkl file?

Thank you for a great product, crewAI is awesome!

lugfug commented 2 months ago

FYI, I created a workaround, code below.

@joaomdmoura maybe you can implement an official method of declaring an environment variable for where the trained_agents_data.pkl may be saved...

Here is my workaround for the error mentioned above.

# Monkey patch the PickleHandler class to use /tmp for the file path
# Import the PickleHandler class from the crewai.utilities.file_handler module
from crewai.utilities.file_handler import PickleHandler

# Store the original __init__ method of the PickleHandler class
# This allows us to call the original method after modifying the file_path
original_init = PickleHandler.__init__

# Define a new __init__ method to replace the original one
def patched_init(self, file_path):
    # Override the file path to use the /tmp directory, which is writable in AWS Lambda
    file_path = "/tmp/trained_agents_data.pkl"
    # Call the original __init__ method with the modified file_path
    original_init(self, file_path)

# Apply the patch by replacing the original __init__ method with the patched version
PickleHandler.__init__ = patched_init

# Import specific classes after environment setup to avoid premature errors.
from crewai import Agent, Task, Crew, Process

from crewai_tools import tool

from crewai_tools import BaseTool
theCyberTech commented 2 months ago

Summary:

Ability to select where the pkl file gets saved when training a crew

@lugfug Feel free to raise a PR with your monkey patch so the Devs can see it

joaomdmoura commented 2 months ago

@pythonbyte might have context to help on this

github-actions[bot] commented 3 weeks ago

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.