09 - 工具(Tools):Function Calling
约 149 字小于 1 分钟
LangChain
2026-03-08
一、什么是工具?
让 LLM 调用外部函数或 API。
二、定义工具
\\python from langchain.tools import Tool
def get_weather(city: str) -> str: return f"{city}今天晴天,25°C"
weather_tool = Tool( name="get_weather", func=get_weather, description="获取指定城市的天气信息" ) \\
三、使用工具
\\python from langchain.agents import initialize_agent
tools = [weather_tool] agent = initialize_agent(tools, llm, agent="zero-shot-react-description")
result = agent.run("北京今天天气怎么样?") \\
四、本课小结
- 工具扩展 LLM 能力
- 支持自定义函数
- Agent 自动选择工具
下一课:10 - Agent 基础