浪链中有两个概念:
建议使用代理的流程是:
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
答案可能就像代理文档中的引用一样简单
代理的核心思想是使用语言模型来选择要采取的一系列操作。在链中,一系列操作被硬编码(在代码中)。在代理中,语言模型被用作推理引擎来确定要采取哪些操作以及按什么顺序。 (来源)