namespace AIStudio.Tools.ToolCallingSystem;
///
/// The rule which tells the model to search the web first, for a tool which may end web search.
///
///
/// Once internal content enters a chat, it is no longer offered web search, see
/// ToolSelectionRules.IsOutboundDataAllowed. A model which does not know that reads the internal
/// content first and finds the search gone when it needs it. Only the tool which brings the
/// content in knows when it does, so each one adds the rule to its own instructions, and this
/// class words it once for all of them.
/// The rule belongs only into a request which offers web search: a rule about a tool the model
/// does not get would only confuse it. Once the search is gone, nothing repeats it. A call of the
/// search in the same request is refused with a text which names the source and says that a new
/// chat without this content can search again, see OutboundDataRequirementExtensions.GetToolBlockedMessage, and the
/// tool selection shows the user the same text.
///
internal static class WebSearchFirstRule
{
///
/// Whether the request may offer web search, so the rule has a search to protect.
///
/// The request, or null when the registered instructions are worded, which assume web search.
/// True when the rule belongs into the instructions.
internal static bool AppliesTo(ToolResolutionContext? context) => context?.MayOffer(ToolSelectionRules.WEB_SEARCH_TOOL_ID) ?? true;
///
/// Words the rule as a further line of the instructions of a tool.
///
/// What takes web search away, up to its verb, such as "A search makes".
/// What the model does with the tool, such as "search the wiki".
/// The line, starting with a line break.
internal static string Build(string cause, string action) => $"""
- {cause} `web_search` unavailable for the rest of this chat. When a task needs `web_search` as well, search the web before you {action}.
""";
}