We then want our output to roughly follow the schema below:class Response(BaseModel):    """Final response to the question being asked"""    answer: str = Field(description = "The final answer to respond to the user")    sources: List[int] = Field(description="List of page chunks that contain answer to the question. Only include a page chunk if it contains relevant information")In this notebook we will go over an agent that has a retriever tool and responds in the correct format.Create the Retriever‚ÄãIn this section we will do some setup work to create our retriever over some mock data containing the "State of the Union" address. Importantly, we will add a "page_chunk" tag to the metadata of each document. This is just some fake data intended to simulate a source field. In practice, this would more likely be the URL or path of a document.from langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import Chromafrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.document_loaders import TextLoader# Load in document to retrieve overloader = TextLoader('../../state_of_the_union.txt')documents = loader.load()# Split document into chunkstext_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)texts = text_splitter.split_documents(documents)# Here is where we add in the fake source informationfor i, doc in enumerate(texts):    doc.metadata['page_chunk'] = i# Create our retrieverembeddings = OpenAIEmbeddings()vectorstore = Chroma.from_documents(texts, embeddings, collection_name="state-of-union")retriever = vectorstore.as_retriever()Create the tools‚ÄãWe will now create the tools we want to give to the agent. In this case, it is just one - a tool that wraps our retriever.from langchain.agents.agent_toolkits.conversational_retrieval.tool import create_retriever_toolretriever_tool = create_retriever_tool(    retriever,    "state-of-union-retriever",    "Query a retriever to get information about
This notebook covers how to have an agent return a structured output.
This notebook covers how to have an agent return a structured output. ->: We then want our output to roughly follow the schema below:class Response(BaseModel):    """Final response to the question being asked"""    answer: str = Field(description = "The final answer to respond to the user")    sources: List[int] = Field(description="List of page chunks that contain answer to the question. Only include a page chunk if it contains relevant information")In this notebook we will go over an agent that has a retriever tool and responds in the correct format.Create the Retriever‚ÄãIn this section we will do some setup work to create our retriever over some mock data containing the "State of the Union" address. Importantly, we will add a "page_chunk" tag to the metadata of each document. This is just some fake data intended to simulate a source field. In practice, this would more likely be the URL or path of a document.from langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import Chromafrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.document_loaders import TextLoader# Load in document to retrieve overloader = TextLoader('../../state_of_the_union.txt')documents = loader.load()# Split document into chunkstext_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)texts = text_splitter.split_documents(documents)# Here is where we add in the fake source informationfor i, doc in enumerate(texts):    doc.metadata['page_chunk'] = i# Create our retrieverembeddings = OpenAIEmbeddings()vectorstore = Chroma.from_documents(texts, embeddings, collection_name="state-of-union")retriever = vectorstore.as_retriever()Create the tools‚ÄãWe will now create the tools we want to give to the agent. In this case, it is just one - a tool that wraps our retriever.from langchain.agents.agent_toolkits.conversational_retrieval.tool import create_retriever_toolretriever_tool = create_retriever_tool(    retriever,    "state-of-union-retriever",    "Query a retriever to get information about