Normandy.Tools.Examples.Weather behaviour
(normandy v0.6.0)
View Source
A weather tool that fetches current weather data from Open-Meteo API.
This tool is designed for integration testing to verify actual tool usage, as models cannot know real-time weather data and must use the tool.
Examples
iex> {:ok, weather} = Weather.validate(%{city: "San Francisco"})
iex> Normandy.Tools.BaseTool.run(weather)
{:ok, "Temperature: 15.2°C, Conditions: Clear sky"}API
Uses the free Open-Meteo API (https://open-meteo.com/) which requires no API key.
Summary
Callbacks
Executes the tool with validated inputs.
Functions
Executes the weather tool by fetching current weather from Open-Meteo API.
Validates input parameters against the tool's schema.
Validates and raises on error.
Callbacks
Executes the tool with validated inputs.
This function must be implemented by the tool. It receives a validated struct with all fields populated according to the schema.
Returns {:ok, result} on success or {:error, reason} on failure.
Examples
@impl Normandy.Tools.SchemaBaseTool
def execute(%__MODULE__{operation: "add", a: a, b: b}) do
{:ok, a + b}
end
def execute(%__MODULE__{operation: "divide", a: _a, b: 0}) do
{:error, "Division by zero"}
end
Functions
Executes the weather tool by fetching current weather from Open-Meteo API.
Validates input parameters against the tool's schema.
Returns {:ok, struct} on success or {:error, errors} on validation failure.
Examples
iex> Elixir.Normandy.Tools.Examples.Weather.validate(%{operation: "add", a: 5, b: 3})
{:ok, %Elixir.Normandy.Tools.Examples.Weather{operation: "add", a: 5, b: 3}}
iex> Elixir.Normandy.Tools.Examples.Weather.validate(%{operation: "invalid"})
{:error, [%{path: [:a], message: "is required", constraint: :required}]}
Validates and raises on error.
Returns the validated struct or raises Normandy.Schema.ValidationError.