初识智能体(【Cherry-Studio、ima】搭建个人知识库+【Cherry-Studio、豆包平台、星火平台】创建智能体+【Cline、Coze、Dify】创建智能体)
国内大模型厂家推出的智能体,以及智能体的应用领域、智能体架构fromlangchain.agentsimportcreate_agentfromlangchain_community.chat_models.tongyiimportChatTongyifromlangchain_core.toolsimporttool""" 通过create_agent方法创造的Agent对象,其也是Runnable接口的子类实现 invoke,执行,一次性得到结果 stream,执行,流式得到结果 """agent=create_agent(model=ChatTongyi(model="qwen3-max"),tools=[get_weather],system_prompt="你是一个聊天助手,可以回答用户问题。")# 一次性得到结果res=agent.invoke({"messages":[{"role":"user","content":"明天深圳天气如何?"}]})# print(res)formsginres["messages"]print(type(msg).__name__,msg.content)# 流式得到结果dict_message={"messages":[{"role":"user","content":"Search for AI news and summarize the findings"}]}forchunkinagent.stream(dict_message,stream_mode="values"):# 每个块都包含该时刻的完整状态,所以取最后一条,即为最新latest_message=chunk["messages"]["-1"]iflatest_message.content:print(f"Agent:{latest_message.content}")eliflatest_message.tool_calls:print(f"Calling tooos: