为了大幅提升大语言模型应用开发效率,主流框架 LangChain 提供了数百款开箱即用的标准化工具

📅 2026/7/11 7:37:18
为了大幅提升大语言模型应用开发效率,主流框架 LangChain 提供了数百款开箱即用的标准化工具
文件操作、数据库处理、网络访问、代码执行、API 集成等核心场景。这些工具统一接口规范内置完善的错误处理与数据转换逻辑避免重复开发同时支持快速封装自定义工具并能与链、智能体、RAG 等核心组件深度协同。这不仅能帮助开发者快速构建稳定可靠的 AI 应用还能极大简化流程、缩短上线周期让开发者聚焦业务逻辑创新与用户体验优化。动画视频在《24. LangChain内置工具开发效率提升10倍》。 搜索引擎类工具名称功能DuckDuckGoSearchRun使用 DuckDuckGo 搜索DuckDuckGoSearchResults获取 DuckDuckGo 搜索结果WikipediaQueryRun查询 WikipediaBingSearchRun使用 Bing 搜索需要 API KeyBingSearchResults获取 Bing 搜索结果需要 API KeyBraveSearch使用 Brave 搜索需要 API KeySearxSearchRun使用 Searx 搜索SearxSearchResults获取 Searx 搜索结果TavilyAnswer获取 Tavily 答案需要 API KeyTavilySearchResults获取 Tavily 搜索结果需要 API KeyGoogleSerperRun使用 Google Serper 搜索需要 API KeyGoogleSerperResults获取 Google Serper 结果需要 API KeySearchAPIRun使用 SearchAPI 搜索需要 API KeySearchAPIResults获取 SearchAPI 结果需要 API KeyJinaSearch使用 Jina 搜索MojeekSearch使用 Mojeek 搜索MetaphorSearchResults获取 Metaphor 搜索结果YouSearchTool使用 You.com 搜索AskNewsSearch搜索新闻需要 API Key 社交媒体和平台工具类工具名称功能RedditSearchRun搜索 RedditRedditSearchSchemaReddit 搜索模式YouTubeSearchTool搜索 YouTubeStackExchangeTool查询 Stack ExchangeSteamWebAPIQueryRun查询 Steam API需要 API KeyNasaAction查询 NASA 数据需要 API KeyJiraAction操作 Jira需要 API Key 文件管理类工具名称功能ReadFileTool读取文件内容WriteFileTool写入文件内容CopyFileTool复制文件DeleteFileTool删除文件MoveFileTool移动文件ListDirectoryTool列出目录内容FileSearchTool搜索文件 金融工具类工具名称功能YahooFinanceNewsTool查询 Yahoo 财经新闻PolygonAggregates获取 Polygon 聚合数据需要 API KeyPolygonFinancials获取 Polygon 财务数据需要 API KeyPolygonLastQuote获取 Polygon 最新报价需要 API KeyPolygonTickerNews获取 Polygon 股票新闻需要 API KeyBalanceSheets获取资产负债表CashFlowStatements获取现金流量表IncomeStatements获取利润表 计算和数据类工具名称功能WolframAlphaQueryRun使用 Wolfram Alpha 计算需要 API KeyJsonGetValueTool获取 JSON 值JsonListKeysTool列出 JSON 键SleepTool延迟执行DataheraldTextToSQL文本转 SQL需要 API KeyAIPluginTool使用 AI 插件 数据库类工具名称功能QuerySQLDatabaseTool查询 SQL 数据库InfoSQLDatabaseTool获取 SQL 数据库信息ListSQLDatabaseTool列出 SQL 数据库表QuerySQLCheckerTool检查 SQL 查询QuerySparkSQLTool查询 Spark SQLInfoSparkSQLTool获取 Spark SQL 信息ListSparkSQLTool列出 Spark SQL 表QueryCheckerTool检查查询QueryPowerBITool查询 Power BI需要 API KeyInfoPowerBITool获取 Power BI 信息需要 API KeyListPowerBITool列出 Power BI 数据集需要 API KeyQueryCassandraDatabaseTool查询 Cassandra 数据库GetSchemaCassandraDatabaseTool获取 Cassandra 架构GetTableDataCassandraDatabaseTool获取 Cassandra 表数据 邮件和通讯工具类工具名称功能GmailCreateDraft创建 Gmail 草稿需要 API KeyGmailGetMessage获取 Gmail 消息需要 API KeyGmailGetThread获取 Gmail 会话需要 API KeyGmailSearch搜索 Gmail需要 API KeyGmailSendMessage发送 Gmail 消息需要 API KeyO365CreateDraftMessage创建 Office 365 草稿需要 API KeyO365SearchEmails搜索 Office 365 邮件需要 API KeyO365SearchEvents搜索 Office 365 事件需要 API KeyO365SendEvent发送 Office 365 事件需要 API KeyO365SendMessage发送 Office 365 消息需要 API KeySlackGetChannel获取 Slack 频道需要 API KeySlackGetMessage获取 Slack 消息需要 API KeySlackScheduleMessage定时发送 Slack 消息需要 API KeySlackSendMessage发送 Slack 消息需要 API Key 网页访问类工具名称功能RequestsGetTool发送 HTTP GET 请求RequestsPostTool发送 HTTP POST 请求RequestsPutTool发送 HTTP PUT 请求RequestsPatchTool发送 HTTP PATCH 请求RequestsDeleteTool发送 HTTP DELETE 请求NavigateTool导航到网页NavigateBackTool返回上一页ClickTool点击网页元素ExtractTextTool提取网页文本ExtractHyperlinksTool提取网页链接GetElementsTool获取网页元素CurrentWebPageTool获取当前网页 语音和图像工具类工具名称功能AzureCogsFormRecognizerToolAzure 表单识别需要 API KeyAzureCogsImageAnalysisToolAzure 图像分析需要 API KeyAzureCogsSpeech2TextToolAzure 语音转文本需要 API KeyAzureCogsText2SpeechToolAzure 文本转语音需要 API KeyAzureCogsTextAnalyticsHealthToolAzure 医疗文本分析需要 API KeyAzureAiServicesDocumentIntelligenceToolAzure 文档智能需要 API KeyAzureAiServicesImageAnalysisToolAzure AI 图像分析需要 API KeyAzureAiServicesSpeechToTextToolAzure AI 语音转文本需要 API KeyAzureAiServicesTextToSpeechToolAzure AI 文本转语音需要 API KeyAzureAiServicesTextAnalyticsForHealthToolAzure AI 医疗文本分析需要 API KeyGoogleCloudTextToSpeechToolGoogle Cloud 文本转语音需要 API KeyElevenLabsText2SpeechToolElevenLabs 文本转语音需要 API KeySceneXplainTool解释图像需要 API KeySteamshipImageGenerationTool生成图像需要 API KeyAI服务和集成工具类工具名称功能EdenAiExplicitImageTool检测敏感图像需要 API KeyEdenAiObjectDetectionTool对象检测需要 API KeyEdenAiParsingIDTool解析身份证需要 API KeyEdenAiParsingInvoiceTool解析发票需要 API KeyEdenAiSpeechToTextTool语音转文本需要 API KeyEdenAiTextModerationTool文本审核需要 API KeyEdenAiTextToSpeechTool文本转语音需要 API KeyEdenaiToolEdenAI 通用工具需要 API KeyBearlyInterpreterTool代码解释器需要 API KeyE2BDataAnalysisTool数据分析需要 API KeyZapierNLAListActions列出 Zapier 动作需要 API KeyZapierNLARunAction运行 Zapier 动作需要 API KeyCogniswitchKnowledgeRequest知识请求需要 API KeyCogniswitchKnowledgeSourceFile知识源文件需要 API KeyCogniswitchKnowledgeSourceURL知识源 URL需要 API KeyCogniswitchKnowledgeStatus知识状态需要 API KeyZenGuardToolZenGuard 工具需要 API KeyDetector检测器需要 API KeyZenGuardInputZenGuard 输入需要 API Key️其他工具类工具名称功能HumanInputRun获取用户输入StdInInquireTool标准输入询问ShellTool执行 Shell 命令MerriamWebsterQueryRun查询 Merriam-Webster 词典需要 API KeyOpenWeatherMapQueryRun查询天气需要 API KeyVectorStoreQATool向量存储问答VectorStoreQAWithSourcesTool带来源的向量存储问答BaseGraphQLToolGraphQL 查询BaseRequestsToolHTTP 请求基础工具BaseSQLDatabaseToolSQL 数据库基础工具BaseSparkSQLToolSpark SQL 基础工具YahooFinanceNewsToolYahoo 财经新闻学术搜索类工具名称功能ArxivQueryRun查询 Arxiv 论文PubmedQueryRun查询 PubMed 医学文献GoogleBooksQueryRun查询 Google BooksLangChain的工具在langchain-community开发包中使用前需要先进行安装。pip install langchain-community这些工具类采用了继承BaseTool类的方式相较于tool装饰器的简洁实现提供了更精细的控制能力支持自定义args_schema、详细的name和description属性以及完整的_run和_arun方法实现更适合复杂的工具开发场景。定义完成之后通过实例化使用可以直接将实例传递给Agent或Chain进行调用使用起来既灵活又高效。复制代码import osfrom dotenv import load_dotenvfrom langchain.agents import create_agentfrom langchain.chat_models import init_chat_modelfrom langchain_core.tools import tool, BaseToolfrom langchain_community.tools import WriteFileTool, ReadFileTool, ListDirectoryToolload_dotenv()prefix “QWEN”model init_chat_model(model_provider“openai”,configurable_fields[“model”, “api_key”, “base_url”],config_prefixprefix).with_config({“configurable”: {f{prefix}_model: os.getenv(f{prefix}_MODEL),f{prefix}_api_key: os.getenv(f{prefix}_API_KEY),f{prefix}_base_url: os.getenv(f{prefix}_BASE_URL)}})class CalculateTool(BaseTool):name: str “calculate”description: str “计算数学表达式的值”def _run(self, expression: str) - str: try: return f计算结果: {eval(expression)} except Exception as e: return f计算错误: {str(e)} async def _arun(self, expression: str) - str: return self._run(expression) 初始化工具 calculate CalculateTool()write_file WriteFileTool()read_file ReadFileTool()list_dir ListDirectoryTool()agent create_agent(modelmodel,tools[calculate, write_file, read_file, list_dir],system_prompt“你是一个助手会用工具计算、读写文件、列出目录。”,debugTrue)queries [“计算 2024*12500然后把结果保存到 result.txt”,“读取 result.txt 的内容”,“列出当前目录文件”]for q in queries:print(f\n问{q}“)result agent.invoke({“messages”: [{“role”: “user”, “content”: q}]})print(f答{result[‘messages’][-1].content}”)复制代码