langchain ZERO_SHOT_REACT运行逻辑

	ZERO_SHOT_REACT_DESCRIPTION
		代码逻辑
			1、initialize_agent函数
				langchain\agents\initialize.py
				ZeroShotAgent : from_llm_and_tools
					langchain\agents\mrkl\base.py
					Construct an agent from an LLM and tools
					prompt = cls.create_prompt
						Create prompt in the style of the zero shot agent.
						tools: Sequence[BaseTool],
						prefix: str = PREFIX,
						suffix: str = SUFFIX,
						将prefix、工具名称以及工具描述、suffix组装成prompt给LLMChain
					llm_chain = LLMChain 构建LLMChain
					_output_parser = output_parser or cls._get_default_output_parser()
				return AgentExecutor.from_agent_and_tools
			2、 run函数
				langchain\chains\base.py
				Chain :__call__函数: Execute the chain.
					AgentExecuter: _call
						langchain\agents\agent.py
						Run text through and get agent response
						while self._should_continue(iterations, time_elapsed) 通过该while循环
							_take_next_step
								_iter_next_step
									Take a single step in the thought-action-observation loop
									output = self.agent.plan
										Call the LLM to see what to do
										LLMChain : predict 
											langchain\chains\llm.py
											Format prompt with kwargs and pass to LLM
											Chain : __call__函数
												LLMChain:_call函数
													response = self.generate([inputs], run_manager=run_manager)
													Generate LLM result from inputs 将问题输入给LLM,获取LLM的结果

													生成的response的内容包括:
													text": " I need to find out the age of Yao Ming's wife first.\n
													Action: Search\n
													Action Input: \"Yao Ming's wife age
									执行工具,获取工具调用的结果
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值