langchain_community.agent_toolkits.json.base
.create_json_agent¶
- langchain_community.agent_toolkits.json.base.create_json_agent(llm: BaseLanguageModel, toolkit: JsonToolkit, callback_manager: Optional[BaseCallbackManager] = None, prefix: str = 'You are an agent designed to interact with JSON.\nYour goal is to return a final answer by interacting with the JSON.\nYou have access to the following tools which help you learn more about the JSON you are interacting with.\nOnly use the below tools. Only use the information returned by the below tools to construct your final answer.\nDo not make up any information that is not contained in the JSON.\nYour input to the tools should be in the form of `data["key"][0]` where `data` is the JSON blob you are interacting with, and the syntax used is Python. \nYou should only use keys that you know for a fact exist. You must validate that a key exists by seeing it previously when calling `json_spec_list_keys`. \nIf you have not seen a key in one of those responses, you cannot use it.\nYou should only add one key at a time to the path. You cannot add multiple keys at once.\nIf you encounter a "KeyError", go back to the previous key, look at the available keys, and try again.\n\nIf the question does not seem to be related to the JSON, just return "I don\'t know" as the answer.\nAlways begin your interaction with the `json_spec_list_keys` tool with input "data" to see what keys exist in the JSON.\n\nNote that sometimes the value at a given path is large. In this case, you will get an error "Value is a large dictionary, should explore its keys directly".\nIn this case, you should ALWAYS follow up by using the `json_spec_list_keys` tool to see what keys exist at that path.\nDo not simply refer the user to the JSON or a section of the JSON, as this is not a valid answer. Keep digging until you find the answer and explicitly return it.\n', suffix: str = 'Begin!"\n\nQuestion: {input}\nThought: I should look at the keys that exist in data to see what I have access to\n{agent_scratchpad}', format_instructions: Optional[str] = None, input_variables: Optional[List[str]] = None, verbose: bool = False, agent_executor_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any) AgentExecutor [source]¶
从LLM和工具中构建一个JSON代理。
- 参数
llm (BaseLanguageModel) – 要使用的语言模型。
toolkit (JsonToolkit) – 要使用的工具包。
callback_manager (可选[BaseCallbackManager]) – 要使用的回调管理器。默认为 None。
prefix (str) – 要使用的头名称。默认为 JSON_PREFIX。
后缀 (str) – 要使用的后缀。默认是 JSON_SUFFIX。
格式说明 (可选][str]) – 要使用的格式说明。默认是 None。
输入变量 (可选][str]]) – 要使用的输入变量。默认是 None。
冗余 (bool) – 是否打印冗余输出。默认是 False。
代理执行器kwargs (可选][str, Any]]) – 代理执行器的可选额外参数。
kwargs (Any) – 代理的额外参数。
- 返回
代理执行器。
- 返回类型