Hello,
I have a tool that reads a file and parses XML. My agent calls this tool, but for some reason, the file path cannot be found. When I run the tool in isolation, it works correctly, it does not work when called by the agent.
class LeadProcessingTool(BaseTool):
name: str = “lead_processing_tool”
description: str = “Extracts key lead details from ADF XML and provides simplified structured data.”
def _parse_xml(self, xml_file: str):
print(f"####################### {txt_file}") ->>>>> This outputs the correct path
import xml.etree.ElementTree as ET
# 📂 Load and parse the XML file
tree = ET.parse(xml_file, parser=ET.XMLParser(encoding="utf-8"))
#tree = ET.parse("lead.xml", parser=ET.XMLParser(encoding="utf-8"))
root = tree.getroot()
# Extract trade-in vehicle details
trade_vehicle = root.find("./vehicle[@interest='trade-in']")
trade_in_value = 0
if trade_vehicle is not None:
trade_in_value = int(trade_vehicle.find("price").text) if trade_vehicle.find("price") is not None else 0
# Extract customer details
customer_data = root.find("./customer/contact")
customer_city = customer_data.find("address/city").text.strip().lower() if customer_data.find("address/city") is not None else ""
customer_state = customer_data.find("address/regioncode").text.strip().lower() if customer_data.find("address/regioncode") is not None else ""
return {
"trade_in_value": trade_in_value,
"customer_city": customer_city,
"customer_state": customer_state,
}
def _run(self, xml_file: str):
return self._parse_xml(xml_file)
Here is the agent:
lead_processing_task = Task(
description=“Extract key attributes of the lead that will be used by agents within your team.”,
expected_output= “A python dictionary with the key value pairs returned by the lead processing tool”,
tools=[lead_processing_tool],
agent=lead_processing_agent,
async_execution=True
)
Here is the error I get from Agent Executor
Entering new CrewAgentExecutor chain…
Thought: I need to process the XML content from the text file to extract the key lead information using the lead_processing_tool.
Action: lead_processing_tool
Action Input: {“xml_file”: “path_to_lead_file.txt”}####################### path_to_lead_file.txt
I encountered an error while trying to use the tool. This was the error: [Errno 2] No such file or directory: ‘path_to_lead_file.txt’.
Tool lead_processing_tool accepts these inputs: lead_processing_tool(xml_file: ‘string’) - Extracts key lead details from ADF XML and provides simplified structured data.
The agent is complaining about access to the file I encountered an error while trying to use the tool. This was the error: [Errno 2] No such file or directory: ‘correct_path_to_file.txt’.
Tool lead_processing_tool accepts these inputs: lead_processing_tool(xml_file: ‘string’) - Extracts key lead details from ADF XML and provides simplified structured data.
Thought: Without the correct file path or a valid example of the XML content, I am unable to use the lead_processing_tool effectively to extract the key information from the automotive lead XML.
Final Answer: Due to the lack of access to the correct file path or the content, I am unable to extract and structure the lead data. Please provide a valid file path or the XML content directly to proceed with processing using the lead_processing_tool.
I have checked the path, it is set up correctly, and as mentioned, the tool works in isolation.
Been stuck on this forever, and cannot figure it out for the life of me. Any help?