[特殊字符]AI智能体大揭秘:从L1到L5,让Agent帮你写代码,小白秒变大模型大神!

一、理解Agents

通用人工智能(AGI)将是AI的终极形态,几乎已成为业界共识。同样,构建智能体(Agent)则是AI

工程应用当下的“终极形态”。

将 AI 和人类协作的程度类比自动驾驶的不同阶段:

AI 等级(类比自动驾驶)名称特点示例
L1Tool人类完成所有工作,没有任何显性的 AI 辅助目前绝大多数软件产品
L2Chatbot人类完成绝大部分工作。人类向 AI 询问意见,了解信息,AI 提供信息和建议但不直接处理工作初代 ChatGPT 等 Chatbot
L3Copilot人类和 AI 进行协作,工作量相当。AI 根据人类 prompt 完成工作初稿,人类进行目标设定、修改调整,最后确认GitHub Copilot、Midjourney、Jasper 等
L4AgentAI 完成绝大部分工作,人类负责设定目标、提供资源和监督结果。AI 完成任务拆分,工具选择,进度控制,实现目标后自主结束工作AutoGPT 等
L5Species完全无需人类监督,AI 自主拆解目标、寻找资源、选择并使用工具、完成全部工作,人类只需给出目标机器人?

二、Agent与Chain的区别

在Chain中行动序列是硬编码的、固定流程的,像是“线性流水线”,而Agent则采用语言模型作为推理引擎 ,具备一定的自主决策能力,来确定以什么样的顺序采取什么样的行动,像是“拥有大脑的机器工人”。

三、Agent的核心能力/组件

image

模块功能描述示例/说明
大模型(LLM)作为大脑,提供推理、规划和知识理解能力OpenAI()、ChatOpenAI()
记忆(Memory)具备短期记忆(上下文)和长期记忆(向量存储),支持快速知识检索ConversationBufferMemory、ConversationSummaryMemory、ConversationBufferWindowMemory等
工具(Tools)调用外部工具(如API、数据库)的执行单元SearchTool、CalculatorTool
规划(Planning)任务分解、反思与自省框架实现复杂任务处理-
行动(Action)实际执行决策的能力检索、推理、编程
协作通过与其他智能体交互合作,完成更复杂的任务目标-

四、关键组件

工具 Tool

LangChain 提供了广泛的入门工具,但也支持自定义工具,包括自定义描述。

在框架内,每个功能或函数被封装成一个工具(Tools),具有自己的输入、输出及处理方法。

具体使用步骤:

  1. Agent 接收任务后,通过大模型推理选择适合的工具处理任务。
  2. 一旦选定,LangChain将任务输入传递给该工具,工具处理输入生成输出。
  3. 输出经过大模型推理,可用于其他工具的输入或作为最终结果返回给用户。

工具集 Toolkits

在构建Agent时,通常提供给LLM的工具不仅仅只有一两个,而是一组可供选择的工具集(Tool列表),

这样可以让 LLM 在完成任务时有更多的选择。

智能体/代理 Agent

智能体/代理(agent)可以协助我们做出决策,调用相应的 API。底层的实现方式是通过 LLM 来决定

下一步执行什么动作。

代理执行器 AgentExecutor

AgentExecutor本质上是代理的运行时,负责协调智能体的决策和实际的工具执行。

AgentExecutor是⼀个很好的起点,但是当你开始拥有更多定制化的代理时,它就不够灵活了。

为了解决这个问题,我们构建了LangGraph,使其成为这种灵活、⾼度可控的运⾏时。

五、Agent 入门使用


1.Agent、AgentExecutor的创建

环节 1: 创建 Agent环节 2: 创建 AgentExecutor
方式 1: 传统方式使用 AgentType 指定initialize_agent()
方式 2: 通用方式create_xxx_agent() 比如:create_react_agent ()、create_tool_calling_agent ()调用 AgentExecutor () 构造方法

2.Agent的类型

在LangChain中Agent的类型就是为你提供不同的"问题解决姿势"的。

API说明:python.langchain.com/v0.1/docs/modules/agents/agent

Agents的核心类型有两种模式:

  • 方式1:Funcation Call模式
  • 方式2:ReAct 模式

FUNCATION_CALL模式

  • 基于结构化函数调用(如 OpenAI Function Calling)
  • 直接生成工具调用参数(JSON 格式
  • 效率更高,适合工具明确的场景

典型 AgentType:

#第1种:AgentType.OPENAI_FUNCTIONS#第2种:AgentType.OPENAI_MULTI_FUNCTIONS

工作流程示例:

第1步:找到Search工具:{"tool": "Search", "args": {"query": "LangChain最新版本"}}第2步:执行Search工具======================================第1步:找打scrape_website工具:{"tool": "Search", "args": {"target": "LangChain最新版本","url":"要抓取的网站地址"}}第2步:执行scrape_website工具

在工具调用举例[^2]中就使用了这种类型。

ReAct 模式

  • 基于 文本推理 的链式思考(Reasoning + Acting),具备反思和自我纠错能力。
  • 推理(Reasoning):分析当前状态,决定下一步行动
  • 行动(Acting):调用工具并返回结果
  • 通过自然语言描述决策过程
  • 适合需要明确推理步骤的场景。例如智能客服、问答系统、任务执行等。

典型 AgentType:

#第1种:零样本推理(可以在没有预先训练的情况下尝试解决新的问题)AgentType.ZERO_SHOT_REACT_DESCRIPTION#第2种:无记忆对话AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION#第3种:带记忆对话AgentType.CONVERSATIONAL_REACT_DESCRIPTION

工作流程示例:

问题:我想要查询xxx思考:我需要先搜索最新信息 → 行动:调用Search工具 → 观察:获得3个结果 →思考:需要抓取第一个链接 → 行动:调用scrape_website工具...→ 观察:获得工具结果最后:获取结果

Agent两种典型类型对比表

特性Function Call 模式ReAct 模式
底层机制结构化函数调用自然语言推理
输出格式JSON / 结构化数据自由文本
适合场景需要高效工具调用需要解释决策过程
典型延迟较低(直接参数化调用)较高(需生成完整文本)
LLM 要求需支持函数调用(如 gpt-4)通用模型即可

六、AgentExecutor创建方式

传统方式:initialize_agent()

特点:

  • 内置一些标准化模板(如ZERO_SHOT_REACT_DESCRIPTION
  • Agent的创建:使用AgentType

优点:快速上手(3行代码完成配置)

缺点:定制化能力较弱(如提示词固定)

代码片段:

from langchain.agents import initialize_agent#第1步:创建AgentExecutoragent_executor = initialize_agent( llm=llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, tools=[search_tool], verbose=True)#第2步:执行agent_executor.invoke({"xxxx"})

通用方式:AgentExecutor构造方法

  • 特点:
  • Agent 的创建:使用create_xxx_agent
  • 优点:
  • 可自定义提示词(如从远程 hub 获取或本地自定义)
  • 清晰分离 Agent 逻辑与执行逻辑
  • 缺点:
  • 需要更多代码
  • 需理解底层组件关系
  • 代码片段:
prompt = hub.pull("hwchase17/react")tools = [search_tool]#第1步: 创建Agent实例agent = create_react_agent(    llm=llm,    prompt=prompt,    tools=tools)#第2步: 创建AgentExecutor实例agent_executor = AgentExecutor(    agent=agent,    tools=tools)#第3步: 执行agent_executor.invoke({"input": "xxxxx"})

七、Agent中工具的使用

传统方式

案例1:单工具使用
  • 需求:今天北京的天气怎么样?
  • 使用 Tavily 搜索工具
  • Tavily 的搜索 API 是一个专门为人工智能 Agent (或 LLM) 构建的搜索引擎,可以快速提供实时、准确和真实的结果。
  • LangChain 中有一个内置工具,可以轻松使用 Tavily 搜索引擎 作为工具。
  • TAVILY_API_KEY 申请:https://tavily.com/,注册账号并登录,创建 API 密钥。

方式1:ReAct模式

AgentType是 ZERO_SHOT_REACT_DESCRIPTION

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :demo01.py@Author  :zxb@Date    :2025/12/10 09:44"""import osfrom dotenv import load_dotenvfrom langchain.agents import initialize_agent, AgentTypefrom langchain_community.tools import TavilySearchResultsfrom langchain_core.tools import Toolfrom langchain_openai import ChatOpenAI# 设置api秘钥load_dotenv()# 初始化搜索工具search = TavilySearchResults(max_results=3)# 创建Tool实例search_tool = Tool(    name="Search",    func=search.run,    description="搜索工具,输入搜索内容,返回搜索结果")# 初始化LLMllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 创建AgentExecutoragent_executor = initialize_agent(    llm=llm,    tools=[search_tool],    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,    verbose=True)# 测试查询query = "今天xx的天气怎么样?"result = agent_executor.invoke(query)print(f"查询结果: {result}")

输出如下:

> Entering new AgentExecutor chain...我需要查询今天xx的天气情况。Action: SearchAction Input: xx今天天气Observation: [{'title': 'xx今天天气预报查询', 'url': 'https://tianqi.2345.com/xiamen1d/59134.htm', 'content': '高温\n 低温\n\n| 排名 | 城市 | 今天气温 |\n\n| 1 | 三沙海南 | 25~28 ° |\n| 2 | 三亚海南 | 23~28 ° |\n| 3 | 东方海南 | 21~27 ° |\n| 4 | 保亭海南 | 20~27 ° |\n| 5 | 西双版纳云南 | 13~27 ° |\n| 6 | 陵水海南 | 22~26 ° |\n| 7 | 昌江海南 | 21~26 ° |\n| 8 | 乐东海南 | 20~26 ° |\n| 9 | 崇左广西 | 17~26 ° |\n| 10 | 漳州福建 | 15~26 ° |\n\n查看更多> [...] 现在 西风 2级 良\n 09:00 西风 1级 优\n 10:00 西南风 1级 优\n 11:00 东南风 1级 优\n 12:00 东南风 2级 优\n 13:00 东南风 1级 优\n 14:00 东南风 1级 优\n 15:00 东南风 2级 优\n 16:00 东南风 2级 优\n 17:00 东南风 2级 优\n 18:00 东风 2级 优\n 19:00 东风 2级 良\n 20:00 东北风 2级 优\n 21:00 东北风 1级 优\n 22:00 东北风 1级 优\n 23:00 西北风 2级 优\n 12/11 西风 2级 优\n 01:00 西南风 2级 优\n 02:00 西风 2级 优\n 03:00 西风 2级 优\n 04:00 西风 2级 优\n 05:00 西北风 2级 优\n 06:00 西北风 2级 良\n 07:00 西北风 2级 良\n\n# xx市今天空气质量\n\n中国环境保护部:发布\n\n更多>\n\n55 良\n\n出去走走放松心情,感受下美好大自然吧。\n\n 不用佩戴口罩\n 适宜运动\n 适宜外出\n 适宜开窗\n\n##### 主要污染物\n\n击败全国87%的城市, 查看榜单>\n\n PM2.5 [...] 北京)\n 上海)\n 杭州)\n 广州)\n 深圳)\n 武汉)\n 南京)\n 济南)\n 郑州)\n 苏州)\n 天津)\n 重庆)\n\n确定 取消\n\n手机看天气\n\n扫码下载app,天气随时看\n\n今天天气 明天天气 一周天气 15天天气\n\n实时天气:08:30发布\n\n17° 多云\n\n 良 55\n\n今天:16-23° 晴\n\n昨天:15~20° 阴转晴 历史天气>\n\n 西风 2级 湿度 74% 紫外线 弱 气压 1018hPa\n\n24小时天气预报\n\n日出 06:40 日落 17:20', 'score': 0.99580115}, {'title': 'xx市天气预报', 'url': 'https://tianqi.moji.com/weather/china/fujian/xiamen', 'content': '随时随地 想查就查\n\n首页 天气 下载 资讯 关于墨迹\n\n 天气\n 中国\n 福建省\n xx市\n\nxx市, 福建省, 中国\n\n 37 优\n\n20 晴 今天14:20更新\n\n湿度 56% 北风4级\n\n今日天气提示 略微偏凉,还是蛮舒适的。\n\nWindows 下载\n\n预报\n\n 7天预报\n 10天预报\n 15天预报\n\n 今天\n 多云\n 16° / 21°\n 东北风 3级\n 37 优\n\n 明天\n 晴\n 16° / 24°\n 东南风 3级\n 60 良\n\n 后天\n 晴\n 16° / 24°\n 东北风 3级\n 55 良\n\n24小时预报\n\n 温度\n 风力\n\n30° 20° 10° 0°\n\n29°\n\n30° 20° 10° 0°\n\n29°\n\n## 生活指数 [...] 同安区\n 方特梦幻王国\n 湖里公园\n xx奥林匹克博物馆\n 英雄三岛战地观光园\n 思明区\n 海沧区\n 湖里区\n\n附近景点 更多\n\n 鼓浪屿\n 海天堂构\n 黄荣远堂\n 日光岩\n 翠丰SPA温泉度假村\n 胡里山炮台\n 嘉庚公园\n 日月谷温泉公园\n\n天气日历\n\n 星期日\n 星期一\n 星期二\n 星期三\n 星期四\n 星期五\n 星期六\n\n 01 \n\n  16/24°\n\n  东北风  3级\n 02 \n\n  18/26°\n\n  东风  3级\n 03 \n\n  12/20°\n\n  东北风  3级\n 04 \n\n  13/19°\n\n  东北风  4级\n 05 \n\n  14/20°\n\n  东风  3级\n 06 \n\n  15/22°\n\n  东风  3级\n 07 \n\n  16/24°\n\n  东南风  3级\n 08 \n\n  16/24°\n\n  东北风  3级\n 09 \n\n  16/21°\n\n  东北风  3级\n 10 \n\n  16/24°\n\n  东南风  3级\n 11 \n\n  16/24°\n\n  东北风  3级\n 12 \n\n  17/22°\n\n  东北风  3级\n 13 \n\n  15/23°', 'score': 0.987375}, {'title': 'xx市十二月天气和平均温度(中国) - Weather Spark', 'url': 'https://zh.weatherspark.com/m/132161/12/%E5%8E%A6%E9%97%A8%E5%B8%82%E3%80%81%E4%B8%AD%E5%9C%8B%E7%9A%8412%E6%9C%88%E5%B9%B3%E5%9D%87%E5%A4%A9%E6%B0%A3', 'content': '| ---   春季夏季秋季冬季   ---   1月2月3月4月5月6月7月8月9月10月11月12月   ---   12345678910111213141516171819202122232425262728293031 xx市 十二月的天气 中国 每日高温下降 3°C,从21°C到18°C,极少低于14°C或超过25°C。  每日低温下降 4°C,从15°C到11°C,极少低于7°C或超过18°C。  作为参考,在xx市,7月17日是一年中最热的一天,气温通常在26°C到32°C之间;而1月27日是一年中最冷的一天,气温在10°C到16°C之间。  十二月 xx市的平均高温和低温 冬季  链接  下载  比较  平均值:123456789101112月  历史:2025年2024年2023年2022年2021年  用第25-75和第10-90百分位区间表示的每日平均高温(红线)和低温(蓝线)。 细虚线是对应的平均感知气温。  下图向您显示以十二月为中心的季度每小时平均气温的简要特征。 横轴表示天,纵轴表示一天中的小时,颜色是该小时和天的平均气温。  十二月 [...] xx市的平均小时气温 冬季  链接  下载  比较  平均值:123456789101112月  历史:2025年2024年2023年2022年2021年  极冷   -9°C   冰冻   0°C   很冷   7°C   寒冷   13°C   凉爽   18°C   舒适   24°C   暖和   29°C   热   35°C   酷热  每小时平均温度,加以数带着色。 阴影叠加表示夜晚和民用曙光/暮光。  美国、德克萨斯州、Jamaica Beach(距此13,094公里)和黎巴嫩、贝鲁特(7,884公里)是同xx市气温最相似的遥远的海外城市(查看对比)。  © OpenStreetMap contributors  将xx市与另一城市相比较:  云彩  十二月 xx市出现逐渐减少的云量,整个月份天空多云或大部分多云的时间从24%减少至20%。 多云或大部分多云气况的最低机率是19%,出现在 12月27日。  一个月中最晴朗的一天是12月27日,此时出现晴朗、大部分晴朗或部分多云气况的机率是81%。 [...] 本报告根据1980年1月1日到2016年12月31日的历史小时天气报告统计分析和模型重建描述xx市的典型天气。 温度和露点 我们的网络中只有一个气象站Xiamen Gaoqi International Airport适合替代xx市的历史气温和露点记录。  在距离xx市 9公里的地点(比我们的150公里阈值更近),该气象站被视为足够近,可用作我们的气温和露点记录的主要来源。  气象站记录依据国际标准大气压和MERRA-2卫星时代再分析中两个地点之间存在的相对变化,对气象站与xx市之间的海拔差异进行纠正。  请注意,气象站记录本身可能已经使用其他临近的气象站或MERRA-2再分析回填。 其他数据 所有与太阳位置(例如,日出和日落)相关的数据均使用Jean Meeus编著的《天文算法》第二版一书中的天文公式计算。  所有其他天气数据(包括云层分布、降水、风速和风向、日辐射通量)来自美国国家航空航天局(NASA)的MERRA-2现代回顾分析。 此项再分析将各种广域测量综合进一个最先进的全球气象模式中,在一个50公里的坐标方格中重建全球天气小时史。', 'score': 0.98087597}]Thought:根据搜索结果,今天xx的天气为多云,气温在16°C到21°C之间,风力为东北风3级,空气质量为优,指数为37。此外,今天xx的湿度为74%,紫外线较弱,气压为1018hPa。  Final Answer: 今天xx的天气是多云,气温16°C到21°C,东北风3级,空气质量优,指数为37。> Finished chain.查询结果: {'input': '今天xx的天气怎么样?', 'output': '今天xx的天气是多云,气温16°C到21°C,东北风3级,空气质量优,指数为37。'}

拓展:上述程序中tool的设置也可以简化为:

# 初始化搜索工具search = TavilySearchResults(max_results=3)# 创建 AgentExecutoragent_executor = initialize_agent( tools=[search], llm=llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)

方式2:FUNCATION_CALL模式

AgentType是 OPENAI_FUNCTIONS

提示:只需要修改前面代码中的initialize_agent中的agent参数值

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :demo02.py@Author  :zxb@Date    :2025/12/10 09:44"""import osfrom dotenv import load_dotenvfrom langchain.agents import initialize_agent, AgentTypefrom langchain_community.tools import TavilySearchResultsfrom langchain_core.tools import Toolfrom langchain_openai import ChatOpenAI# 设置api秘钥load_dotenv()# 初始化搜索工具search = TavilySearchResults(max_results=3)# 创建Tool实例search_tool = Tool(    name="Search",    func=search.run,    description="搜索工具,输入搜索内容,返回搜索结果")# 初始化LLMllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 创建AgentExecutoragent_executor = initialize_agent(    llm=llm,    tools=[search_tool],    agent=AgentType.OPENAI_FUNCTIONS,    verbose=True)# 测试查询query = "今天xx的天气怎么样?"result = agent_executor.invoke(query)print(f"查询结果: {result}")

输出如下:

> Entering new AgentExecutor chain...Invoking: `Search` with `xx天气`[{'title': 'xx市的氣候、每月天氣和平均溫度(中國) - Weather Spark', 'url': 'https://tw.weatherspark.com/y/132161/%E5%8E%A6%E9%97%A8%E5%B8%82%E3%80%81%E4%B8%AD%E5%9C%8B%E7%9A%84%E5%85%A8%E5%B9%B4%E5%B9%B3%E5%9D%87%E5%A4%A9%E6%B0%A3', 'content': '| ---   春季夏季秋季冬季   ---   1月2月3月4月5月6月7月8月9月10月11月12月 xx市的全年氣候和平均天氣 中國 xx市夏季熱、沈悶、潮濕和陰天;冬季涼爽、有風和晴時多雲。 全年溫度一般在 10°C 至 32°C 的範圍内,很少低於 7°C 或高於 35°C。  根據旅游得分,到訪xx市進行溫暖天氣活動的最佳時間是10月上旬至11月下旬。  xx市的氣候 比較  歷史:2025年2024年2023年2022年2021年2020年2019年2018年2017年  xx市的每月天氣。 點擊每個圖表以取得更多資訊。  xx市的平均溫度  熱季從 6月9日至 10月1日持續 3.8 個月,平均每日高溫在 29°C 以上。 xx市一年中最熱的月份是 7月,平均高溫為 32°C,平均低溫為 26°C。  涼季從 12月12日至 3月21日持續 3.3 個月,平均每日高溫在 19°C 以下。 xx市一年中最冷的月份是 1月,平均低溫為 11°C,平均高溫為 17°C。  xx市的平均高溫和低溫 連結  下載  比較 [...] 熱   35°C   酷熱  平均每小時溫度,以色彩編碼成帶。 陰影叠加表示夜晚和民用曙暮光。  Jamaica Beach、德克萨斯州、美國(距此 13,094 公里)和贝鲁特、黎巴嫩 (7,884 公里)是溫度最接近xx市(檢視比較)的遙遠的外國地點。  © OpenStreetMap contributors  將xx市與另一個城市相比較:  雲量  xx市全年天空為雲所覆蓋的平均百分比有極端的季節變化。  xx市一年中較爲晴朗的部分從 9月23日左右開始,持續 6.7 個月,在 4月14日左右結束。  xx市一年中最晴朗的月份是 12月,天氣為晴、晴時多雲或多雲的時間平均為 79%。  一年中較爲多雲的部分從 4月14日左右開始,持續 5.3 個月,在 9月23日左右結束。  xx市一年中最多雲的月份是 6月,天氣為陰天或多雲時晴的時間平均為 79%。  xx市的雲量類別 連結  下載  比較  歷史:2025年2024年2023年2022年2021年2020年2019年2018年2017年  0%   晴   20%   晴時多雲   40%   多雲   60% [...] |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  | | 天數 | 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月 |  ---  ---  ---  ---  ---  ---  | 雨 | 3.9 天 | 6.2 天 | 9.3 天 | 11.3 天 | 12.7 天 | 12.0 天 | 9.1 天 | 10.9 天 | 7.7 天 | 2.4 天 | 2.9 天 | 3.1 天 | |  雨量  爲了展示各月變化而非僅展示月度總量,我們展示了以一年中的每一天爲中心的滑動 31 天纍積雨量。 xx市的每月雨量有極端的季節變化。  xx市的全年降雨。 xx市降雨最多的月份是 6月,平均降雨量為 171 公釐。  xx市降雨最少的月份是 12月,平均降雨量為 32 公釐。  xx市的月平均雨量 連結  下載  比較', 'score': 0.84027237}, {'title': '【xx天气预报】xx天气预报7天,10天,15天_全国天气网', 'url': 'https://tianqi.so.com/weather/101230201', 'content': '# 全国天气网\n\n 首页\n 国内天气\n 空气质量\n 国际天气\n 景点天气\n 天气新闻\n 专业天气\n\n收藏\n\nxx\n\n[切换]\n\n当前时间:2025-12-08周一19:32\n\n空气 优东风 5级\n\n 今天 (12-08)\n\n  东北风 3-5级\n\n 明天 (12-09)\n\n  东北风 3-5级\n\n 周三 (12-10)\n\n  晴\n\n  持续无风向 微风\n\n 周四 (12-11)\n\n  晴转多云\n\n  16/24℃\n\n  东北风 3-5级\n\n 周五 (12-12)\n\n  东北风 4-5级\n\n 周六 (12-13)\n\n  15/22℃\n\n  东北风 3-5级\n\n 周日 (12-14)\n\n  多云\n\n  12/19℃\n\n  东北风 3-5级\n\n 周一 (12-15)\n\n  晴转多云\n\n  10/17℃\n\n  东北风 4-5级\n\n 周二 (12-16)\n\n  晴\n\n  10/19℃\n\n  东北风 微风\n\n 周三 (12-17)\n\n  晴\n\n  13/19℃\n\n  东北风 3-5级\n\n 周四 (12-18)\n\n  晴\n\n  10/18℃\n\n  东北风 4-5级\n\n 周五 (12-19)\n\n  晴 [...] xx市气象台2025年12月08日18时52分发布大风黄色预警信号:预计未来12小时我市及沿海东北风风力逐渐增大,xx内海、各大桥最大可达5~6级、阵风7~8级,xx外海、高海拔山区最大可达6~7级、阵风8级,崇武到东山沿海最大可达6~7级、阵风8~9级。请注意防范。当前大风预警信号状态:黄色(思明、湖里、集美、翔安、海沧)、无(同安)。\n\n### 当前天气信息\n\n天气:晴 18℃\n\n体感:18℃\n\n风向:东风\n\n风力:5级\n\n气压:1004\n\n湿度:50%\n\n日出:06:39\n\n日落:17:19\n\n### 空气质量\n\n43\n\n优\n\n0\n\n50\n\n100\n\n150\n\n200\n\n300\n\n500\n\n空气很棒,快出门呼吸新鲜空气吧。\n\n无需戴口罩\n\n适宜外出\n\n适宜开窗\n\n关闭净化器\n\n### 主要污染物\n\nPM2.5\n\n19优\n\nPM10\n\n44优\n\nO3\n\n96优\n\nNO2\n\n15优\n\nSO2\n\n2优\n\n17时\n\n20时\n\n23时\n\n02时\n\n05时\n\n08时\n\n11时\n\n14时\n\n东风\n\n5级\n\n东北风\n\n3-5级\n\n东北风\n\n4-5级\n\n东北风\n\n4-5级\n\n东北风\n\n4-5级 [...] 11/18℃\n\n  东风 3-5级\n\n 周六 (12-20)\n\n  晴转多云\n\n  13/20℃\n\n  东风 微风\n\n 周日 (12-21)\n\n  阴\n\n  16/21℃\n\n  东风 3-5级\n\n 周一 (12-22)\n\n  多云转晴\n\n  14/20℃\n\n  东风 微风\n\n45日天气\n\n15日天气\n\n今日天气\n\n明日天气\n\nxx市气象台2025年12月08日18时52分发布大风黄色预警信号:预计未来12小时我市及沿海东北风风力逐渐增大,xx内海、各大桥最大可达5~6级、阵风7~8级,xx外海、高海拔山区最大可达6~7级、阵风8级,崇武到东山沿海最大可达6~7级、阵风8~9级。请注意防范。当前大风预警信号状态:黄色(思明、湖里、集美、翔安、海沧)、无(同安)。', 'score': 0.82560414}, {'title': 'xx市天气预报', 'url': 'https://tianqi.moji.com/weather/china/fujian/xiamen', 'content': '同安区\n 方特梦幻王国\n 湖里公园\n xx奥林匹克博物馆\n 英雄三岛战地观光园\n 思明区\n 海沧区\n 湖里区\n\n附近景点 更多\n\n 鼓浪屿\n 海天堂构\n 黄荣远堂\n 日光岩\n 翠丰SPA温泉度假村\n 胡里山炮台\n 嘉庚公园\n 日月谷温泉公园\n\n天气日历\n\n 星期日\n 星期一\n 星期二\n 星期三\n 星期四\n 星期五\n 星期六\n\n 01 \n\n  16/24°\n\n  东北风  3级\n 02 \n\n  18/26°\n\n  东风  3级\n 03 \n\n  12/20°\n\n  东北风  3级\n 04 \n\n  13/19°\n\n  东北风  4级\n 05 \n\n  14/20°\n\n  东风  3级\n 06 \n\n  15/22°\n\n  东风  3级\n 07 \n\n  16/24°\n\n  东南风  3级\n 08 \n\n  16/24°\n\n  东北风  3级\n 09 \n\n  16/21°\n\n  东北风  3级\n 10 \n\n  16/24°\n\n  东南风  3级\n 11 \n\n  16/24°\n\n  东北风  3级\n 12 \n\n  17/22°\n\n  东北风  3级\n 13 \n\n  15/23° [...] 随时随地 想查就查\n\n首页 天气 下载 资讯 关于墨迹\n\n 天气\n 中国\n 福建省\n xx市\n\nxx市, 福建省, 中国\n\n 37 优\n\n20 晴 今天14:20更新\n\n湿度 56% 北风4级\n\n今日天气提示 略微偏凉,还是蛮舒适的。\n\nWindows 下载\n\n预报\n\n 7天预报\n 10天预报\n 15天预报\n\n 今天\n 多云\n 16° / 21°\n 东北风 3级\n 37 优\n\n 明天\n 晴\n 16° / 24°\n 东南风 3级\n 60 良\n\n 后天\n 晴\n 16° / 24°\n 东北风 3级\n 55 良\n\n24小时预报\n\n 温度\n 风力\n\n30° 20° 10° 0°\n\n29°\n\n30° 20° 10° 0°\n\n29°\n\n## 生活指数', 'score': 0.78552294}]今天xx的天气是晴天,气温在18°C左右,体感温度也是18°C。风向为东风,风力为5级。空气质量良好,适合外出。如果你需要更详细的天气预报或未来几天的天气情况,可以查看[这里](https://tianqi.so.com/weather/101230201)。> Finished chain.查询结果: {'input': '今天xx的天气怎么样?', 'output': '今天xx的天气是晴天,气温在18°C左右,体感温度也是18°C。风向为东风,风力为5级。空气质量良好,适合外出。\n\n如果你需要更详细的天气预报或未来几天的天气情况,可以查看[这里](https://tianqi.so.com/weather/101230201)。'}

Tips

目前预计只有OpenAI自家模型支持此操作。

二者对比:ZERO_SHOT_REACT_DESCRIPTION和OPENAI_FUNCTIONS

对比维度ZERO_SHOT_REACT_DESCRIPTIONOPENAI_FUNCTIONS
底层机制模型生成文本指令,系统解析后调用工具模型直接返回 JSON 格式工具调用
执行效率🐢 较低(需多轮文本交互)⬆️ 更高(单步完成)
输出可读性直接显示人类可读的思考过程需查看结构化日志
工具参数处理依赖模型文本描述准确性自动匹配工具参数结构
兼容模型所有文本生成模型仅 GPT-4/Claude 3 等新模型
复杂任务表现可能因文本解析失败出错更可靠(结构化保证)

案例2:多工具使用

需求:

  • 计算特斯拉当前股价是多少?
  • 比去年上涨了百分之几?(提示:调用PythonREPL实例的run方法)

多个(两个)工具的选择

方式1:ReAct 模式

AgentType是 ZERO_SHOT_REACT_DESCRIPTION

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :demo01.py@Author  :zxb@Date    :2025/12/10 13:03"""import osfrom dotenv import load_dotenvfrom langchain.agents import initialize_agent, AgentTypefrom langchain_community.tools import TavilySearchResultsfrom langchain_core.tools import Toolfrom langchain_experimental.utilities.python import PythonREPLfrom langchain_openai import ChatOpenAIload_dotenv()# 定义搜索工具search = TavilySearchResults(max_results=3)search_tool = Tool(    name="Search",    func=search.run,    description="用于搜索互联网上的信息,特别是股票价格和新闻")# 定义计算工具python_repl = PythonREPL()calc_tool = Tool(    name="Calculator",    func=python_repl.run,    description="用于执行数学计算,例如百分比变化")# 定义llmllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 创建AgentExecutoragent_executor = initialize_agent(    tools=[search_tool, calc_tool],    llm=llm,    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,    verbose=True)query = "特斯拉今天的股票价格如何?比上周的变化是多少?"result = agent_executor.invoke(query)print(f"查询结果: {result}")

输出如下:

> Entering new AgentExecutor chain...F:\Project\JetbrainsProjects\PycharmProject\LangChain-tutorial\chapter06-agent\traditional_use\mulitple_tool_use\demo01.py:45: LangChainDeprecationWarning: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool-calling, persistence of state, and human-in-the-loop workflows. For details, refer to the `LangGraph documentation <https://langchain-ai.github.io/langgraph/>`_ as well as guides for `Migrating from AgentExecutor <https://python.langchain.com/docs/how_to/migrate_agent/>`_ and LangGraph's `Pre-built ReAct agent <https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/>`_.  agent_executor = initialize_agent(我需要先搜索特斯拉今天的股票价格,然后搜索上周的股票价格,再计算两者的百分比变化。Action: SearchAction Input: 特斯拉今天的股票价格Observation: [{'title': '特斯拉(TSLA)股票历史数据 - 英为财情', 'url': 'https://cn.investing.com/equities/tesla-motors-historical-data', 'content': '最高:\n\n458.87\n\n涨跌幅:\n\n2.04\n\n平均:\n\n423.07\n\n差价:\n\n76.09\n\n最低:\n\n382.78\n\n## 常见问题\n\n### 特斯拉(TSLA)的历史股价表现如何?\n\n过去一年间,特斯拉 (TSLA)实现了16.90%的涨跌幅,其52周股价波动区间为214.25至488.54。\n\n### 特斯拉(TSLA)的平均日成交量是多少?\n\n特斯拉(TSLA)的平均日成交量为56,427,522。\n\n### 特斯拉进行过多少次拆股?\n\n特斯拉共进行过2次拆股。\n\n### 特斯拉(TSLA)的每日股价波动范围是多少?\n\n今日特斯拉(TSLA)的股价波动范围为451.66至458.87元。\n\n### 今日特斯拉的开盘价是多少?\n\n今日特斯拉的开盘价为453.03。\n\n查找股票交易商\n\n上证指数\n\n3,902.81\n\n+27.01\n\n+0.70%\n\n富时中国A50指数\n\n15,237.44\n\n+88.13\n\n+0.58%\n\n香港恒生指数")\n\n26,085.08\n\n+149.18\n\n+0.58%\n\n日经225")\n\n50,491.87\n\n-536.55\n\n-1.05% [...] | 名称 | 最新价 | 看涨 | 公允价值 |\n ---  --- |\n| Aa Aaaaa | 53.49 | +51.79% |  |\n| Aaaaaaaaaaaa | 0.969 | +50.47% |  |\n| Aaaaaaaa Aaaaa | 44.48 | +50.13% |  |\n| Aaaaaaaa Aaaa | 11.31 | +48.91% |  |\n| Aaaa Aaaa Aaaaa Aa | 5.91 | +48.25% |  |\n| Aaaaaa Aaaaaaaa A | 7.52 | +45.18% |  |\n| Aaaaaa | 15.15 | +45.01% |  | [...] 货币USD\n\nTSLAPro分析报告(英文)\n\n455.00\n\n+0.47(+0.10%)\n\n闭盘·\n\n盘后\n\n454.61-0.39(-0.09%)\n\n·\n\n公允价格\n\n根据折现现金流、同类公司估值倍数以及股息贴现模型等估值方法,预估的股票真实价格。\n\n解锁估值功能\n\n当日幅度\n\n451.66458.87\n\n52 周范围\n\n214.25488.54\n\n## TSLA历史数据\n\n免费获取特斯拉(TSLA)股票历史数据,用于特斯拉股票投资参考。此历史数据包括近期和往年特斯拉(TSLA)股票的历史行情,每日股价和价格涨跌走势图表。选择日期范围,可按每日、每周或每月周期查询特斯拉股票的收盘价、开盘价、最高价、最低价、价格变动、涨跌幅和股票收益率。\n\n时间范围\n\n1日\n\n下载\n\n2025-11-07 - 2025-12-07', 'score': 0.890761}, {'title': 'TSLA股價— 特斯拉圖表 - TradingView', 'url': 'https://tw.tradingview.com/symbols/NASDAQ-TSLA/', 'content': 'Image 112\n\n自動駕駛汽車股票:未來的汽車\n\n −5.71%  今日 \n\n +102.56%  1-年 \n\nImage 113\n\n美國股票:全美英雄\n\n −2.18%  今日 \n\n −3.00%  1-年 \n\nImage 114\n\n華爾街賭場股:猩球崛起\n\n −5.25%  今日 \n\n +30.23%  1-年 \n\n查看所有精選股\n\n常見問題\n\n今天 Tesla, Inc.的股價是多少?\n\nTSLA目前的價格是 413.49 USD — 在過去24小時內下跌了−5.06%。 在圖表上更密切地關注 Tesla, Inc.股票價格表現。\n\nTesla, Inc.股票代碼是什麼?\n\n根據交易所的不同,股票代碼可能會有所不同。例如:在 NASDAQ交易所 Tesla, Inc.股票以股票代號 TSLA進行交易。\n\nTesla, Inc.的股價在上漲嗎?\n\n與前一週相比,TSLA的股價下跌了−5.76%, 月變動為 19.17%的上漲, 在過去一年中,Tesla, Inc.表現出 71.00%的上漲。\n\nTSLA的股票預測為何?', 'score': 0.8732259}, {'title': 'Tesla, Inc. (TSLA) Stock Historical Prices & Data - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/history/', 'content': '| Nov 5, 2025 | 452.05 | 466.33 | 440.71 | 462.07 | 462.07 | 85,573,000 |\n| Nov 4, 2025 | 454.46 | 460.22 | 443.60 | 444.26 | 444.26 | 87,756,600 |\n| Nov 3, 2025 | 455.99 | 474.07 | 453.80 | 468.37 | 468.37 | 84,595,200 |\n| Oct 31, 2025 | 446.75 | 458.00 | 443.69 | 456.56 | 456.56 | 83,135,800 |\n| Oct 30, 2025 | 451.05 | 455.06 | 439.61 | 440.10 | 440.10 | 72,447,900 |\n| Oct 29, 2025 | 462.50 | 465.70 | 452.65 | 461.51 | 461.51 | 67,983,500 | [...] | Dec 2, 2025 | 430.81 | 436.80 | 422.12 | 429.24 | 429.24 | 69,336,600 |\n| Dec 1, 2025 | 425.32 | 433.66 | 425.29 | 430.14 | 430.14 | 57,463,600 |\n| Nov 28, 2025 | 426.59 | 432.93 | 426.20 | 430.17 | 430.17 | 36,252,900 |\n| Nov 26, 2025 | 423.95 | 426.94 | 416.89 | 426.58 | 426.58 | 63,463,000 |\n| Nov 25, 2025 | 414.42 | 420.48 | 405.95 | 419.40 | 419.40 | 71,915,600 |\n| Nov 24, 2025 | 402.17 | 421.72 | 401.09 | 417.78 | 417.78 | 96,806,400 | [...] | Aug 28, 2025 | 350.91 | 353.55 | 340.26 | 345.98 | 345.98 | 67,903,200 |\n| Aug 27, 2025 | 351.94 | 355.39 | 349.16 | 349.60 | 349.60 | 65,519,000 |\n| Aug 26, 2025 | 344.93 | 351.90 | 343.72 | 351.67 | 351.67 | 76,651,600 |\n| Aug 25, 2025 | 338.90 | 349.53 | 335.03 | 346.60 | 346.60 | 86,670,000 |\n| Aug 22, 2025 | 321.66 | 340.25 | 319.69 | 340.01 | 340.01 | 94,016,300 |\n| Aug 21, 2025 | 322.08 | 324.90 | 318.68 | 320.11 | 320.11 | 55,744,400 |', 'score': 0.8674071}]Thought:从搜索结果中,特斯拉今天的股票价格是 413.49 USD,比上周下跌了 -5.76%。  Final Answer: 特斯拉今天的股票价格是 413.49 USD,比上周下跌了 5.76%。> Finished chain.查询结果: {'input': '特斯拉今天的股票价格如何?比上周的变化是多少?', 'output': '特斯拉今天的股票价格是 413.49 USD,比上周下跌了 5.76%。'}

方式2:FUNCATION_CALL模式

AgentType是 FUNCATION_CALL

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :demo02.py@Author  :zxb@Date    :2025/12/10 13:03"""import osfrom dotenv import load_dotenvfrom langchain.agents import initialize_agent, AgentTypefrom langchain_community.tools import TavilySearchResultsfrom langchain_core.tools import Toolfrom langchain_experimental.utilities.python import PythonREPLfrom langchain_openai import ChatOpenAIload_dotenv()# 定义搜索工具search = TavilySearchResults(max_results=3)search_tool = Tool(    name="Search",    func=search.run,    description="用于搜索互联网上的信息,特别是股票价格和新闻")# 定义计算工具python_repl = PythonREPL()calc_tool = Tool(    name="Calculator",    func=python_repl.run,    description="用于执行数学计算,例如百分比变化")# 定义llmllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 创建AgentExecutoragent_executor = initialize_agent(    tools=[search_tool, calc_tool],    llm=llm,    agent=AgentType.OPENAI_MULTI_FUNCTIONS,    verbose=True)query = "特斯拉今天的股票价格如何?比上周的变化是多少?"result = agent_executor.invoke(query)print(f"查询结果: {result}")

输出如下:

> Entering new AgentExecutor chain...F:\Project\JetbrainsProjects\PycharmProject\LangChain-tutorial\chapter06-agent\traditional_use\mulitple_tool_use\demo02.py:45: LangChainDeprecationWarning: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool-calling, persistence of state, and human-in-the-loop workflows. For details, refer to the `LangGraph documentation <https://langchain-ai.github.io/langgraph/>`_ as well as guides for `Migrating from AgentExecutor <https://python.langchain.com/docs/how_to/migrate_agent/>`_ and LangGraph's `Pre-built ReAct agent <https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/>`_.  agent_executor = initialize_agent(Invoking: `Search` with `{'tool_input': 'Tesla stock price today'}`[{'title': "TSLA Stock Price | Tesla Inc. Stock Quote (U.S.: Nasdaq ... Tesla Inc (TSLA) Stock Price & News - Google Finance Tesla Stock Price Today | NASDAQ: TSLA Live - Investing.com TSLA: Tesla Inc - Stock Price, Quote and News - CNBC Tesla (TSLA) Stock Price & Overview Is Elon Musk's Pay Package Really $1 Trillion? And What Could It Mea… Morgan Stanley cuts Tesla 's stock rating from 'buy' for the first time i… Is Elon Musk's Pay Package Really $1 Trillion? And What Could It Mea… Morgan Stanley cuts Tesla 's stock rating from 'buy' for the first time i… Tesla (TSLA) Stock Price, News & Analysis - MarketBeat", 'url': 'https://www.marketwatch.com/investing/stock/tsla', 'content': '2 days ago · TSLA | Complete Tesla Inc. stock news by MarketWatch . View real-time stock prices and stock quotes for a full financial overview. Get the latest Tesla Inc (TSLA) real-time quote , historical performance, charts, and other financial information to help you make more informed trading and investment decisions. Financial overview for TSLA stock (Tesla Inc) including price , charts, technical analysis, Tesla stock price history, Tesla reports and more. Get Tesla Inc (TSLA:NASDAQ) real-time stock quotes, news , price and financial information from CNBC. 4 days ago · A detailed overview of Tesla, Inc. (TSLA ) stock , including real-time price , chart, key statistics, news , and more. How much should a Tesla share price be? Using Tesla\'s current shares outstanding (3.5 billion) and the market cap target suggests a share price of about $2,400 . That\'s nearly 6 times the current share price, which is extremely ambitious. (Note that 424 million shares multiplied by $2,400 gets you to over $1 trillion.) Why did Tesla stock fall on Monday? Tesla stock fell on Monday after shares were downgraded by Morgan Stanley . Analyst Andrew Percoco moved it from a "buy" to a "hold" rating. It is the first downgrade Tesla has received from Morgan Stanley since June 2023. How much is Tesla worth? At the time of this writing, Tesla\'s share price is around $420, making the value of 424 million shares $178 billion as I write this. It\'s hardly peanuts, but that\'s well short of the $1 trillion figure. Another key detail is that Tesla\'s market capitalization will need to reach $8.5 trillion for milestone 12 to be met. Is Tesla a \'buy\' or \'hold\' stock? Analyst Andrew Percoco moved it from a "buy" to a " hold " rating. It is the first downgrade Tesla has received from Morgan Stanley since June 2023. Tesla stock got a downgrade on Monday, sending it tumbling as much as 4% as Morgan Stanley lowered its recommendation for the first time since 2023. 2 days ago · Should You Buy or Sell Tesla Stock ? Get The Latest TSLA Stock Analysis, Price Target, Earnings Estimates, Headlines, and Short Interest at MarketBeat.', 'score': 0.84215075}, {'title': 'Tesla , Inc. ( TSLA ) Stock Price , News, Quote & History - Yahoo …', 'url': 'https://finance.yahoo.com/quote/TSLA/', 'content': 'While the weekly insider-sentiment data from Vickers Stock Research is noticeably improved from what was seen over the past two weeks, insiders clearly remain cautious. And while improved, the sentiment data is still far from the readings below 2.00 that are needed for a bullish call. By the number, the current Total (all exchanges) One-Week Sell/Buy Ratio is 6.02 versus 11.45 last week and 17.32 the week before that. The NYSE One-Week Sell/Buy Ratio is 3.40 versus 8.15 last week and 27.25 the [...] Oops, something went wrong\n\n### News\n\n### Life\n\n### Entertainment\n\n### Finance\n\n### Sports\n\n### New on Yahoo\n\n# Yahoo Finance\n\nWe are experiencing some temporary issues. The market data on this page is currently delayed.\n\n# Tesla, Inc. (TSLA)\n\nThis price reflects trading activity during the overnight session on the Blue Ocean ATS, available 8 PM to 4 AM ET, Sunday through Thursday, when regular markets are closed.\n\n### 3.71%\n\n### 3.64%\n\n### 44.26%\n\n### 10.23%\n\n### 14.21%\n\n### 120.94% [...] ### 1-Year Return\n\n### 3-Year Return\n\n### 5-Year Return\n\n### Earnings Trends: TSLA\n\n### Earnings Per Share\n\n### Revenue vs. Earnings\n\nQ4\n\nFY24\n\nQ1\n\nFY25\n\nQ2\n\nFY25\n\nQ3\n\nFY25\n\n### Analyst Insights: TSLA\n\n### Top Analyst\n\n### Analyst Price Targets\n\n### Analyst Recommendations\n\n### Latest Rating\n\n### Statistics: TSLA\n\n### Valuation Measures\n\nMarket Cap\n\n1.48T\n\nEnterprise Value\n\n1.45T\n\nTrailing P/E\n\n307.01\n\nForward P/E\n\n200.00\n\nPEG Ratio (5yr expected)\n\n8.89\n\nPrice/Sales (ttm)\n\n16.40', 'score': 0.7373288}, {'title': 'Tesla, Inc. (TSLA) Stock Historical Prices & Data', 'url': 'https://finance.yahoo.com/quote/TSLA/history/', 'content': 'Discover historical prices for TSLA stock on Yahoo Finance. View daily ... Dec 10, 2024 - Dec 10, 2025. Historical Prices. Daily. Currency in USD. Download', 'score': 0.54492307}]Invoking: `Search` with `{'tool_input': 'Tesla stock price last week'}`[{'title': 'Tesla, Inc. (TSLA) Stock Historical Prices & Data - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/history/', 'content': 'Volume. Dec 9, 2025, 437.61, 452.39, 435.70, 445.17, 445.17, 60,868,108. Dec 8, 2025, 447.45, 449.75, 435.25, 439.58, 439.58, 69,165,800.', 'score': 0.8548847}, {'title': 'TSLA Stock Price — Tesla Chart - TradingView', 'url': 'https://www.tradingview.com/symbols/NASDAQ-TSLA/', 'content': 'Tesla, Inc.\nTesla, Inc.\nTesla, Inc.\n\n# Tesla, Inc.\n\n## Chart\ufeff\n\n## Key facts today\n\n## Upcoming earnings\ufeff\n\n## Key stats\ufeff\n\n## Employees\ufeff\n\n## About Tesla, Inc.\n\n## Related stocks\n\n## Financials\ufeff\n\n## Community forum\ufeff\n\nSee all minds \n\n## News\ufeff\n\n## Ideas\ufeff\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nSee all ideas \n\n## Technicals\ufeff\n\n## Analyst rating\ufeff\n\n## Seasonals\ufeff\n\n## Highest yielding bonds\ufeff\n\nSee all TSLA bonds [...] ## ETFs\ufeff\n\nExplore more ETFs \n\n## Sparks\ufeff\n\nSee all sparks \n\n## Frequently Asked Questions\n\nSelect market data provided by ICE Data Services. Select reference data provided by FactSet. Copyright © 2025 FactSet Research Systems Inc.Copyright © 2025, American Bankers Association. CUSIP Database provided by FactSet Research Systems Inc. All rights reserved. SEC fillings and other documents provided by Quartr.© 2025 TradingView, Inc.\n\nLook First\nLook First', 'score': 0.56985265}, {'title': 'Tesla, Inc. Common Stock (TSLA) Historical Quotes - Nasdaq', 'url': 'https://www.nasdaq.com/market-activity/stocks/tsla/historical', 'content': '### We couldn’t find any results matching your search.\n\nPlease try using other words for your search or explore other sections of the website for relevant information.\n\n### We’re sorry, we are currently experiencing some issues, please try again later.\n\nOur team is working diligently to resolve the issue. Thank you for your patience and understanding.\n\n### TSLA\n\n## Breadcrumb\n\n# Tesla, Inc. Common Stock (TSLA) Historical Quotes\n\n# \n\n|  | [...] |  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n\nInformation\n\n## Latest TSLA News\n\nInfo icon\n\nThis data feed is not available at this time.\n\n|  |\n\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n\n### Symbol Search\n\n### Recently Viewed\n\n|  |\n\n|  |\n|  |\n|  |\n\n### Trending Indexes\n\n|  |\n\n|  |  |  |  |\n|  |  |  |  |\n\n© 2025, Nasdaq, Inc. All Rights Reserved.\n\nTo add symbols: [...] Type a symbol or company name. When the symbol you want to add appears, add it to My Quotes by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.\n\nThese symbols will be available throughout the site during your session.\n\n Type a symbol or company name. When the symbol you want to add appears, add it to My Quotes by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.', 'score': 0.24508502}]Invoking: `Search` with `{'tool_input': 'Tesla stock price today'}`[{'title': 'Tesla, Inc. (TSLA) Stock Price, News, Quote & History - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/', 'content': 'While the weekly insider-sentiment data from Vickers Stock Research is noticeably improved from what was seen over the past two weeks, insiders clearly remain cautious. And while improved, the sentiment data is still far from the readings below 2.00 that are needed for a bullish call. By the number, the current Total (all exchanges) One-Week Sell/Buy Ratio is 6.02 versus 11.45 last week and 17.32 the week before that. The NYSE One-Week Sell/Buy Ratio is 3.40 versus 8.15 last week and 27.25 the [...] Oops, something went wrong\n\n### News\n\n### Life\n\n### Entertainment\n\n### Finance\n\n### Sports\n\n### New on Yahoo\n\n# Yahoo Finance\n\nWe are experiencing some temporary issues. The market data on this page is currently delayed.\n\n# Tesla, Inc. (TSLA)\n\nThis price reflects trading activity during the overnight session on the Blue Ocean ATS, available 8 PM to 4 AM ET, Sunday through Thursday, when regular markets are closed.\n\n### 3.71%\n\n### 3.64%\n\n### 44.26%\n\n### 10.23%\n\n### 14.21%\n\n### 120.94% [...] ### 1-Year Return\n\n### 3-Year Return\n\n### 5-Year Return\n\n### Earnings Trends: TSLA\n\n### Earnings Per Share\n\n### Revenue vs. Earnings\n\nQ4\n\nFY24\n\nQ1\n\nFY25\n\nQ2\n\nFY25\n\nQ3\n\nFY25\n\n### Analyst Insights: TSLA\n\n### Top Analyst\n\n### Analyst Price Targets\n\n### Analyst Recommendations\n\n### Latest Rating\n\n### Statistics: TSLA\n\n### Valuation Measures\n\nMarket Cap\n\n1.48T\n\nEnterprise Value\n\n1.45T\n\nTrailing P/E\n\n307.01\n\nForward P/E\n\n200.00\n\nPEG Ratio (5yr expected)\n\n8.89\n\nPrice/Sales (ttm)\n\n16.40', 'score': 0.769306}, {'title': 'Tesla Inc (TSLA) Stock Price & News - Google Finance', 'url': 'https://www.google.com/finance/quote/TSLA:NASDAQ', 'content': "| (USD) | Sep 2025info Fiscal Q3 2025 ended 9/30/25. Reported on 10/22/25. | Y/Y change |\n --- \n| Net income  Company’s earnings for a period net of operating costs, taxes, and interest | 1.37B | -36.82% |\n| Cash from operations  Net cash used or generated for core business activities | 6.24B | -0.27% |\n| Cash from investing  Net cash used or generated in investing activities such as purchasing assets | -4.36B | -51.48% | [...] | (USD) | Sep 2025info Fiscal Q3 2025 ended 9/30/25. Reported on 10/22/25. | Y/Y change |\n --- \n| Revenue  The total amount of income generated by the sale of goods or services related to the company's primary operations | 28.10B | 11.57% |\n| Operating expense  Represents the total incurred expenses through normal operations | 3.19B | 43.46% |\n| Net income  Company’s earnings for a period net of operating costs, taxes, and interest | 1.37B | -36.82% | [...] | (USD) | Sep 2025info Fiscal Q3 2025 ended 9/30/25. Reported on 10/22/25. | Y/Y change |\n --- \n| Cash and short-term investments  Investments that are relatively liquid and have maturities between 3 months and one year | 41.65B | 23.77% |\n| Total assets  The total amount of assets owned by a company | 133.74B | 11.58% |\n| Total liabilities  Sum of the combined debts a company owes | 53.02B | 7.89% |", 'score': 0.71113056}, {'title': 'TSLA: Tesla Inc - Stock Price, Quote and News - CNBC', 'url': 'https://www.cnbc.com/quotes/TSLA', 'content': 'Data also provided byReuters logo\n\nReuters logo [...] CNBC\nJoin IC\nJoin Pro\nJoin IC\nJoin Pro\n\n# Tesla Inc TSLA:NASDAQ\n\ndownload chart\nafter hours icon\nquote price arrow up\nquote price arrow up\nLoading...\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n## Key Stats\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n### KEY STATS\n\n### RATIOS/PROFITABILITY\n\n### EVENTS\n\n## Content From Our Affiliates\n\n### Related Video\n\nHow SpaceX is fueling Elon Musk’s wealth surge\n\n### Profile\n\nCNBC logo\n\n#### News Tips\n\nGot a confidential news tip? We want to hear from you. [...] #### CNBC Newsletters\n\nSign up for free newsletters and get more CNBC delivered to your inbox\n\nGet this delivered to your inbox, and more info about our products and services.\n\n#### Advertise With Us\n\nCalifornia Consumer Privacy Act (CCPA) Opt-Out Icon\n\n© 2025 Versant Media, LLC. All Rights Reserved. A Versant Media Company.\n\nData is a real-time snapshot \\Data is delayed at least 15 minutes.\nGlobal Business and Financial News, Stock Quotes, and Market Data\nand Analysis.', 'score': 0.4191967}]Invoking: `Search` with `{'tool_input': 'Tesla stock price last week'}`[{'title': 'Tesla Stock Price History', 'url': 'https://www.investing.com/equities/tesla-motors-historical-data', 'content': 'Tesla Stock Price History ; Dec 03, 2025, 446.74, 432.10, 447.92, 431.11 ; Dec 02, 2025, 429.24, 430.81, 436.80, 422.12', 'score': 0.81418616}, {'title': 'TSLA Stock Price — Tesla Chart - TradingView', 'url': 'https://www.tradingview.com/symbols/NASDAQ-TSLA/', 'content': 'Tesla, Inc.\nTesla, Inc.\nTesla, Inc.\n\n# Tesla, Inc.\n\n## Chart\ufeff\n\n## Key facts today\n\n## Upcoming earnings\ufeff\n\n## Key stats\ufeff\n\n## Employees\ufeff\n\n## About Tesla, Inc.\n\n## Related stocks\n\n## Financials\ufeff\n\n## Community forum\ufeff\n\nSee all minds \n\n## News\ufeff\n\n## Ideas\ufeff\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nSee all ideas \n\n## Technicals\ufeff\n\n## Analyst rating\ufeff\n\n## Seasonals\ufeff\n\n## Highest yielding bonds\ufeff\n\nSee all TSLA bonds [...] ## ETFs\ufeff\n\nExplore more ETFs \n\n## Sparks\ufeff\n\nSee all sparks \n\n## Frequently Asked Questions\n\nSelect market data provided by ICE Data Services. Select reference data provided by FactSet. Copyright © 2025 FactSet Research Systems Inc.Copyright © 2025, American Bankers Association. CUSIP Database provided by FactSet Research Systems Inc. All rights reserved. SEC fillings and other documents provided by Quartr.© 2025 TradingView, Inc.\n\nLook First\nLook First', 'score': 0.3929196}, {'title': 'Tesla, Inc. Common Stock (TSLA) Historical Quotes', 'url': 'https://www.nasdaq.com/market-activity/stocks/tsla/historical', 'content': '|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n\nInformation\n\n## Latest TSLA News\n\nInfo icon\n\nThis data feed is not available at this time.\n\n|  |\n\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n\n### Symbol Search\n\n### Recently Viewed\n\n|  |\n\n|  |\n|  |\n|  |\n\n### Trending Indexes\n\n|  |\n\n|  |  |  |  |\n|  |  |  |  |\n\n© 2025, Nasdaq, Inc. All Rights Reserved.\n\nTo add symbols: [...] These symbols will be available throughout the site during your session.\n\nThese symbols will be available throughout the site during your session.\n\n## Opt in to Smart Portfolio\n\nSmart Portfolio is supported by our partner TipRanks. By connecting my portfolio to TipRanks Smart Portfolio I agree to their Terms of Use. [...] Type a symbol or company name. When the symbol you want to add appears, add it to Watchlist by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.\n\nThese symbols will be available throughout the site during your session.\n\n Type a symbol or company name. When the symbol you want to add appears, add it to Watchlist by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.', 'score': 0.2909209}]Invoking: `Search` with `{'tool_input': 'Tesla stock price today'}`[{'title': 'Tesla: TSLA Stock Price Quote & News - Robinhood', 'url': 'https://robinhood.com/us/en/stocks/TSLA/', 'content': "On 2025-12-10, Tesla(TSLA) stock traded between a low of $435.00 and a high of $452.39. Shares are currently priced at $445.40, which is +2.4% above the low and -1.5% below the high.\n\nThe Tesla(TSLA)'s current trading volume is 62.37M, compared to an average daily volume of 64.58M.\n\nDuring the past year, Tesla(TSLA) stock moved between $214.25 at its lowest and $488.54 at its peak.\n\nDuring the past year, Tesla(TSLA) stock moved between $214.25 at its lowest and $488.54 at its peak. [...] Mixed options sentiment in Tesla (TSLA), with shares up $11.50, or 2.62%, near $451.08. Options volume relatively light with 1.19m contracts traded and calls le...\n\nThe end of the year is closer than you might think, with just over three weeks to go. And that means companies are trying to clear the shelves and get next year...\n\n## People also own [...] # Tesla\n\n#### Trade Tesla 24 hours a day, five days a week on Robinhood.\n\n## About TSLA\n\n### Tesla, Inc. engages in the design, development, manufacture, and sale of electric vehicles and energy generation and storage systems. It operates through the Automotive and Energy Generation and Storage segments. Show more\n\n## TSLA Key Statistics\n\n## Stock Snapshot\n\nWith a market cap of 1.48T, Tesla(TSLA) trades at $445.40. The stock has a price-to-earnings ratio of 293.72.", 'score': 0.999608}, {'title': 'Tesla, Inc. (TSLA) Stock Price, News, Quote & History - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/', 'content': "### 35,044.99%\n\n## Tesla, Inc. Overview Auto Manufacturers / Consumer Cyclical [...] Oops, something went wrong\n\n### News\n\n### Life\n\n### Entertainment\n\n### Finance\n\n### Sports\n\n### New on Yahoo\n\n# Yahoo Finance\n\nWe are experiencing some temporary issues. The market data on this page is currently delayed.\n\n# Tesla, Inc. (TSLA)\n\nThis price reflects trading activity during the overnight session on the Blue Ocean ATS, available 8 PM to 4 AM ET, Sunday through Thursday, when regular markets are closed.\n\n### 3.71%\n\n### 3.64%\n\n### 44.26%\n\n### 10.23%\n\n### 14.21%\n\n### 120.94% [...] Tesla is navigating a complex landscape with recent adjustments in analyst outlooks and competition from emerging EV players like Rivian. Key market indicators, including the Federal Reserve's upcoming decisions, are influencing investor sentiment.\n\nStock market today: Dow, S&P 500, Nasdaq futures waver with Fed rate decision on deck\n\n### Stock market today: Dow, S&P 500, Nasdaq futures waver with Fed rate decision on deck\n\nHow Mag 7's lead over other stocks could shrink in 2026", 'score': 0.950411}, {'title': 'TSLA: Tesla Inc - Stock Price, Quote and News - CNBC', 'url': 'https://www.cnbc.com/quotes/TSLA', 'content': 'CNBC\nJoin IC\nJoin Pro\nJoin IC\nJoin Pro\n\n# Tesla Inc TSLA:NASDAQ\n\ndownload chart\nafter hours icon\nquote price arrow up\nquote price arrow up\nLoading...\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n## Key Stats\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n### KEY STATS\n\n### RATIOS/PROFITABILITY\n\n### EVENTS\n\n## Content From Our Affiliates\n\n### Related Video\n\nHow SpaceX is fueling Elon Musk’s wealth surge\n\n### Profile\n\nCNBC logo\n\n#### News Tips\n\nGot a confidential news tip? We want to hear from you. [...] Data also provided byReuters logo\n\nReuters logo [...] #### CNBC Newsletters\n\nSign up for free newsletters and get more CNBC delivered to your inbox\n\nGet this delivered to your inbox, and more info about our products and services.\n\n#### Advertise With Us\n\nCalifornia Consumer Privacy Act (CCPA) Opt-Out Icon\n\n© 2025 Versant Media, LLC. All Rights Reserved. A Versant Media Company.\n\nData is a real-time snapshot \\Data is delayed at least 15 minutes.\nGlobal Business and Financial News, Stock Quotes, and Market Data\nand Analysis.', 'score': 0.15507847}]Invoking: `Search` with `{'tool_input': 'Tesla stock price last week'}`[{'title': 'Tesla Stock Price History - Investing.com', 'url': 'https://www.investing.com/equities/tesla-motors-historical-data', 'content': 'Tesla Stock Price History ; Dec 03, 2025, 446.74, 432.10, 447.92, 431.11 ; Dec 02, 2025, 429.24, 430.81, 436.80, 422.12', 'score': 0.9953544}, {'title': 'TSLA Stock Price — Tesla Chart — TradingView', 'url': 'https://www.tradingview.com/symbols/NASDAQ-TSLA/', 'content': "View live Tesla chart to track its stock 's price action. Find market predictions, TSLA financials, and market news.", 'score': 0.92683524}, {'title': 'Tesla, Inc. (TSLA) Stock Historical Prices & Data - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/history/', 'content': 'Volume. Dec 9, 2025, 437.61, 452.39, 435.70, 445.17, 445.17, 60,868,108. Dec 8, 2025, 447.45, 449.75, 435.25, 439.58, 439.58, 69,165,800.', 'score': 0.8548847}]Invoking: `Search` with `{'tool_input': 'Tesla stock price today'}`[{'title': 'Tesla, Inc. (TSLA) Stock Historical Prices & Data - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/history/', 'content': 'Discover historical prices for TSLA stock on Yahoo Finance. View daily ... Dec 10, 2024 - Dec 10, 2025. Historical Prices. Daily. Currency in USD. Download', 'score': 0.9532751}, {'title': 'Tesla, Inc. (TSLA) Stock Price, News, Quote & History - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/', 'content': "### 35,044.99%\n\n## Tesla, Inc. Overview Auto Manufacturers / Consumer Cyclical [...] Oops, something went wrong\n\n### News\n\n### Life\n\n### Entertainment\n\n### Finance\n\n### Sports\n\n### New on Yahoo\n\n# Yahoo Finance\n\nWe are experiencing some temporary issues. The market data on this page is currently delayed.\n\n# Tesla, Inc. (TSLA)\n\nThis price reflects trading activity during the overnight session on the Blue Ocean ATS, available 8 PM to 4 AM ET, Sunday through Thursday, when regular markets are closed.\n\n### 3.71%\n\n### 3.64%\n\n### 44.26%\n\n### 10.23%\n\n### 14.21%\n\n### 120.94% [...] Tesla is navigating a complex landscape with recent adjustments in analyst outlooks and competition from emerging EV players like Rivian. Key market indicators, including the Federal Reserve's upcoming decisions, are influencing investor sentiment.\n\nStock market today: Dow, S&P 500, Nasdaq futures waver with Fed rate decision on deck\n\n### Stock market today: Dow, S&P 500, Nasdaq futures waver with Fed rate decision on deck\n\nHow Mag 7's lead over other stocks could shrink in 2026", 'score': 0.950411}, {'title': 'TSLA: Tesla Inc - Stock Price, Quote and News - CNBC', 'url': 'https://www.cnbc.com/quotes/TSLA', 'content': 'CNBC\nJoin IC\nJoin Pro\nJoin IC\nJoin Pro\n\n# Tesla Inc TSLA:NASDAQ\n\ndownload chart\nafter hours icon\nquote price arrow up\nquote price arrow up\nLoading...\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n## Key Stats\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n### KEY STATS\n\n### RATIOS/PROFITABILITY\n\n### EVENTS\n\n## Content From Our Affiliates\n\n### Related Video\n\nHow SpaceX is fueling Elon Musk’s wealth surge\n\n### Profile\n\nCNBC logo\n\n#### News Tips\n\nGot a confidential news tip? We want to hear from you. [...] Data also provided byReuters logo\n\nReuters logo [...] #### CNBC Newsletters\n\nSign up for free newsletters and get more CNBC delivered to your inbox\n\nGet this delivered to your inbox, and more info about our products and services.\n\n#### Advertise With Us\n\nCalifornia Consumer Privacy Act (CCPA) Opt-Out Icon\n\n© 2025 Versant Media, LLC. All Rights Reserved. A Versant Media Company.\n\nData is a real-time snapshot \\Data is delayed at least 15 minutes.\nGlobal Business and Financial News, Stock Quotes, and Market Data\nand Analysis.', 'score': 0.15507847}]Invoking: `Search` with `{'tool_input': 'Tesla stock price last week'}`[{'title': 'TSLA Stock Price — Tesla Chart - TradingView', 'url': 'https://www.tradingview.com/symbols/NASDAQ-TSLA/', 'content': 'Tesla, Inc.\nTesla, Inc.\nTesla, Inc.\n\n# Tesla, Inc.\n\n## Chart\ufeff\n\n## Key facts today\n\n## Upcoming earnings\ufeff\n\n## Key stats\ufeff\n\n## Employees\ufeff\n\n## About Tesla, Inc.\n\n## Related stocks\n\n## Financials\ufeff\n\n## Community forum\ufeff\n\nSee all minds \n\n## News\ufeff\n\n## Ideas\ufeff\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nSee all ideas \n\n## Technicals\ufeff\n\n## Analyst rating\ufeff\n\n## Seasonals\ufeff\n\n## Highest yielding bonds\ufeff\n\nSee all TSLA bonds [...] ## ETFs\ufeff\n\nExplore more ETFs \n\n## Sparks\ufeff\n\nSee all sparks \n\n## Frequently Asked Questions\n\nSelect market data provided by ICE Data Services. Select reference data provided by FactSet. Copyright © 2025 FactSet Research Systems Inc.Copyright © 2025, American Bankers Association. CUSIP Database provided by FactSet Research Systems Inc. All rights reserved. SEC fillings and other documents provided by Quartr.© 2025 TradingView, Inc.\n\nLook First\nLook First', 'score': 0.3928497}, {'title': 'Tesla, Inc. Common Stock (TSLA) Historical Quotes - Nasdaq', 'url': 'https://www.nasdaq.com/market-activity/stocks/tsla/historical', 'content': '|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n\nInformation\n\n## Latest TSLA News\n\nInfo icon\n\nThis data feed is not available at this time.\n\n|  |\n\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n\n### Symbol Search\n\n### Recently Viewed\n\n|  |\n\n|  |\n|  |\n|  |\n\n### Trending Indexes\n\n|  |\n\n|  |  |  |  |\n|  |  |  |  |\n\n© 2025, Nasdaq, Inc. All Rights Reserved.\n\nTo add symbols: [...] These symbols will be available throughout the site during your session.\n\nThese symbols will be available throughout the site during your session.\n\n## Opt in to Smart Portfolio\n\nSmart Portfolio is supported by our partner TipRanks. By connecting my portfolio to TipRanks Smart Portfolio I agree to their Terms of Use. [...] Type a symbol or company name. When the symbol you want to add appears, add it to Watchlist by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.\n\nThese symbols will be available throughout the site during your session.\n\n Type a symbol or company name. When the symbol you want to add appears, add it to Watchlist by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.', 'score': 0.28858462}, {'title': '2025 Shipping Movements | Tesla Motors Club', 'url': 'https://teslamotorsclub.com/tmc/threads/2025-shipping-movements.319517/', 'content': 'Tesla Motors Club\nTesla Motors Club\nTesla Motors Club\nTesla Motors Club\nTesla Motors Club\nTesla Motors Club\n\n### Search\n\n#### More options\n\nYou can install our site as a web app on your iOS device by utilizing the Add to Home Screen feature in Safari. Please see this thread for more details on this.\n\n\n\nNote: This feature may not be available in some browsers.\n\n# 2025 Shipping Movements\n\nLike\nHelpful\nMr Miserable\n\n### Mr Miserable\n\n#### Go to page\n\n#### Go to page\n\nMr Miserable\n\n#### Mr Miserable [...] ##### Well-Known Member\n\nLike\n\n#### harib sami\n\n##### Member\n\nMr Miserable\n\n#### Mr Miserable\n\n##### Well-Known Member\n\nFunny\n\n#### harib sami\n\n##### Member\n\n😁\n\n#### AlaaM747\n\n##### Member\n\nMr Miserable\n\n#### Mr Miserable\n\n##### Well-Known Member\n\nLike\nfholbert\n\n#### fholbert\n\n##### Active Member\n\nIMG_1470.jpeg\nIMG_1471.jpeg\nLike\n\n#### Nikow\n\n##### Member\n\n:)")\nLike\nroutya\n\n#### routya\n\n##### Member\n\nMr Miserable\n\n#### Mr Miserable\n\n##### Well-Known Member\n\nMr Miserable\n\n#### Mr Miserable [...] ##### Well-Known Member\n\n:)")\n\n#### Joh Joh\n\n##### Member\n\n#### pondereplay\n\n##### New Member\n\n#### GiacomoMa\n\n##### New Member\n\n#### smcd1410\n\n##### Member\n\nroutya\n\n#### routya\n\n##### Member\n\nLike\n\n#### Jimmyj07\n\n##### Member\n\nLike\n\n#### Brian O\n\n##### Member\n\nLike\nroutya\n\n#### routya\n\n##### Member\n\nLike\n\n#### Go to page\n\n#### Go to page\n\n### Similar threads\n\nMr Miserable\nJupiterMan\nSecret-EV\nSecret-EV\n\n### Meta\n\n### Help/Tutorials\n\n### Supporting Members', 'score': 0.062268417}]Invoking: `Search` with `{'tool_input': 'Tesla stock price today'}`[{'title': 'Tesla, Inc. (TSLA) Stock Price, News, Quote & History - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/', 'content': 'While the weekly insider-sentiment data from Vickers Stock Research is noticeably improved from what was seen over the past two weeks, insiders clearly remain cautious. And while improved, the sentiment data is still far from the readings below 2.00 that are needed for a bullish call. By the number, the current Total (all exchanges) One-Week Sell/Buy Ratio is 6.02 versus 11.45 last week and 17.32 the week before that. The NYSE One-Week Sell/Buy Ratio is 3.40 versus 8.15 last week and 27.25 the [...] Oops, something went wrong\n\n### News\n\n### Life\n\n### Entertainment\n\n### Finance\n\n### Sports\n\n### New on Yahoo\n\n# Yahoo Finance\n\nWe are experiencing some temporary issues. The market data on this page is currently delayed.\n\n# Tesla, Inc. (TSLA)\n\nThis price reflects trading activity during the overnight session on the Blue Ocean ATS, available 8 PM to 4 AM ET, Sunday through Thursday, when regular markets are closed.\n\n### 3.71%\n\n### 3.64%\n\n### 44.26%\n\n### 10.23%\n\n### 14.21%\n\n### 120.94% [...] ### 1-Year Return\n\n### 3-Year Return\n\n### 5-Year Return\n\n### Earnings Trends: TSLA\n\n### Earnings Per Share\n\n### Revenue vs. Earnings\n\nQ4\n\nFY24\n\nQ1\n\nFY25\n\nQ2\n\nFY25\n\nQ3\n\nFY25\n\n### Analyst Insights: TSLA\n\n### Top Analyst\n\n### Analyst Price Targets\n\n### Analyst Recommendations\n\n### Latest Rating\n\n### Statistics: TSLA\n\n### Valuation Measures\n\nMarket Cap\n\n1.48T\n\nEnterprise Value\n\n1.45T\n\nTrailing P/E\n\n307.01\n\nForward P/E\n\n200.00\n\nPEG Ratio (5yr expected)\n\n8.89\n\nPrice/Sales (ttm)\n\n16.40', 'score': 0.76972175}, {'title': 'Tesla, Inc. (TSLA) Stock Historical Prices & Data - Yahoo Finance', 'url': 'https://finance.yahoo.com/quote/TSLA/history/', 'content': 'Discover historical prices for TSLA stock on Yahoo Finance. View daily ... Dec 10, 2024 - Dec 10, 2025. Historical Prices. Daily. Currency in USD. Download', 'score': 0.54492307}, {'title': 'TSLA: Tesla Inc - Stock Price, Quote and News - CNBC', 'url': 'https://www.cnbc.com/quotes/TSLA', 'content': 'Data also provided byReuters logo\n\nReuters logo [...] CNBC\nJoin IC\nJoin Pro\nJoin IC\nJoin Pro\n\n# Tesla Inc TSLA:NASDAQ\n\ndownload chart\nafter hours icon\nquote price arrow up\nquote price arrow up\nLoading...\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n## Key Stats\n\n## Latest On Tesla Inc\n\nCNBC Video\n\n### KEY STATS\n\n### RATIOS/PROFITABILITY\n\n### EVENTS\n\n## Content From Our Affiliates\n\n### Related Video\n\nHow SpaceX is fueling Elon Musk’s wealth surge\n\n### Profile\n\nCNBC logo\n\n#### News Tips\n\nGot a confidential news tip? We want to hear from you. [...] #### CNBC Newsletters\n\nSign up for free newsletters and get more CNBC delivered to your inbox\n\nGet this delivered to your inbox, and more info about our products and services.\n\n#### Advertise With Us\n\nCalifornia Consumer Privacy Act (CCPA) Opt-Out Icon\n\n© 2025 Versant Media, LLC. All Rights Reserved. A Versant Media Company.\n\nData is a real-time snapshot \\Data is delayed at least 15 minutes.\nGlobal Business and Financial News, Stock Quotes, and Market Data\nand Analysis.', 'score': 0.41933936}]Invoking: `Search` with `{'tool_input': 'Tesla stock price last week'}`[{'title': 'Tesla | TSLA - Stock Price | Live Quote | Historical Chart', 'url': 'https://tradingeconomics.com/tsla:us', 'content': '## Tesla traded at $445.20 this Tuesday December 9th, increasing $5.62 or 1.28 percent since the previous trading session. Looking back, over the last four weeks, Tesla gained 0.01 percent. Over the last 12 months, its price rose by 11.13 percent. Looking ahead, we forecast Tesla to be priced at 440.62 by the end of this quarter and at 400.16 in one year, according to Trading Economics global macro models projections and analysts expectations. [...] |  | Actual | Chg | %Chg |  |\n ---  --- \n| US500 | 6845.02 | 5 | 0.07% |  |\n| US30 | 47586 | 26 | 0.05% |  |\n| US100 | 25683 | 15 | 0.06% |  |\n| JP225 | 50569 | 86 | -0.17% |  |\n| GB100 | 9642 | 3 | -0.03% |  |\n| DE40 | 24097 | 66 | -0.27% |  |\n| FR40 | 8028 | 25 | -0.31% |  |\n| IT40 | 43404 | 166 | -0.38% |  |\n| ES35 | 16675 | 60 | -0.36% |  |\n| ASX200 | 8544 | 42 | -0.49% |  |\n| SHANGHAI | 3901 | 9 | -0.22% |  |\n| SENSEX | 84613 | 53 | -0.06% |  |\n| TSX | 31244 | 74 | 0.24% |  | [...] |  | Actual | Chg | %Chg |\n ---  --- |\n| EURUSD | 1.16348 | 0.0006 | 0.05% |\n| GBPUSD | 1.33132 | 0.0017 | 0.13% |\n| AUDUSD | 0.66483 | 0.0007 | 0.10% |\n| NZDUSD | 0.57808 | 0.0002 | 0.04% |\n| USDJPY | 156.672 | 0.2085 | -0.13% |\n| USDCNY | 7.05940 | 0.0017 | -0.02% |\n| USDCHF | 0.80564 | 0.0008 | -0.09% |\n| USDCAD | 1.38483 | 0.0001 | 0.01% |\n| USDMXN | 18.1890 | 0.0086 | -0.05% |\n| USDINR | 90.0470 | 0.1296 | 0.14% |\n| USDBRL | 5.43310 | 0.0006 | -0.01% |', 'score': 0.89849097}, {'title': 'TSLA Stock Price — Tesla Chart - TradingView', 'url': 'https://www.tradingview.com/symbols/NASDAQ-TSLA/', 'content': 'Tesla, Inc.\nTesla, Inc.\nTesla, Inc.\n\n# Tesla, Inc.\n\n## Chart\ufeff\n\n## Key facts today\n\n## Upcoming earnings\ufeff\n\n## Key stats\ufeff\n\n## Employees\ufeff\n\n## About Tesla, Inc.\n\n## Related stocks\n\n## Financials\ufeff\n\n## Community forum\ufeff\n\nSee all minds \n\n## News\ufeff\n\n## Ideas\ufeff\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nNASDAQ:TSLA\n\nSee all ideas \n\n## Technicals\ufeff\n\n## Analyst rating\ufeff\n\n## Seasonals\ufeff\n\n## Highest yielding bonds\ufeff\n\nSee all TSLA bonds [...] ## ETFs\ufeff\n\nExplore more ETFs \n\n## Sparks\ufeff\n\nSee all sparks \n\n## Frequently Asked Questions\n\nSelect market data provided by ICE Data Services. Select reference data provided by FactSet. Copyright © 2025 FactSet Research Systems Inc.Copyright © 2025, American Bankers Association. CUSIP Database provided by FactSet Research Systems Inc. All rights reserved. SEC fillings and other documents provided by Quartr.© 2025 TradingView, Inc.\n\nLook First\nLook First', 'score': 0.3928497}, {'title': 'Tesla, Inc. Common Stock (TSLA) Historical Quotes - Nasdaq', 'url': 'https://www.nasdaq.com/market-activity/stocks/tsla/historical', 'content': '|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n|  |  |  |  |\n\nInformation\n\n## Latest TSLA News\n\nInfo icon\n\nThis data feed is not available at this time.\n\n|  |\n\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n|  |\n\n### Symbol Search\n\n### Recently Viewed\n\n|  |\n\n|  |\n|  |\n|  |\n\n### Trending Indexes\n\n|  |\n\n|  |  |  |  |\n|  |  |  |  |\n\n© 2025, Nasdaq, Inc. All Rights Reserved.\n\nTo add symbols: [...] These symbols will be available throughout the site during your session.\n\nThese symbols will be available throughout the site during your session.\n\n## Opt in to Smart Portfolio\n\nSmart Portfolio is supported by our partner TipRanks. By connecting my portfolio to TipRanks Smart Portfolio I agree to their Terms of Use. [...] Type a symbol or company name. When the symbol you want to add appears, add it to Watchlist by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.\n\nThese symbols will be available throughout the site during your session.\n\n Type a symbol or company name. When the symbol you want to add appears, add it to Watchlist by selecting it and pressing Enter/Return.\n Copy and paste multiple symbols separated by spaces.', 'score': 0.28858462}]今天特斯拉(Tesla, TSLA)的股票价格为 **$445.20**。相比上周,特斯拉的股票价格变化如下:- 上周的价格(12月2日)为 **$429.24**。- 上周的价格(12月3日)为 **$446.74**。因此,今天的价格相比上周的价格(以12月2日的价格为基准)上涨了 **$15.96**,涨幅约为 **3.72%**。如果你需要更详细的信息或其他数据,请告诉我!> Finished chain.查询结果: {'input': '特斯拉今天的股票价格如何?比上周的变化是多少?', 'output': '今天特斯拉(Tesla, TSLA)的股票价格为 **$445.20**。相比上周,特斯拉的股票价格变化如下:\n\n- 上周的价格(12月2日)为 **$429.24**。\n- 上周的价格(12月3日)为 **$446.74**。\n\n因此,今天的价格相比上周的价格(以12月2日的价格为基准)上涨了 **$15.96**,涨幅约为 **3.72%**。\n\n如果你需要更详细的信息或其他数据,请告诉我!'}

案例3:自定义函数与工具

需求:计算3的平方,Agent自动调用工具完成

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :custom-demo.py@Author  :zxb@Date    :2025/12/10 15:06"""import osfrom dotenv import load_dotenvfrom langchain.agents import initialize_agent, AgentTypefrom langchain_core.tools import Toolfrom langchain_openai import ChatOpenAI# 定义工具 - 计算器def simple_calculator(expression: str)-> str:    """    基础数学计算工具,支持加减乘除和幂运算    参数:        expression: 数学表达式字符串,如"3 + 5" 或 "2**3"    返回:        计算结果字符串或错误信息    """    print(f"[计算工具调用] 正在计算:{expression}")    print("计算完成~")    return str(eval(expression))# 创建工具对象match_calculator_tool = Tool(    name="Math_Calculator",    func=simple_calculator,    description="用于执行数学计算,输入必须是一个数学表达式,如'3 + 5' 或 '2**3'。不支持字母或特殊符号")# 初始化大模型load_dotenv()llm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 初始化AgentExecutoragent_executor = initialize_agent(    tools=[match_calculator_tool],    llm=llm,    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,    verbose=True)# 测试print("===测试:正常工具调用===")res = agent_executor.invoke("计算9的平方")print(res)

输出如下:

===测试:正常工具调用===> Entering new AgentExecutor chain...F:\Project\JetbrainsProjects\PycharmProject\LangChain-tutorial\chapter06-agent\traditional_use\custom-demo.py:46: LangChainDeprecationWarning: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool-calling, persistence of state, and human-in-the-loop workflows. For details, refer to the `LangGraph documentation <https://langchain-ai.github.io/langgraph/>`_ as well as guides for `Migrating from AgentExecutor <https://python.langchain.com/docs/how_to/migrate_agent/>`_ and LangGraph's `Pre-built ReAct agent <https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/>`_.  agent_executor = initialize_agent(我需要计算9的平方,这可以通过数学表达式9**2来实现。Action: Math_CalculatorAction Input: 9**2[计算工具调用] 正在计算:9**2计算完成~Observation: 81Thought:计算结果为81。Final Answer: 9的平方是81。> Finished chain.{'input': '计算9的平方', 'output': '9的平方是81。'}

通用方式

需求:今天北京的天气怎么样??

方式1:FUNCATION_CALL模式
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :FUNCATION_CALL.py@Author  :zxb@Date    :2025/12/10 15:41@Desc    :FUNCATION_CALL模式 Demo"""import osfrom dotenv import load_dotenvfrom langchain.agents import create_tool_calling_agent, AgentExecutorfrom langchain_community.tools import TavilySearchResultsfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_openai import ChatOpenAIload_dotenv()search = TavilySearchResults(max_results=1)# 定义自定义提示词模板prompt = ChatPromptTemplate.from_messages([    ("system", "您是一位乐于助人的助手,请务必使用tavily_search_results_json工具来获取信息。"),    ("human", "{input}"),    ("placeholder", "{agent_scratchpad}")])# 定义LLMllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 创建Agent对象agent = create_tool_calling_agent(    llm=llm,    tools=[search],    prompt=prompt)# 创建AgentExecutor执行器agent_executor = AgentExecutor(agent=agent, tools=[search], verbose=True)# 测试res = agent_executor.invoke({"input": "今天厦门的天气怎么样?"})print(res)

输出如下:

> Entering new AgentExecutor chain...Invoking: `tavily_search_results_json` with `{'query': '今天厦门的天气怎么样?'}`[{'title': '廈門, 福建省, 中國每小時天氣 - AccuWeather', 'url': 'https://www.accuweather.com/zh/cn/xiamen/57919/hourly-weather-forecast/57919', 'content': '返回 \n\n# 廈門, 福建省\n\n68°F   \n\n68°\n\n設定\n\n廈門, 福建省 天氣\n\n今天 WinterCast 當地{stormName}追蹤 每小時 每天 雷達 MinuteCast® 每月 空氣品質 健康與活動\n\n全球範圍\n\n### 颶風 ### 惡劣天氣 ### 雷達與氣象圖 ### 視訊\n\n今天  ## 每小時  每天   雷達   MinuteCast®   每月   空氣品質   健康與活動\n\n## 下午8时\n\n65°\n\nRealFeel® 59°\n\n涼爽\n\n0%\n\n大致晴朗\n\n警告\n\n大風黃色預警\n\nPM6:52 星期一 - AM6:52 星期二\n\n風東北 22英里/小时\n\n空氣品質不佳\n\n陣風29英里/小时\n\n濕度60%\n\n露點50° F\n\nAccuLumen Brightness Index™0 (暗)\n\n雲層14%\n\n能見度10英里\n\n雲冪30000英尺\n\n## 下午9时\n\n64°\n\nRealFeel® 58°\n\n涼爽\n\n0%\n\n晴朗\n\n警告\n\n大風黃色預警\n\nPM6:52 星期一 - AM6:52 星期二\n\n風東北 20英里/小时\n\n空氣品質不佳 [...] 陣風28英里/小时\n\n濕度61%\n\n露點50° F\n\nAccuLumen Brightness Index™0 (暗)\n\n雲層9%\n\n能見度10英里\n\n雲冪30000英尺\n\n## 下午10时\n\n63°\n\nRealFeel® 58°\n\n涼爽\n\n0%\n\n晴朗\n\n警告\n\n大風黃色預警\n\nPM6:52 星期一 - AM6:52 星期二\n\n風東北 17英里/小时\n\n空氣品質不佳\n\n陣風27英里/小时\n\n濕度61%\n\n露點50° F\n\nAccuLumen Brightness Index™0 (暗)\n\n雲層5%\n\n能見度10英里\n\n雲冪30000英尺\n\n## 下午11时\n\n63°\n\nRealFeel® 58°\n\n涼爽\n\n0%\n\n晴朗\n\n警告\n\n大風黃色預警\n\nPM6:52 星期一 - AM6:52 星期二\n\n風東北 16英里/小时\n\n空氣品質不健康\n\n陣風25英里/小时\n\n濕度61%\n\n露點50° F\n\nAccuLumen Brightness Index™0 (暗)\n\n雲層0%\n\n能見度10英里\n\n雲冪30000英尺\n\n### 明天 ### 星期三 ### 每天\n\n全球範圍', 'score': 0.6999322}]今天厦门的天气大致晴朗,气温在63°F到68°F之间,体感温度在58°F左右。风力方面,东北风速度为16到22英里/小时,伴有阵风,最高可达29英里/小时。湿度为60%到61%,露点温度为50°F。空气品质不佳,甚至不健康,需要注意防护。能见度良好,为10英里,云层覆盖度较低,从0%到14%不等。此外,有大风黄色预警,提醒注意防范。> Finished chain.{'input': '今天厦门的天气怎么样?', 'output': '今天厦门的天气大致晴朗,气温在63°F到68°F之间,体感温度在58°F左右。风力方面,东北风速度为16到22英里/小时,伴有阵风,最高可达29英里/小时。湿度为60%到61%,露点温度为50°F。空气品质不佳,甚至不健康,需要注意防护。能见度良好,为10英里,云层覆盖度较低,从0%到14%不等。此外,有大风黄色预警,提醒注意防范。'}

举例2:ReAct 模式

ReAct模式下,创建Agent时,可以使用ChatPromptTemplate、PromptTemplate

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :ReAct.py@Author  :zxb@Date    :2025/12/10 16:31"""import osfrom dotenv import load_dotenvfrom langchain.agents import AgentExecutorfrom langchain.agents import create_react_agentfrom langchain.memory import ConversationBufferMemory# 导入必要的库from langchain_community.tools.tavily_search import TavilySearchResultsfrom langchain_core.prompts import PromptTemplatefrom langchain_openai import ChatOpenAIload_dotenv()# 定义搜索工具search = TavilySearchResults(max_results=1)# 设置工具集tools = [search]# 自定义提示词模版template = ("Assistant is a large language model trained by OpenAl.\n\n\n\n"            "Assistant is designed to be able to assist with a wide range of tasks, from answering "            "simple questions to providing in-depth explanations and discussions on a wide range of topics. "            "As a language model, Assistant is able to generate human-like text based on the input it "            "receives, allowing it to engage in natural-sounding conversations and provide responses that "            "are coherent and relevant to the topic at hand.\n\n"            "Assistant is constantly learning and improving, and its capabilities are constantly "            "evolving. It is able to process and understand large amounts of text, and can use this "            "knowledge to provide accurate and informative responses to a wide range of questions. "            "Additionally, Assistant is able to generate its own text based on the input it receives, allowing it "            "to engage in discussions and provide explanations and descriptions on a wide range of "            "topics.\n\n"            "Overall, Assistant is a powerful tool that can help with a wide range of tasks and "            "provide valuable insights and information on a wide range of topics. Whether you need help "            "with a specific question or just want to have a conversation about a particular topic, Assistant is "            "here to assist.\n\n"            "TOOLS:\n"            "------\n"            "Assistant has access to the following tools:\n\n"            "{tools}\n\n"            "To use a tool, please use the following format:\n\n"            "Thought: Do I need to use a tool? Yes\n"            "Action: the action to take, should be one of [{tool_names}]\n"            "Action Input: the input to the action\n"            "Observation: the result of the action\n"            "When you have a response to say to the Human, or if you do not need to use a tool, "            "you MUST use the format:\n\n"            "Thought: Do I need to use a tool? No\n"            "Final Answer: [your response here]\n"            "Begin!\n\n"            "Previous conversation history:\n"            "{chat_history}\n\n"            "New input: {input}\n"            "{agent_scratchpad}")# 创建提示词模板prompt = PromptTemplate.from_template(template)# 定义LLMllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 定义记忆组件(以ConversationBufferMemory为例)memory = ConversationBufferMemory(    memory_key="chat_history",    return_messages=True)# 创建Agent对象agent = create_react_agent(llm, tools, prompt)# 创建AgentExecutor执行器agent_executor = AgentExecutor(    agent=agent,    tools=tools,    verbose=True,    memory=memory)# 测试agent_executor.invoke({"input": "我的名字叫Bob"})agent_executor.invoke({"input": "请问,我的名字叫什么?"})

输出如下:

> Entering new AgentExecutor chain...F:\Project\JetbrainsProjects\PycharmProject\LangChain-tutorial\chapter06-agent\common_use\ReAct.py:68: LangChainDeprecationWarning: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/  memory = ConversationBufferMemory(Thought: Do I need to use a tool? No  Final Answer: 你好,Bob!很高兴认识你。有什么我可以帮助你的吗?> Finished chain.> Entering new AgentExecutor chain...Thought: Do I need to use a tool? NoFinal Answer: 你的名字是Bob。> Finished chain.

举例3:远程获取提示词模版

以通用方式create_xxx_agent的ReAct模式为例,FUNCATION_CALL一样

远程的提示词模版通过https://smith.langchain.com/hub/hwchase17获取

  • 举例:https://smith.langchain.com/hub/hwchase17/react-chat,这个模板是专为聊天场景设计的ReAct提示模板。这个模板中已经有聊天对话键chat_historyagent_scratchpad
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""@Project :LangChain-tutorial @File    :pull.py@Author  :zxb@Date    :2025/12/10 16:43"""import osfrom dotenv import load_dotenvfrom langchain.agents import create_react_agent, AgentExecutorfrom langchain.memory import ConversationBufferMemoryfrom langchain_community.tools import TavilySearchResultsfrom langchain import hubfrom langchain_openai import ChatOpenAIload_dotenv()search = TavilySearchResults(max_results=1)# 设置工具集tools = [search]# 获取提示词prompt = hub.pull("hwchase17/react-chat")# 定义llmllm = ChatOpenAI(    model=os.getenv("LLM_MODEL"),    temperature=0)# 定义记忆组件memory = ConversationBufferMemory(    memory_key="chat_history",    return_messages=True)# 创建Agent、AgentExecutoragent = create_react_agent(llm, tools, prompt)agent_executor = AgentExecutor(agent=agent, tools=tools, memory=memory, verbose=True)# 执行agent_executor.invoke({"input": "今天广州的天气怎么样?"})

输出如下:

> Entering new AgentExecutor chain...Thought: Do I need to use a tool? YesAction: tavily_search_results_jsonAction Input: 今天广州的天气怎么样?[{'title': '广州天气预报,广州7天天气预报,广州15天天气预报,广州天气查询', 'url': 'https://www.weather.com.cn/weather/101280101.shtml', 'content': '首页 预报 预警 雷达 云图 天气地图 专业产品 资讯 视频 节气 我的天空\n\n更多\n\n台风路径 空间天气 图片 专题 环境 旅游 碳中和 气象科普 一带一路 产创平台\n\n国内) 本地) 国际)\n\n:   北京 上海 成都 杭州 南京 天津 深圳 重庆 西安 广州 青岛 武汉\n\n:   故宫 阳朔漓江 龙门石窟 野三坡 颐和园 九寨沟 东方明珠 凤凰古城 秦始皇陵 桃花源\n\n高球\n:   佘山 春城湖畔 华彬庄园 观澜湖 依必朗 旭宝 博鳌 玉龙雪山 番禺南沙 东方明珠\n\n<<返回 全国\n\n河北下辖区域\n\n热门城市\n\n:   曼谷 东京 首尔 吉隆坡 新加坡 巴黎 罗马 伦敦 雅典 柏林 纽约 温哥华 墨西哥城 哈瓦那 圣何塞 巴西利亚 布宜诺斯艾利斯 圣地亚哥 利马 基多 悉尼 墨尔本 惠灵顿 奥克兰 苏瓦 开罗 内罗毕 开普敦 维多利亚 拉巴特\n\n:   亚洲 欧洲 北美洲 南美洲 非洲 大洋洲\n\n全国> 广东 > 广州> 城区\n\n 今天\n 7天\n 8-15天\n 40天\n 雷达图\n\n # 6日(今天)\n\n  晴\n\n  13℃\n\n  <3级\n # 7日(明天)\n\n  晴', 'score': 0.7458619}]Thought: Do I need to use a tool? No  Final Answer: 今天广州的天气晴,气温13℃,风力小于3级。> Finished chain.

如何学习大模型 AI ?

由于新岗位的生产效率,要优于被取代岗位的生产效率,所以实际上整个社会的生产效率是提升的。

但是具体到个人,只能说是:

“最先掌握AI的人,将会比较晚掌握AI的人有竞争优势”。

这句话,放在计算机、互联网、移动互联网的开局时期,都是一样的道理。

我在一线科技企业深耕十二载,见证过太多因技术卡位而跃迁的案例。那些率先拥抱 AI 的同事,早已在效率与薪资上形成代际优势,我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在大模型的学习中的很多困惑。我们整理出这套 AI 大模型突围资料包

  • ✅ 从零到一的 AI 学习路径图
  • ✅ 大模型调优实战手册(附医疗/金融等大厂真实案例)
  • ✅ 百度/阿里专家闭门录播课
  • ✅ 大模型当下最新行业报告
  • ✅ 真实大厂面试真题
  • ✅ 2025 最新岗位需求图谱

所有资料 ⚡️ ,朋友们如果有需要 《AI大模型入门+进阶学习资源包》下方扫码获取~
在这里插入图片描述

① 全套AI大模型应用开发视频教程

(包含提示工程、RAG、LangChain、Agent、模型微调与部署、DeepSeek等技术点)
在这里插入图片描述

② 大模型系统化学习路线

作为学习AI大模型技术的新手,方向至关重要。 正确的学习路线可以为你节省时间,少走弯路;方向不对,努力白费。这里我给大家准备了一份最科学最系统的学习成长路线图和学习规划,带你从零基础入门到精通!
在这里插入图片描述

③ 大模型学习书籍&文档

学习AI大模型离不开书籍文档,我精选了一系列大模型技术的书籍和学习文档(电子版),它们由领域内的顶尖专家撰写,内容全面、深入、详尽,为你学习大模型提供坚实的理论基础。
在这里插入图片描述

④ AI大模型最新行业报告

2025最新行业报告,针对不同行业的现状、趋势、问题、机会等进行系统地调研和评估,以了解哪些行业更适合引入大模型的技术和应用,以及在哪些方面可以发挥大模型的优势。
在这里插入图片描述

⑤ 大模型项目实战&配套源码

学以致用,在项目实战中检验和巩固你所学到的知识,同时为你找工作就业和职业发展打下坚实的基础。
在这里插入图片描述

⑥ 大模型大厂面试真题

面试不仅是技术的较量,更需要充分的准备。在你已经掌握了大模型技术之后,就需要开始准备面试,我精心整理了一份大模型面试题库,涵盖当前面试中可能遇到的各种技术问题,让你在面试中游刃有余

图片

以上资料如何领取?

在这里插入图片描述

为什么大家都在学大模型?

最近科技巨头英特尔宣布裁员2万人,传统岗位不断缩减,但AI相关技术岗疯狂扩招,有3-5年经验,大厂薪资就能给到50K*20薪!

图片

不出1年,“有AI项目经验”将成为投递简历的门槛。

风口之下,与其像“温水煮青蛙”一样坐等被行业淘汰,不如先人一步,掌握AI大模型原理+应用技术+项目实操经验,“顺风”翻盘!
在这里插入图片描述
在这里插入图片描述

这些资料真的有用吗?

这份资料由我和鲁为民博士(北京清华大学学士和美国加州理工学院博士)共同整理,现任上海殷泊信息科技CEO,其创立的MoPaaS云平台获Forrester全球’强劲表现者’认证,服务航天科工、国家电网等1000+企业,以第一作者在IEEE Transactions发表论文50+篇,获NASA JPL火星探测系统强化学习专利等35项中美专利。本套AI大模型课程由清华大学-加州理工双料博士、吴文俊人工智能奖得主鲁为民教授领衔研发。

资料内容涵盖了从入门到进阶的各类视频教程和实战项目,无论你是小白还是有些技术基础的技术人员,这份资料都绝对能帮助你提升薪资待遇,转行大模型岗位。
在这里插入图片描述
在这里插入图片描述

以上全套大模型资料如何领取?

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值