crewAI: FileReadTool Failing Consistently
I have the following script. I ran this a month ago and it ran fine. Now it’s failing on FileReadTool.
import os, sys
from crewai import Agent, Task, Process, Crew
from langchain_community.llms import Ollama
from crewai_tools import FileReadTool
script_dir = os.path.dirname(__file__)
haiku_filename = "haiku.txt"
file_read_tool = FileReadTool(file_path=f"{script_dir}/haiku.txt")
llm_mixtral = Ollama(model="dolphin-mistral")
writer = Agent(
role="Haiku Expert",
goal="Write Haiku",
backstory="You love Haiku",
verbose=True,
allow_delegation=False,
llm=llm_mixtral
)
reviewer = Agent(
role="Haiku Expert",
goal="Review Haikus",
backstory="You review Haikus",
verbose=True,
allow_delegation=False,
llm=llm_mixtral
)
write = Task(
description="Write a short haiku about the ocean.",
agent=writer,
expected_output="A string containing a short haiku about the ocean saved to a file.",
output_file=haiku_filename
)
review = Task(
description=f"Read a haiku from {haiku_filename} and let me know if it's actually a haiku.",
agent=reviewer,
expected_output=f"A string containing a review of {haiku_filename}.",
tools=[file_read_tool]
)
crew = Crew(
agents=[writer,reviewer],
tasks=[write,review],
verbose=2,
process=Process.sequential
)
result = crew.kickoff()
print("######################")
print(result)
This is the output:
[DEBUG]: == Working Agent: Haiku Expert
[INFO]: == Starting Task: Write a short haiku about the ocean.
> Entering new CrewAgentExecutor chain...
A glistening deep
Endless waves whisper secrets
Life's rhythm, ocean keeps.
Final Answer:
A glistening deep,
Endless waves whisper secrets,
Life's rhythm, ocean keeps.
> Finished chain.
[DEBUG]: == [Haiku Expert] Task output: A glistening deep,
Endless waves whisper secrets,
Life's rhythm, ocean keeps.
[DEBUG]: == Working Agent: Haiku Expert
[INFO]: == Starting Task: Read a haiku from haiku.txt and let me know if it's actually a haiku.
> Entering new CrewAgentExecutor chain...
Thought: To determine if a given text from haiku.txt is actually a haiku, I need to read its content first.
Action: Read a file's content
Action Input: {'file_name': '/Users/ken/devel/ai/agents/crewai-agents-save-a-haiku/haiku.txt'}
A glistening deep,
Endless waves whisper secrets,
Life's rhythm, ocean keeps.
Thought: To assess whether the given text is a haiku or not, I will analyze its structure and content as per the classical haiku rules.
Action: Read a file's content
Action Input: {'file_name': '/Users/ken/devel/ai/agents/crewai-agents-save-a-haiku/haiku.txt'}
I tried reusing the same input, I must stop using this action input. I'll try something else instead.
The output keeps spitting out I tried reusing the same input... continuously. The documentation here mentions file types. If this is an issue with the format, it would be helpful to have some guidance on what the correct format should be.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 26 (6 by maintainers)
I am getting this too with local llms (mistral 7b with recommended modefile), annoyingly it resolves perfectly on the first go, but the agent thinks it hasnt finished and continues on trying different tasks rather than moving onto the next agent. In my case reading a local PDF file - which it does first go - and then thinking it hasnt, so tries various other things firstly using the following message then breaking with errors. so essentially it doesnt realise it has finished its task.
I tried reusing the same input, I must stop using this action input. I’ll try something else instead.
I’m running into this issue when running Groq’s llama3-70b-8192 and when searching using Serper. It seems like the LLM does not particularly like the results, tries to search again with a different query but then it just stays there indefinitely.
@joaomdmoura I can see this happening over here:
Eventually it did manage to get out, although it took 130s when it usually takes 5s.
Actually, you can also control that; you will let the model know if it should keep trying or not. You can do that in your prompting, which is going to be in the
Task descriptionand maybeexpected_outputtoo (if only description didn’t fix the issue alone)Hey there folks, unfortunately smaller models will struggle with using the same tools over. Larger models won’t experience this issue of
Using the same tool with the same arguments.We do use function calling if the model supports it but will do a pass on that just in case. That said I did just merge improvements to the
FIleReadToolthat will be part of a new version we cutting between tomorrow and Monday.If you want to have more strict control over reading files you can use a CrewAI Flow as well, where you could have a function read the file ans pass the content as an input to the crew
I was unable to figure this out and gave up on the problem and using crewai, due to how much time I spent on failing to figure this out unfortunately.
Yes, I haven’t tested yet but I think this has to do something with if the model supports tool calling. I found these 2 links. These list what is supported or not. I will test them today.
https://python.langchain.com/docs/integrations/chat/
https://python.langchain.com/docs/integrations/llms/
Also let us know about any discoveries