mirror of
https://github.com/crewAIInc/crewAI.git
synced 2025-12-16 04:18:35 +00:00
* Cleaned up task execution to now have separate paths for async and sync execution. Updating all kickoff functions to return CrewOutput. WIP. Waiting for Joao feedback on async task execution with task_output * Consistently storing async and sync output for context * outline tests I need to create going forward * Major rehaul of TaskOutput and CrewOutput. Updated all tests to work with new change. Need to add in a few final tricky async tests and add a few more to verify output types on TaskOutput and CrewOutput. * Encountering issues with callback. Need to test on main. WIP * working on tests. WIP * WIP. Figuring out disconnect issue. * Cleaned up logs now that I've isolated the issue to the LLM * more wip. * WIP. It looks like usage metrics has always been broken for async * Update parent crew who is managing for_each loop * Merge in main to bugfix/kickoff-for-each-usage-metrics * Clean up code for review * Add new tests * Final cleanup. Ready for review. * Moving copy functionality from Agent to BaseAgent * Fix renaming issue * Fix linting errors * use BaseAgent instead of Agent where applicable * Fixing missing function. Working on tests. * WIP. Needing team to review change * Fixing issues brought about by merge * WIP: need to fix json encoder * WIP need to fix encoder * WIP * WIP: replay working with async. need to add tests * Implement major fixes from yesterdays group conversation. Now working on tests. * The majority of tasks are working now. Need to fix converter class * Fix final failing test * Fix linting and type-checker issues * Add more tests to fully test CrewOutput and TaskOutput changes * Add in validation for async cannot depend on other async tasks. * WIP: working replay feat fixing inputs, need tests * WIP: core logic of seq and heir for executing tasks added into one * Update validators and tests * better logic for seq and hier * replay working for both seq and hier just need tests * fixed context * added cli command + code cleanup TODO: need better refactoring * refactoring for cleaner code * added better tests * removed todo comments and fixed some tests * fix logging now all tests should pass * cleaner code * ensure replay is delcared when replaying specific tasks * ensure hierarchical works * better typing for stored_outputs and separated task_output_handler * added better tests * added replay feature to crew docs * easier cli command name * fixing changes * using sqllite instead of .json file for logging previous task_outputs * tools fix * added to docs and fixed tests * fixed .db * fixed docs and removed unneeded comments * separating ltm and replay db * fixed printing colors * added how to doc --------- Co-authored-by: Brandon Hancock <brandon@brandonhancock.io>
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
import os
|
|
import pickle
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
class FileHandler:
|
|
"""take care of file operations, currently it only logs messages to a file"""
|
|
|
|
def __init__(self, file_path):
|
|
if isinstance(file_path, bool):
|
|
self._path = os.path.join(os.curdir, "logs.txt")
|
|
elif isinstance(file_path, str):
|
|
self._path = file_path
|
|
else:
|
|
raise ValueError("file_path must be either a boolean or a string.")
|
|
|
|
def log(self, **kwargs):
|
|
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
message = f"{now}: ".join([f"{key}={value}" for key, value in kwargs.items()])
|
|
with open(self._path, "a", encoding="utf-8") as file:
|
|
file.write(message + "\n")
|
|
|
|
|
|
class PickleHandler:
|
|
def __init__(self, file_name: str) -> None:
|
|
"""
|
|
Initialize the PickleHandler with the name of the file where data will be stored.
|
|
The file will be saved in the current directory.
|
|
|
|
Parameters:
|
|
- file_name (str): The name of the file for saving and loading data.
|
|
"""
|
|
self.file_path = os.path.join(os.getcwd(), file_name)
|
|
|
|
def initialize_file(self) -> None:
|
|
"""
|
|
Initialize the file with an empty dictionary if it does not exist or is empty.
|
|
"""
|
|
if not os.path.exists(self.file_path) or os.path.getsize(self.file_path) == 0:
|
|
self.save({}) # Save an empty dictionary to initialize the file
|
|
|
|
def save(self, data) -> None:
|
|
"""
|
|
Save the data to the specified file using pickle.
|
|
|
|
Parameters:
|
|
- data (object): The data to be saved.
|
|
"""
|
|
with open(self.file_path, "wb") as file:
|
|
pickle.dump(data, file)
|
|
|
|
def load(self) -> dict:
|
|
"""
|
|
Load the data from the specified file using pickle.
|
|
|
|
Returns:
|
|
- dict: The data loaded from the file.
|
|
"""
|
|
if not os.path.exists(self.file_path) or os.path.getsize(self.file_path) == 0:
|
|
return {} # Return an empty dictionary if the file does not exist or is empty
|
|
|
|
with open(self.file_path, "rb") as file:
|
|
try:
|
|
return pickle.load(file)
|
|
except EOFError:
|
|
return {} # Return an empty dictionary if the file is empty or corrupted
|
|
except Exception:
|
|
raise # Raise any other exceptions that occur during loading
|