微信扫码
添加专属顾问
我要投稿
LangChain 1.0 Alpha重磅发布,统一Agent抽象让开发更高效稳定,企业级应用迎来新选择。 核心内容: 1. 统一代理抽象:简化开发流程,一行代码实现复杂功能 2. 标准输出格式:新增content_blocks属性解决LLM提供商差异 3. 企业级稳定性:1.0版本提升可靠性,降低企业采用风险
LangChain 自推出以来迅速成为开发者构建 LLM 驱动应用的重要框架之一,支持多种链(chains)、代理(Agents)、工具调用、向量检索、模型接口等功能。其生态不断壮大,但也因模式多样、抽象纷繁导致开发者面对不同 “agent 模式” 时感到困惑。为提升一致性、可维护性与企业级稳定性,LangChain 在 2025 年 9 月推出了 v1.0.0 Alpha,与 LangGraph 一起迈入 1.x 版本演进。
content_blocks
属性,用以统一 reasoning、工具调用、引用、媒体类型等新 API 特性create_agent
过去要实现“调用工具 → 整理结果 → 输出结构化 JSON”,要手写 chain,现在一行搞定:
from langchain.agents import create_agent
from langchain_core.messages import HumanMessage
from pydantic import BaseModel
class WeatherInfo(BaseModel):
city: str
temperature_c: float
condition: str
def fake_weather(city: str) -> str:
returnf"25,Sunny"if city == "Singapore"else"18,Rainy"
agent = create_agent(
model="openai:gpt-4o-mini",
tools=[fake_weather],
response_format=WeatherInfo
)
res = agent.invoke({"messages": [
HumanMessage("What's the weather like in Singapore?")
]})
print(res["structured_response"])
# WeatherInfo(city='Singapore', temperature_c=25.0, condition='Sunny')
create_agent
的预设配置。LangGraph
作为执行引擎,暴露标准接口:invoke(input: dict) -> dict
。{"messages": List[BaseMessage]}
{"messages": List[BaseMessage], "structured_response": Optional[BaseModel]}
content_blocks
所有 AIMessage
新增 .content_blocks: List[ContentBlock]
属性。
class TextBlock(ContentBlock):
text: str
class ToolCallBlock(ContentBlock):
name: str
args: dict
class CitationBlock(ContentBlock):
sources: List[Source]
class ImageBlock(ContentBlock):
mime_type: str
data: bytes
function_call
→ ToolCallBlock
<thinking>
→ TextBlock
+ reasoning=True
ToolCallBlock
ImageBlock.data
仅在访问时解码。create_agent
返回的 agent 本质是一个编译后的 LangGraph
实例。
GraphState
。自定义重试逻辑:
from langgraph.graph import StateGraph
def tool_node(state):
try:
result = tool.invoke(state["input"])
return {"result": result, "error": None}
except Exception as e:
return {"result": None, "error": str(e)}
def should_retry(state):
if state["error"] and state["retry_count"] < 3:
return"tool_node"
else:
return"end_node"
graph = StateGraph(AgentState)
graph.add_node("tool_node", tool_node)
graph.add_conditional_edges("tool_node", should_retry)
langchain.* | langchain.* | |
langchain.index | langchain-legacy | |
AgentExecutor | langchain-legacy |
create_agent
+ content_blocks
。langchain-legacy
保持兼容。initialize_agent(..., AgentType.REACT...)
→ create_react_agent(...)
(兼容层)。create_agent(...)
。BaseMessage.text()
→ .text
(属性)AIMessage
,非 str
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-09-06
沧海独家:LangChain 1.0 Alpha 架构重构全解析
2025-08-30
LangChain如何使用通义千问的向量模型
2025-08-29
Claude code prompt原来这么写的,怪不得这么厉害
2025-08-27
从LangChain到LangGraph:AI智能体提示词工程的系统化学习
2025-08-25
Agent实战教程:LangGraph相关概念介绍以及快速入门
2025-08-23
企业级复杂任务智能体构建:解锁LangChain新品Deep Agents及其UI利器
2025-08-20
使用LLamaIndex Workflow来打造水墨风格图片生成工作流
2025-08-19
让 LangChain 知识图谱抽取更聪明:BAML 模糊解析助力升级
2025-07-14
2025-06-26
2025-07-14
2025-07-16
2025-06-16
2025-08-19
2025-06-26
2025-08-17
2025-06-16
2025-06-24
2025-07-14
2025-07-13
2025-07-05
2025-06-26
2025-06-13
2025-05-21
2025-05-19
2025-05-08