๐ Create agent tools
The easiest way to define custom tools for agents in LangChain is using the @tool
decorator. The decorator makes tools out of functions by using the function name as the tool name by default, and the function's docstring as the tool's description.
We want the documentation agent to have access to the following tools:
-
get_information_for_question_answering
: Uses vector search to retrieve information to answer questions -
get_page_content_for_summarization
: Gets the content of specific document pages for summarization
Fill in any <CODE_BLOCK_N>
placeholders and run the cells under the Step 4: Create agent tools section in the notebook to create tools for the agent to use.
The answers for code blocks in this section are as follows:
CODE_BLOCK_5
Answer
embedding_model.encode(text)
CODE_BLOCK_6
Answer
get_embedding(user_query)
CODE_BLOCK_7
Answer
[
{
"$vectorSearch": {
"index": VS_INDEX_NAME,
"path": "embedding",
"queryVector": query_embedding,
"numCandidates": 150,
"limit": 5,
}
},
{
"$project": {
"_id": 0,
"body": 1,
"score": {"$meta": "vectorSearchScore"},
}
},
]
CODE_BLOCK_8
Answer
vs_collection.aggregate(pipeline)
CODE_BLOCK_9
Answer
{"title": user_query}
CODE_BLOCK_10
Answer
{"_id": 0, "body": 1}
CODE_BLOCK_11
Answer
full_collection.find_one(query, projection)