为什么代理不是连锁?

问题描述 投票:0回答:1

浪链中有两个概念:

  1. 链条
  2. 代理

建议使用代理的流程是:

prompt = SomePrompt()
llm_chain: Chain = LLMChain(prompt)
tools = [...]
agent: Agent = SomeAgent(llm_chain, tools)
agent_executor: Chain = AgentExecutor(agent)

将Agent作为一个单独的类而不是继承Chain类的原因是什么?

为什么我们需要将

llm_chain: Chain
包裹在
agent: Agent
里面
agent_executor: Chain

预期的架构是:

class Agent(Chain):
   def _call(self, *args, **kwargs):
      while True:
         action = self.plan()
         if isinstance(action, ActionTool):
            self.run_tool(plan)
         elif isinstance(action, ActionFinish):
            return action.result

   def plan():
      # as it is done in actual implementation of Agent
      pass
          

但我不明白为什么我们要分开

AgentExecutor
Agent

python architecture open-source langchain py-langchain
1个回答
0
投票

答案可能就像代理文档中的引用一样简单

代理的核心思想是使用语言模型来选择要采取的一系列操作。在链中,一系列操作被硬编码(在代码中)。在代理中,语言模型被用作推理引擎来确定要采取哪些操作以及按什么顺序。 (来源

© www.soinside.com 2019 - 2024. All rights reserved.