ANTHROPIC_API_KEY
and EXA_API_KEY
for Anthropic and Exa keys respectively.
ExaSearchRetriever
. This tool (read more here) will help retrieve relevant documents based on a query.
First we need to import the required libraries:
tool
decorator which you can read more about here. The decorator uses the function name as the tool name. The docstring provides the agent with a tool description.
The retriever
is where we initialize the Exa search retriever and configure it with parameters such as highlights=True
. You can read more about all the available parameters here.
ExaSearchRetriever
is set to fetch 3 documents.
Then we use LangChain’s PromptTemplate
to structure the results from Exa in a more AI friendly way. Creating and using this template is optional, but recommended. Read more about PromptTemplate (here.
We also use a RunnableLambda to extract necessary metadata (like URL and highlights) from the search results and format it using the prompt template.
After all of this we start the retrieval and processing chain and store the results in the documents
variable which is returned.