langchain.agents.mrkl.base.ZeroShotAgent¶
- class langchain.agents.mrkl.base.ZeroShotAgent[源代码]¶
- 基础: - Agent- 自版本 0.1.0 已弃用: 请使用 - create_react_agent代替。- MRKL 链的代理。 - 参数
- output_parser – 代理的输出解析器。 
 - 通过解析和验证关键字参数中的输入数据来创建新模型。 - 如果输入数据无法解析成有效模型,则引发 ValidationError。 - paramallowed_tools:Optional[List[str]] = None¶
- 允许代理使用的工具。如果为 None,则允许所有工具。 
 - paramllm_chain [必需]¶
- 用于代理的 LLMChain。 
 - paramoutput_parser:AgentOutputParser [可选]¶
- 用于代理的输出解析器。 
 - async aplan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]], **kwargs: Any) Union[AgentAction, AgentFinish]¶
- 异步给定输入,决定要做什么。 - 参数
- intermediate_steps (列表[Tuple[AgentAction, str]]) – LLM至今为止采取的步骤以及观测结果。 
- callbacks (可选[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 要执行的回调。 
- **kwargs (任何) – 用户输入。 
 
- 返回
- 指定使用哪个工具的动作。 
- 返回类型
- Union[AgentAction, AgentFinish] 
 
 - classmethod create_prompt(tools: Sequence[BaseTool], prefix: str = 'Answer the following questions as best you can. You have access to the following tools:', suffix: str = 'Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}', format_instructions: str = 'Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', input_variables: Optional[List[str]] = None) PromptTemplate[source]¶
- 按零样本代理的风格创建提示。 - 参数
- tools (Sequence中的BaseTool) – 代理将能够访问的工具列表,用于格式化提示。 
- prefix (str) – 将要放在工具列表之前的字符串。默认为 PREFIX。 
- 后缀 (str) – 要添加到工具列表之后的字符串。默认为 SUFFIX。 
- 格式说明 (str) – 关于如何使用工具的说明。默认为 FORMAT_INSTRUCTIONS。 
- 输入变量 (可选[字符串列表]) – 最终提示将期望的输入变量列表。默认为 None。 
 
- 返回
- 由这里的片段组装而成的 PromptTemplate。 
- 返回类型
 
 - classmethod from_llm_and_tools(llm: BaseLanguageModel, tools: Sequence[BaseTool], callback_manager: Optional[BaseCallbackManager] = None, output_parser: Optional[AgentOutputParser] = None, prefix: str = 'Answer the following questions as best you can. You have access to the following tools:', suffix: str = 'Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}', format_instructions: str = 'Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', input_variables: Optional[List[str]] = None, **kwargs: Any) Agent[source]¶
- 从 LLM 和工具构建智能体。 - 参数
- llm (BaseLanguageModel) – 作为智能体 LLM 使用的 LLM。 
- tools (工具序列) – 要使用的工具。 
- callback_manager (可选[BaseCallbackManager]) – 要使用的回调管理器。默认为 None。 
- output_parser (可选[AgentOutputParser]) – 要使用的输出解析器。默认为 None。 
- 前缀 (str) – 要使用的前缀。默认为 PREFIX。 
- 后缀 (str) – 要使用的后缀。默认为 SUFFIX。 
- 格式说明 (str) – 要使用的格式说明。默认为 FORMAT_INSTRUCTIONS。 
- 输入变量 (可选[字符串列表]) – 要使用的输入变量。默认为 None。 
- kwargs (任何类型) – 要传给智能体的额外参数。 
 
- 返回类型
 
 - get_allowed_tools() Optional[字符串列表]¶
- 获取允许使用的工具。 - 返回类型
- 可选[字符串列表] 
 
 - get_full_inputs(intermediate_steps: 中间步骤列表: List[Tuple[, str]], **kwargs: 任何类型) Dict[str, 任何类型]¶
- 从中间步骤创建 LLMChain 的完整输入。 - 参数
- intermediate_steps (列表[Tuple[AgentAction, str]]) – LLM至今为止采取的步骤以及观测结果。 
- **kwargs (任何) – 用户输入。 
 
- 返回
- LLMChain 的完整输入。 
- 返回类型
- Dict[str, 任何类型] 
 
 - plan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) Union[AgentAction, AgentFinish]¶
- 给定的输入,决定要做什么。 - 参数
- intermediate_steps (列表[Tuple[AgentAction, str]]) – LLM至今为止采取的步骤以及观测结果。 
- callbacks (可选[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 要执行的回调。 
- **kwargs (任何) – 用户输入。 
 
- 返回
- 指定使用哪个工具的动作。 
- 返回类型
- Union[AgentAction, AgentFinish] 
 
 - return_stopped_response(early_stopping_method: str, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any) AgentFinish¶
- 当智能体因最大迭代次数而停止时返回响应。 - 参数
- early_stopping_method (str) – 使用早期停止的方法。 
- intermediate_steps (列表[Tuple[AgentAction, str]]) – LLM至今为止采取的步骤以及观测结果。 
- **kwargs (任何) – 用户输入。 
 
- 返回
- 智能体完成对象。 
- 返回类型
- 抛出异常
- ValueError – 如果 early_stopping_method 不在 [‘force’, ‘generate’] 范围内。 
 
 - save(file_path: Union[Path, str]) None¶
- 保存代理。 - 参数
- file_path (Union[Path, str]) – 要保存代理的文件路径。 
- 返回类型
- None 
 - 示例: .. code-block:: python - 若与代理执行器协同使用,则使用:agent.agent.save(file_path="path/agent.yaml") 
 - tool_run_logging_kwargs() Dict¶
- 返回工具运行的日志参数。 - 返回类型
- Dict 
 
 - property llm_prefix: str¶
- 附加到 llm 调用的前缀。 - 返回
- 返回类型
- “Thought” 
 
 - property observation_prefix: str¶
- 附加到观测值的前缀。 - 返回
- 返回类型
- “Observation” 
 
 - property return_values: List[str]¶
- 代理的返回值。