In the {lab-folder}/tools/index.ts
file, you will find an initTools()
function.
This function provides an array of tools for the agent to use.
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/modules/agent/tools/index.ts[tag=function]
Modify the function to return the Cypher Retrieval and Vector Retrieval tools along with appropriate descriptions for how the agent should use them.
Cypher Retrieval Chain
First, use the initCypherRetrievalChain()
function to create an instance of the Cypher Retrieval Tool.
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/solutions/modules/agent/tools/index.ts[tag=cypherchain,indent=0]
Append a new instance of the DynamicStructuredTool
to the return array.
Use the object passed to the constructor to give the tool the name graph-cypher-retrieval-chain
and provide instructions for retrieving advanced movie information.
return [
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/solutions/modules/agent/tools/index.ts[tag=cypher]
]
Vector Retrieval Chain
Next, use the initVectorRetrievalChain()
function to create an instance of the Vector Retrieval Tool.
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/solutions/modules/agent/tools/index.ts[tag=retrievalchain,indent=0]
Append a new instance of the DynamicStructuredTool
to the return array.
Use the object passed to the constructor to give the tool the name graph-vector-retrieval-chain
and provide instructions to use the tool when comparing movies by plot.
return [
// ...
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/solutions/modules/agent/tools/index.ts[tag=vector]
]
Completed code
Your implemented function should resemble the following:
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/solutions/modules/agent/tools/index.ts[tag=function]
Testing your changes
If you have followed the instructions, you should be able to run the following unit test to verify the response using the npm run test
command.
npm run test tools.test.ts
View Unit Test
Unresolved directive in ../../../../includes/test.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/modules/agent/tools/tools.test.ts[]
It works!
Once the tests have passed, hit the button below to mark the lesson as completed.
Summary
In this lesson, you implemented a function that creates a set of tools that the agent can use to perform specific tasks.
In the next lesson, you will create an agent and use this function to register these tools.