Agent

🔹 2. Agent(智能体)

| 功能 | 自动决定是否调用工具,以及调用顺序 |
| 类型 | "zero-shot-react-description", "openai-functions", "chat-conversational-react-description" 等 |
| 推荐 | 初学者优先使用 "openai-functions" 类型 agent(支持 function-calling) |

示例(函数调用 Agent):

python 复制编辑 from langchain.agents import initialize_agent from langchain.chat_models import ChatOpenAI llm = ChatOpenAI(model="gpt-4") agent = initialize_agent( tools=tools, llm=llm, agent="openai-functions", verbose=True ) agent.run("What is the price of AAPL stock?")