Need help with imports

from langchain.tools import Tool

insurance_tool = Tool(
name=“insurance_subagent”,
description=“Use this for insurance-related issues like accidents, claims, and coverage.”,
func=lambda x: insurance_agent.invoke({“input”: x})[“output”]
)

drafting_tool = Tool(
name=“drafting_subagent”,
description=“Use this for drafting emails or structured writing tasks.”,
func=lambda x: drafting_agent.invoke({“input”: x})[“output”]
)

the code above is giving a error as follows

ImportError Traceback (most recent call last)
Cell In[5], line 2
1 # 1. IMPORT WITH CAPITAL ‘T’
----> 2 from langchain.tools import Tool
4 # 2. USE CAPITAL ‘T’ TO DEFINE THE TOOLS
5 insurance_tool = Tool(
6 name=“insurance_subagent”,
7 description=“Use this for insurance-related issues like accidents, claims, and coverage.”,
8 func=lambda x: insurance_agent.invoke({“input”: x})[“output”]
9 )

ImportError: cannot import name ‘Tool’ from ‘langchain.tools’ (C:\Users\Aditya\anaconda3\Lib\site-packages\langchain\tools\_init_.py)

I am new to this and have tried as much abilites and knowledge allows me to , please help

hi @koltoboss

have you tried to import from langchain_core.tools rather than langchain.tools?

yes I did , but didnt work so tried something else and it worked below code is exactly what worked

from langchain.tools import tool

@tool
def insurance_subagent(input: str) → str:
“”“Use this for insurance-related issues like accidents, claims, and coverage.”“”
return insurance_agent.invoke({“input”: input})[“output”]

@tool
def drafting_subagent(input: str) → str:
“”“Use this for drafting emails or structured writing tasks.”“”
return drafting_agent.invoke({“input”: input})[“output”]

1 Like

Ooo yeah, I haven’t noticed you were importing ‘Tool’ and then trying to instantiate it.

Great catch @koltoboss :ok_hand: