Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lugfug opened this issue Jul 3, 2024 · 3 comments
Open

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

lugfug opened this issue Jul 3, 2024 · 3 comments

Comments

@lugfug
Copy link

lugfug commented Jul 3, 2024

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
Copy link
Author

lugfug commented Jul 3, 2024

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
Copy link
Collaborator

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
Copy link
Collaborator

@pythonbyte might have context to help on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants