Tools
Open core/tools.ts
. You should see the following code already:
Define a tool called weather.
Provide a description for the tool.
Note: the description is very important because it is what the model will use to decide whether or not to use the tool.
Import Zod and define a Zod schema that describes the parameters necessary for the tool to run. Pass this schema to the parameters
key.
Note: you can optionally describe your parameters using the .describe
function. This will ensure the model has the appropriate context to produce a great generation.
Define an execute function.
Note: This is the function that will be run if the model decides to use the tool.
Check if the model called the tool.
Note: the SDK will not automatically send the Tool result to another model call to summarise.
Import and call streamText
passing in the users' location and the weather of their current location (toolResult
).
Finally, iterate over the resulting textStream
and write it to the console.
Run the script in the terminal, and see what happens.