I am executing this code:
file_reader = FileReadTool(file_path=filtered_filename)
the filename orginally was like c:\path\source.cpp and decided oh FIleReadTool might not know .cpp is a text file so I copied it to .txt so now c:\path\source.txt is passed in and the file does exist, but I get exception on tools after execution of this line…any idea what might be going on or how to investage further I am at a dead end.
can you share the appropriate code please, just where you are setting this up
this is the full function the code is called in:
def ai_transform(self):
# Define the Ollama model instance
ollama_llama3 = Ollama(model="crewai-llama3.1")
self.log_message("ai_transform() started")
"""Perform AI transformation."""
# Log the exact value of the destination directory for debugging
self.log_message(f"Checking destination directory: '{self.dest_dir}'")
# Check if the destination directory exists and log the result
if not os.path.exists(self.dest_dir):
self.log_message(f"Destination directory '{self.dest_dir}' does not exist.")
return
else:
self.log_message(f"Destination directory '{self.dest_dir}' exists.")
role = self.role_entry.get().strip()
goal = self.goal_entry.get('1.0', tk.END).strip()
backstory = self.backstory_entry.get('1.0', tk.END).strip()
transformation_instructions = self.transformation_text.get('1.0', tk.END).strip()
if transformation_instructions == "":
self.log_message("Transformation instructions must be given")
return
if not role or not goal or not backstory or not transformation_instructions:
self.log_message("Please provide Role, Goal, Backstory, and Transformation Instructions.")
return
# Skip excluded directories during transformation
try:
for root, dirs, files in os.walk(self.dest_dir):
dirs[:] = [d for d in dirs if os.path.normpath(os.path.join(root, d)) not in self.excluded_directories]
for file in files:
ext = Path(file).suffix.lower()
if ext in self.excluded_extensions:
continue
full_file_path = Path(root) / file
self.log_message(f"Processing file: {full_file_path}")
try:
# Use FileReadTool to read the contents of the file
self.log_message("Use FileReadTool to read the contents of the file");
# Initialize the FileReadTool from crewai_tools
self.log_message("Initialize the FileReadTool from crewai_tools");
filtered_filename, filtered = self.filter_filename(full_file_path)
self.check_file_existence(filtered_filename)
try:
# ... existing code ...
file_reader = FileReadTool(file_path=filtered_filename)
# ... rest of the code ...
except Exception as e:
self.log_message(f"Error FileReadTool file {full_file_path}: {str(e)}")
self.log_message(f"Exception type: {type(e).__name__}")
self.log_message(f"Exception details: {e.args}")
import traceback
self.log_message(f"Traceback: {traceback.format_exc()}")
programmer = Agent(
role=self.role_entry.get().strip(),
goal=self.goal_entry.get('1.0', tk.END).strip(),
backstory=self.backstory_entry.get('1.0', tk.END).strip(),
verbose=True,
allow_delegation=False,
tools=[file_reader],
llm=ollama_llama3
)
task = Task(description=transformation_instructions, agent=programmer)
crew=Crew(
agents=[programmer],
tasks=[task],
verbose=2,
process=Process.sequential
)
transformed_content=crew.kickoff()
self.delete_filtered_filename(filtered_filename, filtered)
if transformed_content!="Agent stopped due to iteration limit or time limit.":
# Use FileWriterTool to write the transformed content back to the file
# self.log_message("Use FileWriterTool to write the transformed content back to the file");
# file_writer._run(Path(str(full_file_path)).name, transformed_content, str(full_file_path)) # Ensure full_file_path is passed as a string
# Open the file in write mode ('w') to overwrite existing contents
with open(full_file_path, 'w') as file:
file.write(transformed_content)
# Log the success of the operation
self.log_message(f"Transformed file: {full_file_path}")
else:
self.log_message(f"{transformed_content}") # error don't put this in the file
except Exception as e:
self.log_message(f"Error transforming file {full_file_path}: {str(e)}")
self.log_message(f"Exception type: {type(e).__name__}")
self.log_message(f"Exception details: {e.args}")
import traceback
self.log_message(f"Traceback: {traceback.format_exc()}")
self.log_message("ai_transform() finished")
except Exception as e:
self.log_message(f"Error during AI Transformation: {e}")
self.log_message(f"Exception type: {type(e).__name__}")
self.log_message(f"Exception details: {e.args}")
import traceback
self.log_message(f"Traceback: {traceback.format_exc()}")
This code has bettter exception diagnostics and gives:
Error transforming file D:\test\AI_computername\computername\computername\computername.cpp: ‘tools’
Exception type: KeyError
Exception details: (‘tools’,)
Traceback: Traceback (most recent call last):
File “D:\test\CrewAI\test.py”, line 433, in ai_transform
programmer = Agent(
^^^^^^
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\pydantic\main.py”, line 171, in init
self.pydantic_validator.validate_python(data, self_instance=self)
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\crewai\agent.py”, line 128, in check_agent_executor
self.set_cache_handler(self.cache_handler)
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\crewai\agent.py”, line 181, in set_cache_handler
self.create_agent_executor()
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\crewai\agent.py”, line 242, in create_agent_executor
self.agent_executor = CrewAgentExecutor(
^^^^^^^^^^^^^^^^^^
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\langchain_core\load\serializable.py”, line 107, in init
super().init(**kwargs)
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\pydantic\v1\main.py”, line 339, in init
values, fields_set, validation_error = validate_model(pydantic_self.class, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\pydantic\v1\main.py”, line 1100, in validate_model
values = validator(cls_, values)
^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\dclark.conda\envs\crewAI_51\Lib\site-packages\langchain\agents\agent.py”, line 944, in validate_tools
tools = values[“tools”]
~~~~~~^^^^^^^^^
KeyError: ‘tools’
got this working, had to do with things like verbose=2 should be verbose=True and had to add an expected_output=" " description my task.
Interesting. Any idea why those 2 things fixed it?
I think they changed that during an update. I remember needing to change their values when I upgraded.
The verbose=2 to verbose=true did indeed change a few releases ago. My question is though any idea why those 2 changes fixed the original problem?
Not too much…I just hooked the source code and the error messages up to perplexity.ai and it told me to make those changes and they seemed reasonable and worked…chatgpt 4.0 was clueless about crewai.