crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

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

Open lugfug opened this issue 1 year ago • 4 comments

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 avatar Jul 03 '24 01:07 lugfug

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

lugfug avatar Jul 03 '24 02:07 lugfug

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

theCyberTech avatar Jul 04 '24 07:07 theCyberTech

@pythonbyte might have context to help on this

joaomdmoura avatar Jul 04 '24 09:07 joaomdmoura

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 Aug 08 '24 14:08 github-actions[bot]

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

github-actions[bot] avatar Dec 12 '24 06:12 github-actions[bot]