ImportError: cannot import name ‘create_tool_calling_agent‘ from ‘langchain.agents‘ [duplicate]
·
from langchain.agents import create_tool_calling_agent
prompt = ChatPromptTemplate.from_messages(
[
("system", ""),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"), # 这部分agnet提示符写法是写死的不可以修改
]
)
# 使用 DeepSeek 模型
model = init_chat_model(
model='deepseek-chat', # deepseek-chat表示调用DeepSeek-v3模型
model_provider='deepseek',# 模型提供商写deepseek
api_key="你注册的deepseek api key",
)
# 直接使用`create_tool_calling_agent`创建代理
agent = create_tool_calling_agent(model, tools, prompt)
原因
create_tool_calling_agent 在 LangChain v0.2+ 中被移除,且在最新版本的 langchain.agents 中不再可用。
直接下载
pip install langchain-classic
from langchain_classic.agents import AgentExecutor,create_tool_calling_agent
from langchain.agents import create_agent
# Create agent (replace 'gpt-4o-mini' with your model string or ChatModel instance)
agent = create_agent(
model="gpt-4o-mini", # or ChatOpenAI(model="gpt-4o-mini")
tools=[example_tool],
system_prompt="You are a helpful assistant with access to tools." # Optional
)
result = agent.invoke({"messages": [{"role": "user", "content": "Use the tool!"}]})
更多推荐


所有评论(0)