ai
and zod
installed.
Install ai sdk and zod
tool
and stepCountIs
from ai
and import zod
.
Note: you probably already imported streamText
and ModelMessage
streamResponse
in the case of a message received, initialize a tool. For instance, weather
streamText
You should also set these properties
Next steps: telling the user that tool calling is happening
One thing many many developers wish to do is update the user that tool calling is happening so they don’t expect an immediate response. To do this, your tools can notify the client that there is a tool call happening. This guide will show you how you can do that.Sending speech to the user to tell them a call is happening.
If you anticipate a long tool call, you may want to send a spoken message to them, such as “just a moment, let me grab that for you.”. With ai sdk, you can do that by calling Layercode’s stream.tts at the start of yourexecute
function.
Note that the tool must be defined inside your Layercode streamResponse callback function so that it has access to stream
.