Skip to content

fix: Respect custom trained data file during inference#4968

Open
goingforstudying-ctrl wants to merge 1 commit intocrewAIInc:mainfrom
goingforstudying-ctrl:fix/trained-data-file
Open

fix: Respect custom trained data file during inference#4968
goingforstudying-ctrl wants to merge 1 commit intocrewAIInc:mainfrom
goingforstudying-ctrl:fix/trained-data-file

Conversation

@goingforstudying-ctrl
Copy link
Copy Markdown

Summary

When training a crew with a custom filename via train -f <custom_file>.pkl, the crew now correctly loads from that same file during inference, instead of always loading from the hardcoded trained_agents_data.pkl.

Problem

The _use_trained_data() method in Agent always loaded from TRAINED_AGENTS_DATA_FILE constant, ignoring any custom filename provided during training.

Solution

  1. Added _trained_data_file attribute to Crew class to store the custom filename
  2. Store the filename during _setup_for_training()
  3. Pass the stored filename to _use_trained_data() via the utility function
  4. Fall back to default trained_agents_data.pkl when no custom file is specified

Changes

  • src/crewai/crew.py: Add _trained_data_file attribute and store filename during setup
  • src/crewai/agent/core.py: Add trained_data_file parameter to _use_trained_data()
  • src/crewai/agent/utils.py: Retrieve and pass trained_data_file from crew

Backwards Compatibility

Fully backwards compatible. Existing code using default filename continues to work unchanged.

Fixes #4905

When training a crew with a custom filename via `train -f <file>`,
the crew now correctly loads from that same file during inference,
instead of always loading from the hardcoded `trained_agents_data.pkl`.

Changes:
- Add _trained_data_file attribute to Crew class
- Store custom filename during _setup_for_training()
- Pass trained_data_file to _use_trained_data() method
- Use custom file if provided, fall back to default otherwise

Fixes crewAIInc#4905
@goingforstudying-ctrl
Copy link
Copy Markdown
Author

Rebased with latest main. Ready for review!

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

Successfully merging this pull request may close these issues.

Agents always load trained_agents_data.pkl, ignoring custom filename; custom training file not respected on inference

1 participant