using System.Text.Json; using AIStudio.Tools.PluginSystem; namespace AIStudio.Tools.ToolCallingSystem; public interface IToolImplementation { public string ImplementationKey { get; } /// /// Describes this tool: what the model may call, which settings it needs, and where it may /// be used. /// /// /// For a tool written in C#, the definition and the implementation are one object. Tools that /// arrive from elsewhere — a plugin, an assistant — get their definition from their own /// definition source instead, and are matched to an implementation by their implementation key. /// public ToolDefinition GetDefinition(); public string Icon => Icons.Material.Filled.Build; public IReadOnlySet SensitiveTraceArgumentNames { get; } /// /// Whether this tool returns content it fetched from outside AI Studio, such as a web page. /// /// /// Such content is attacker-controlled and must be filtered for prompt injections before a /// model sees it. A tool that returns it filters it itself, because only the tool knows which /// of its fields came from where — see the web search and read web page tools, which do so /// through the web page content sanitizer.

/// Declaring it here keeps the obligation visible in one place, and gives tools that cannot /// carry it out themselves, such as tools defined by plugin authors, a flag the tool executor /// can act on for them. ///
public bool ReturnsUntrustedExternalContent => false; public string GetDisplayName() => TB("Tool"); public string GetDescription() => TB("Tool description"); public string GetSettingsFieldLabel(string fieldName, ToolSettingsFieldDefinition fieldDefinition) => TB(fieldDefinition.Title); public string GetSettingsFieldDescription(string fieldName, ToolSettingsFieldDefinition fieldDefinition) => TB(fieldDefinition.Description); public string? GetSettingsFieldDefaultValue(string fieldName, ToolSettingsFieldDefinition fieldDefinition) => null; /// /// The heading shown above one group of settings. /// /// /// The group name in the schema is an identifier, so it is not what the user should read. /// A tool that declares groups translates their headings here, the same way it does for /// its field labels. /// public string GetSettingsGroupLabel(string groupKey) => groupKey; /// /// Links offered next to one group of settings, such as where to create an account. /// public IReadOnlyList GetSettingsGroupLinks(string groupKey) => []; /// /// Whether one settings field is worth showing, given what is filled in at the moment. /// /// /// For a setting that only has a meaning once something else is set, such as choosing /// between services while only one of them is configured. It is asked again after every /// change in the dialog, so a field can appear the moment it starts to matter.

/// A hidden field keeps its stored value, because hiding it is not clearing it. Two things /// follow from that: a required field must never be hidden, and a check on a hidden field /// must not be able to fail, or the user is left with a message about something they /// cannot see. ///
public bool IsSettingsFieldVisible(string fieldName, IReadOnlyDictionary settingsValues) => true; /// /// What the user should know about their settings without any of it being wrong. /// /// /// For a combination that is allowed, saveable, and does less than it looks like it does: /// something configured that a policy then keeps out of use, for instance. A setting that is /// actually wrong belongs in the configuration state instead, which is what stops the dialog /// from saving it.

/// Asked again after every change in the dialog, like the field visibility, so a warning /// appears and disappears with the value it is about. ///
public IReadOnlyList GetSettingsWarnings(IReadOnlyDictionary settingsValues) => []; public Task ValidateConfigurationAsync( ToolDefinition definition, IReadOnlyDictionary settingsValues, CancellationToken token = default) => Task.FromResult(null); public Task ExecuteAsync(JsonElement arguments, ToolExecutionContext context, CancellationToken token = default); private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(IToolImplementation).Namespace, nameof(IToolImplementation)); }