Creating the tools
A tool is a function that an agent can use to carry out actions like calling external APIs or looking up information in a data source, as part of following the instructions defined in the prompt. We’ll need two tools: one to give it access to our data source with the general weather information, and one to give the weather agent the ability to query the Open-Meteo API for real-time weather data. We’ll create the former first.Before we create the tools, we need to create a service to which we can link them. You can use the sample code below.
weather_facts
data source that we created as its knowledge base.
- The “endpoint” object gives the agent details on what API endpoint to call and how to pass the parameters (in the body of a POST request).
- The “tool” object includes a description of the tool, which should be written as instructions to the agent regarding what the tool does. It also includes a “parameters” object, which describes the various parameters that the agent should gather from the user’s input and send to the API endpoint in the “endpoint” object.
- The “static parameters” object also describes parameters that should be sent to the API, but are predetermined at configuration time, rather than gathered by the agent from the user’s input.
Updating prompt to access tools
Now that we have our two tools, we can make them available to the prompt that we created earlier, so that any agents using that prompt will have access to the tools. We can use the promptsupdate
function to accomplish this.