using System.Text.Json;using Agent.Core.ToolCalling;namespace Agent.Addons.Tools;/// <summary>Example addon tool — returns demo weather text (not a live API).</summary>public static class GetWeatherTool{ public const string Name = "get_weather"; public static void Register(ToolRegistry registry) { registry.Register(new AgentTool( Name, "Returns example weather for a city (demo addon; not a live forecast API).", Invoke, ParametersSchema, ToolCategory.Addon)); } private static object ParametersSchema => new { type = "object", properties = new { city = new { type = "string", description = "City or place name to describe weather for." } }, required = new[] { "city" } }; private static string Invoke(string argumentsJson) { string city = ParseCity(argumentsJson); if (string.IsNullOrWhiteSpace(city)) { return "Error: Provide a city name (JSON property \"city\")."; } int seed = city.GetHashCode(StringComparison.OrdinalIgnoreCase); string[] conditions = ["Sunny", "Partly cloudy", "Light rain", "Clear", "Overcast"]; string condition = conditions[Math.Abs(seed) % conditions.Length]; int tempC = 10 + (Math.Abs(seed) % 20); return $"Example weather for {city}: {condition}, about {tempC}°C (demo data from Agent-Addons)."; } private static string ParseCity(string argumentsJson) { try { using var doc = JsonDocument.Parse(argumentsJson); if (doc.RootElement.TryGetProperty("city", out var cityProp)) { return cityProp.GetString()?.Trim() ?? ""; } } catch (JsonException) { } return ""; }}