why my agent is not using the provided tool even after a proper initialization and assignment of the tool to the agent?
I have provided a clear prompt in the task description how to use the tool and at what instance.
Is it a custom tool?
Yes, it is a custom tool
Make sure your tool name and description are descriptive so that the agent understands why, how and when to use the tool.
If you are subclassing the tool base class it’s also a great idea to have a class for your inputs. That way the agent has all it needs to use the class effcetively.
Can you post your tool code and how it’s being invoked here. Someone might be able to spot why it’s not being used and help you better.
this portal is not allowing me to send.
getting the below error:
New user can put only 2 links
Here is the custom tool:
class CIMFormattingValidator(BaseModel):
neo4j_raw_data: Dict[str, Any] = Field(…,description=‘CIM Json’)
class CIMFormatterTool(BaseTool):
name: str = "CIM Formatter Tool"
description: str = "Tool to format the incoming large CIM json data into a concise manner focusing on relationship of the sensor node"
args_schema: Type[BaseModel] = CIMFormattingValidator
def _run(self, neo4j_raw_data: Dict[str, Any]) -> Dict[str, Any]:
def format_neo4j_data(data, nearby_sections=None, required_columns=None):
nodes = data.get('responseData', {}).get('nodes', [])
relationships = data.get('responseData', {}).get('relationship', {})
near_by_data = data.get('responseData', {}).get('NearByData', {})
id_to_node = {}
for node in nodes:
node_id = node.get('id')
label = node.get('labels', ['Unknown'])[0]
properties = node.get('properties', {})
outgoing = node.get('outgoingAccessNodes', [])
entity_type = label
entity_name = properties.get('name', '')
id_to_node[node_id] = {
"EntityType": entity_type,
"EntityName": entity_name,
"Properties": properties,
"OutgoingIds": outgoing,
"Relationships": []
}
for node_id, node in id_to_node.items():
for out_id in node["OutgoingIds"]:
if isinstance(out_id, str) and "_" in out_id:
try:
ref_type, ref_id_part = out_id.rsplit("_", 1)
ref_id = int(ref_id_part)
ref_node = id_to_node.get(ref_id)
if ref_node:
node["Relationships"].append({
"EntityType": ref_node["EntityType"],
"EntityName": ref_node["EntityName"],
"Properties": ref_node["Properties"]
})
except ValueError:
continue
elif isinstance(out_id, int):
ref_node = id_to_node.get(out_id)
if ref_node:
node["Relationships"].append({
"EntityType": ref_node["EntityType"],
"EntityName": ref_node["EntityName"],
"Properties": ref_node["Properties"]
})
referenced_node_ids = set()
for node in id_to_node.values():
for conn in node["Relationships"]:
entity_name = conn["EntityName"]
for nid, ndata in id_to_node.items():
if ndata["Properties"].get('name', '') == entity_name:
referenced_node_ids.add(nid)
break
final_nodes = []
main_node_id = next(iter(id_to_node))
if main_node_id in id_to_node:
main_node = id_to_node.pop(main_node_id)
final_nodes.append(main_node)
for node_id, node_data in id_to_node.items():
if node_data["Relationships"] or node_id not in referenced_node_ids:
final_nodes.append(node_data)
near_by_section = {}
if nearby_sections:
for section_name in nearby_sections:
section_data = near_by_data.get(section_name)
if section_data:
near_by_section[section_name] = section_data
else:
print(
f"Warning: '{section_name}' section is empty. It will not be included in the output.")
if required_columns:
for node in final_nodes:
entity_name = node["EntityType"]
required_fields = required_columns.get(entity_name, [])
node["Properties"] = {key: node["Properties"].get(
key, None) for key in required_fields}
for key in required_fields:
if key not in node["Properties"]:
print(
f"Warning: Missing required field '{key}' in entity '{entity_name}'")
final_output = {
"Nodes": final_nodes,
**near_by_section
}
return final_output
nearby_sections = ['NearByBuilding', 'NearByPoliceStation']
required_columns = {
'Leak_Detection_Sensor': ['name', 'sensorModel', 'latitude', 'longitude', 'status'],
'Pipe': ['name', 'pipeId', 'diameter', 'material'],
'Tanks': ['tankName', 'capacity', 'currentWaterLevel']
}
formatted_data = format_neo4j_data(
neo4j_raw_data, nearby_sections=nearby_sections, required_columns=required_columns)
print('formatted_data:\n', formatted_data)
print('type of formatted_data:\n', type(formatted_data))
return None