mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
* feat: add training logic to agent and crew * feat: add training logic to agent executor * feat: add input parameter to cli command * feat: add utilities for the training logic * feat: polish code, logic and add private variables * feat: add docstring and type hinting to executor * feat: add constant file, add constant to code * feat: fix name of training handler function * feat: remove unused var * feat: change file handler file name * feat: Add training handler file, class and change on the code * feat: fix name error from file * fix: change import to adapt to logic * feat: add training handler test * feat: add tests for file and training_handler * feat: add test for task evaluator function * feat: change text to fit in-screen * feat: add test for train function * feat: add test for agent training_handler function * feat: add test for agent._use_trained_data
32 lines
912 B
Python
32 lines
912 B
Python
from crewai.utilities.file_handler import PickleHandler
|
|
|
|
|
|
class CrewTrainingHandler(PickleHandler):
|
|
def save_trained_data(self, agent_id: str, trained_data: dict) -> None:
|
|
"""
|
|
Save the trained data for a specific agent.
|
|
|
|
Parameters:
|
|
- agent_id (str): The ID of the agent.
|
|
- trained_data (dict): The trained data to be saved.
|
|
"""
|
|
data = self.load()
|
|
data[agent_id] = trained_data
|
|
self.save(data)
|
|
|
|
def append(self, train_iteration: int, agent_id: str, new_data) -> None:
|
|
"""
|
|
Append new data to the existing pickle file.
|
|
|
|
Parameters:
|
|
- new_data (object): The new data to be appended.
|
|
"""
|
|
data = self.load()
|
|
|
|
if agent_id in data:
|
|
data[agent_id][train_iteration] = new_data
|
|
else:
|
|
data[agent_id] = {train_iteration: new_data}
|
|
|
|
self.save(data)
|