Learn how to train your CrewAI agents by giving them feedback early on and get consistent results.
crewai train -n <n_iterations>
, you can specify the number of iterations for the training process.
During training, CrewAI utilizes techniques to optimize the performance of your agents along with human feedback.
This helps the agents improve their understanding, decision-making, and problem-solving abilities.
<n_iterations>
with the desired number of training iterations and <filename>
with the appropriate filename ending with .pkl
.-f
, the output defaults to trained_agents_data.pkl
in the current working directory. You can pass an absolute path to control where the file is written.initial_output
: the agent’s first answerhuman_feedback
: your inline feedback when promptedimproved_output
: the agent’s follow-up answer after feedbacktraining_data.pkl
keyed by the agent’s internal ID and iteration.human_input = true
, so running in a non-interactive environment will block on user input.train(...)
finishes, CrewAI evaluates the collected training data per agent and produces a consolidated result containing:
suggestions
: clear, actionable instructions distilled from your feedback and the difference between initial/improved outputsquality
: a 0–10 score capturing improvementfinal_summary
: a step-by-step set of action items for future taskstrain(...)
(default via CLI is trained_agents_data.pkl
). Entries are keyed by the agent’s role
so they can be applied across sessions.suggestions
and appends them to the task prompt as mandatory instructions. This gives you consistent improvements without changing your agent definitions.training_data.pkl
(ephemeral, per-session):
agent_id -> { iteration_number: { initial_output, human_feedback, improved_output } }
trained_agents_data.pkl
(or your custom filename):
agent_role -> { suggestions: string[], quality: number, final_summary: string }
-f
to set a custom (including absolute) pathn_iterations
) is a positive integer. The code will raise a ValueError
if this condition is not met..pkl
. The code will raise a ValueError
if this condition is not met.trained_agents_data.pkl
located in the current working directory. If you trained to a different filename, either rename it to trained_agents_data.pkl
before running, or adjust the loader in code.crewai train
with -f/--filename
. Absolute paths are supported if you want to save outside the CWD.