developer.chat
10 May 2023
SEO Title
基于LLM的代理通过访问其可支配的LLM和工具来维护自主权
关于代理的更多信息
LangChain代理在一套可用工具的上下文中是自主的。现在,您可以通过使用LangFlow在GUI中构建LangChain代理。
LangChain代理在收到请求时会使用各种操作。采取行动后,代理人进入观察步骤,在那里他们分享一个想法。如果未达到最终答案,Agent会循环返回以选择不同的操作,以便更接近最终答案。
代理之所以有吸引力,是因为他们能够独立行动,不走预先确定的道路。
他们配备了一套工具,使他们能够响应这些工具范围内的任何请求。
这个执行管道使代理能够独立地解决问题,可能需要多次迭代,直到达到所需的结果。
使用LangFlow构建简单代理
一开始,通过亲代码的方法构建LangChain代理可能看起来令人望而生畏且抽象。然而,LangFlow在很大程度上揭开了这个过程的神秘面纱。
下面您可以看到用于构建Agent的六个组件。
- ZeroShotPrompt组件包含提示模板,本文稍后将对此进行详细讨论。
- OpenAI组件包含型号名称、温度设置和API键。
- LLM Chain组件仅将Prompt和LLM与Agent连接起来。代理有两个工具可以在这种情况下使用,即PAL-MATH和Search。
在这个例子中,你可以看到一个模糊而复杂的问题被提出给代理人:iPhone父亲的出生年份的平方根是多少(What is the square root of the birth year of the father of the iPhone?)。
答案已经给出,点击聊天气泡,显示代理的思维链推理。
For a detailed high resolution video of the flow, click here.
详细的思维链推理:
> Entering new AgentExecutor chain... I need to figure out the father of the iPhone and the year of his birth. Action: Search Action Input: "Father of the iphone" Observation: Steve Jobs ; Pioneer of the personal computer revolution with Steve Wozniak; Co-creator of the Apple II, Macintosh, iPod, iPhone, iPad, and first Apple Stores. Thought: I now need to find the year of birth of Steve Jobs Action: Search Action Input: "Steve Jobs birth year" Observation: February 24, 1955 Thought: I now need to find the square root of 1955 Action: PAL-MATH Action Input: "What is the square root of 1955?" Observation: name 'math' is not defined Thought: I need to use a different language model Action: PAL-MATH Action Input: "What is the square root of one thousand nine hundred and fifty-five?" Observation: 44.21538193886829 Thought: I now know the final answer Final Answer: The square root of the year of birth of the father of the iphone is 44.21538193886829. > Finished chain.
提示组件中使用的提示模板,带有前缀、后缀和说明。
提示前缀:
Answer the following questions as best you can. You have access to the following tools:
Prompt Suffix:
Begin! Question: {input} Thought:{agent_scratchpad}
提示说明:
Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [{tool_names}] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can repeat N times) Thought: I now know the final answer Final Answer: the final answer to the original input question
搜索是通过SerpApi作为一种工具添加的,如下所示。
交割时
即使在问题不明确并且需要多跳方法的情况下,代理也是有效的。这可以被认为是一个将复杂的问题或指令分解为思维链过程的自动化过程。
- 登录 发表评论