This is useful when you want to answer questions about a JSON blob that's too large to fit in the context window of an LLM. The agent is able to iteratively explore the blob to find what it needs to answer the user's question.In the below example, we are using the OpenAPI spec for the OpenAI API, which you can find here.We will use the JSON agent to answer some questions about the API spec.Initialization‚Äãimport osimport yamlfrom langchain.agents import create_json_agent, AgentExecutorfrom langchain.agents.agent_toolkits import JsonToolkitfrom langchain.chains import LLMChainfrom langchain.llms.openai import OpenAIfrom langchain.requests import TextRequestsWrapperfrom langchain.tools.json.tool import JsonSpecwith open("openai_openapi.yml") as f:    data = yaml.load(f, Loader=yaml.FullLoader)json_spec = JsonSpec(dict_=data, max_value_length=4000)json_toolkit = JsonToolkit(spec=json_spec)json_agent_executor = create_json_agent(    llm=OpenAI(temperature=0), toolkit=json_toolkit, verbose=True)Example: getting the required POST parameters for a request‚Äãjson_agent_executor.run(    "What are the required parameters in the request body to the /completions endpoint?")            > Entering new AgentExecutor chain...    Action: json_spec_list_keys    Action Input: data    Observation: ['openapi', 'info', 'servers', 'tags', 'paths', 'components', 'x-oaiMeta']    Thought: I should look at the paths key to see what endpoints exist    Action: json_spec_list_keys    Action Input: data["paths"]    Observation: ['/engines', '/engines/{engine_id}', '/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/engines/{engine_id}/search', '/files', '/files/{file_id}', '/files/{file_id}/content', '/answers', '/classifications', '/fine-tunes', '/fine-tunes/{fine_tune_id}', '/fine-tunes/{fine_tune_id}/cancel', '/fine-tunes/{fine_tune_id}/events', '/models', '/models/{model}', '/moderations']    Thought: I should look at the /completions
This notebook showcases an agent interacting with large JSON/dict objects.
This notebook showcases an agent interacting with large JSON/dict objects. ->: This is useful when you want to answer questions about a JSON blob that's too large to fit in the context window of an LLM. The agent is able to iteratively explore the blob to find what it needs to answer the user's question.In the below example, we are using the OpenAPI spec for the OpenAI API, which you can find here.We will use the JSON agent to answer some questions about the API spec.Initialization‚Äãimport osimport yamlfrom langchain.agents import create_json_agent, AgentExecutorfrom langchain.agents.agent_toolkits import JsonToolkitfrom langchain.chains import LLMChainfrom langchain.llms.openai import OpenAIfrom langchain.requests import TextRequestsWrapperfrom langchain.tools.json.tool import JsonSpecwith open("openai_openapi.yml") as f:    data = yaml.load(f, Loader=yaml.FullLoader)json_spec = JsonSpec(dict_=data, max_value_length=4000)json_toolkit = JsonToolkit(spec=json_spec)json_agent_executor = create_json_agent(    llm=OpenAI(temperature=0), toolkit=json_toolkit, verbose=True)Example: getting the required POST parameters for a request‚Äãjson_agent_executor.run(    "What are the required parameters in the request body to the /completions endpoint?")            > Entering new AgentExecutor chain...    Action: json_spec_list_keys    Action Input: data    Observation: ['openapi', 'info', 'servers', 'tags', 'paths', 'components', 'x-oaiMeta']    Thought: I should look at the paths key to see what endpoints exist    Action: json_spec_list_keys    Action Input: data["paths"]    Observation: ['/engines', '/engines/{engine_id}', '/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/engines/{engine_id}/search', '/files', '/files/{file_id}', '/files/{file_id}/content', '/answers', '/classifications', '/fine-tunes', '/fine-tunes/{fine_tune_id}', '/fine-tunes/{fine_tune_id}/cancel', '/fine-tunes/{fine_tune_id}/events', '/models', '/models/{model}', '/moderations']    Thought: I should look at the /completions