mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-23 08:53:48 +00:00
Moved the background agents to AI operations (#1215)
This commit is contained in:
1 parent
8a4a26503b
commit
c50a93cd17
139 files changed
+4069
-2340
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace AIStudio.Tests.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Checks when the minimum confidence of a background task applies.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The text content cleaner, the data source selection, and the retrieval context validation apply their
|
||||
/// provider and their minimum only while their preselection is switched on, like the assistants. The audit
|
||||
/// of plugins has no such switch, so its minimum always applies. Names are written out in full where a short
|
||||
/// one would find a namespace of this assembly first, see AIOperationProviderResolverTests.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class BackgroundTaskMinimumConfidenceTests
|
||||
{
|
||||
[Test]
|
||||
public void TheTextContentCleanerAppliesItsMinimumOnlyWithItsPreselection()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
settingsManager.ConfigurationData.TextContentCleaner.MinimumProviderConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
AssertMinimumFollowsPreselection(settingsManager, AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, on => settingsManager.ConfigurationData.TextContentCleaner.PreselectAgentOptions = on);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheDataSourceSelectionAppliesItsMinimumOnlyWithItsPreselection()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
settingsManager.ConfigurationData.AgentDataSourceSelection.MinimumProviderConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
AssertMinimumFollowsPreselection(settingsManager, AIStudio.Tools.Components.AGENT_DATA_SOURCE_SELECTION, on => settingsManager.ConfigurationData.AgentDataSourceSelection.PreselectAgentOptions = on);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheRetrievalContextValidationAppliesItsMinimumOnlyWithItsPreselection()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
settingsManager.ConfigurationData.AgentRetrievalContextValidation.MinimumProviderConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
AssertMinimumFollowsPreselection(settingsManager, AIStudio.Tools.Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION, on => settingsManager.ConfigurationData.AgentRetrievalContextValidation.PreselectAgentOptions = on);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThePluginAuditAlwaysAppliesItsMinimum()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
settingsManager.ConfigurationData.AssistantPluginAudit.MinimumProviderConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
Assert.That(AIStudio.Tools.ComponentsExtensions.MinimumConfidence(AIStudio.Tools.Components.AGENT_ASSISTANT_PLUGIN_AUDIT, settingsManager), Is.EqualTo(ConfidenceLevel.HIGH), "The audit has no preselection switch, so nothing may turn its minimum off.");
|
||||
}
|
||||
|
||||
private static void AssertMinimumFollowsPreselection(SettingsManager settingsManager, AIStudio.Tools.Components component, Action<bool> setPreselection)
|
||||
{
|
||||
setPreselection(false);
|
||||
var minimumWithoutPreselection = AIStudio.Tools.ComponentsExtensions.MinimumConfidence(component, settingsManager);
|
||||
|
||||
setPreselection(true);
|
||||
var minimumWithPreselection = AIStudio.Tools.ComponentsExtensions.MinimumConfidence(component, settingsManager);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(minimumWithoutPreselection, Is.EqualTo(ConfidenceLevel.NONE), "With the preselection switched off, the stored minimum must not apply.");
|
||||
Assert.That(minimumWithPreselection, Is.EqualTo(ConfidenceLevel.HIGH));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a settings manager without the rust service, which reading a minimum never asks.
|
||||
/// </summary>
|
||||
private static SettingsManager CreateSettingsManager() => new(NullLogger<SettingsManager>.Instance, null!);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public sealed class ChatTemplateConfigurationTests
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(read.DataSourceOptions, Is.Not.Null);
|
||||
Assert.That(read.DataSourceOptions!.AutomaticDataSourceSelection, Is.True, "Letting an agent pick the sources is the one thing only a chat template can state, so it must not be lost on the way through Lua.");
|
||||
Assert.That(read.DataSourceOptions!.AutomaticDataSourceSelection, Is.True, "Letting an AI operation pick the sources is the one thing only a chat template can state, so it must not be lost on the way through Lua.");
|
||||
Assert.That(read.DataSourceOptions.PreselectedDataSourceIds, Is.Empty);
|
||||
Assert.That(read.ToolIds, Is.Null);
|
||||
}
|
||||
@@ -383,7 +383,7 @@ public sealed class ChatTemplateConfigurationTests
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(ChatTemplate.GetPreselectedLocalDataSourceNames(eriOnly, ConfiguredDataSources()), Is.Empty);
|
||||
Assert.That(ChatTemplate.GetPreselectedLocalDataSourceNames(agentic, ConfiguredDataSources()), Is.Empty, "An agent picks the sources per message, so this template names none to begin with.");
|
||||
Assert.That(ChatTemplate.GetPreselectedLocalDataSourceNames(agentic, ConfiguredDataSources()), Is.Empty, "An AI operation picks the sources per message, so this template names none to begin with.");
|
||||
Assert.That(ChatTemplate.GetPreselectedLocalDataSourceNames(NewTemplate(), ConfiguredDataSources()), Is.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace AIStudio.Tests.Settings;
|
||||
/// Either side can be filled in without knowing about the other, so all four combinations happen.
|
||||
/// The rule is deliberately the same for tools and for data sources: the chat template wins as a
|
||||
/// whole, because it is the only one of the two which can also leave the choice of sources to an
|
||||
/// agent, and a field-by-field mix of both would be something neither of them asked for.
|
||||
/// AI operation, and a field-by-field mix of both would be something neither of them asked for.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ChatTemplatePrecedenceTests
|
||||
@@ -115,7 +115,7 @@ public sealed class ChatTemplatePrecedenceTests
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(optionsChoice.Options!.AutomaticDataSourceSelection, Is.True, "Letting an agent pick the sources is the one thing a launcher cannot express, so it is exactly what must not be overwritten by one.");
|
||||
Assert.That(optionsChoice.Options!.AutomaticDataSourceSelection, Is.True, "Letting an AI operation pick the sources is the one thing a launcher cannot express, so it is exactly what must not be overwritten by one.");
|
||||
Assert.That(optionsChoice.Options.PreselectedDataSourceIds, Is.Empty);
|
||||
Assert.That(optionsChoice.LauncherChoiceDropped, Is.True);
|
||||
}
|
||||
|
||||
@@ -1,217 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace AIStudio.Tests.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which provider an agent is handed when nobody picked one for it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Agents such as the content cleaner or the security audit may be given a model of their own,
|
||||
/// because a small and cheap one is enough for what they do. Almost nobody does that, so what
|
||||
/// matters in practice is what happens when they have none: the model of the assistant they sit
|
||||
/// in, the app-wide default, or nothing at all. Two bugs shipped in that fallback, and both of
|
||||
/// them lived here rather than in the components -- which is why this is where they are pinned
|
||||
/// down. The component lifecycle itself is not covered; there is no bUnit in this solution.
|
||||
///
|
||||
/// Names are written out in full throughout. This assembly has an AIStudio.Tests.Tools and an
|
||||
/// AIStudio.Tests.Provider of its own, and the app has an AIStudio.Components -- all three are
|
||||
/// what a short name finds from here, and a using alias does not help, because names from the
|
||||
/// enclosing namespaces win over it.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class PreselectedProviderTests
|
||||
{
|
||||
private const string ASSISTANT_PROVIDER_ID = "11111111-1111-1111-1111-111111111111";
|
||||
private const string AGENT_PROVIDER_ID = "22222222-2222-2222-2222-222222222222";
|
||||
private const string APP_DEFAULT_PROVIDER_ID = "33333333-3333-3333-3333-333333333333";
|
||||
|
||||
[Test]
|
||||
public void ContentCleanerFallsBackToTheAssistantProvider()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, ASSISTANT_PROVIDER_ID, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(ASSISTANT_PROVIDER_ID), "With nothing configured for the cleaner, it has to use the model of the assistant around it.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentCleanerFallsBackToTheAppDefault()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, APP_DEFAULT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
settingsManager.ConfigurationData.App.PreselectedProvider = APP_DEFAULT_PROVIDER_ID;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, null, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(APP_DEFAULT_PROVIDER_ID), "Without an assistant model, the app-wide default is what is left before giving up.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentCleanerPrefersItsOwnProviderOverTheAssistantOne()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
settingsManager.ConfigurationData.TextContentCleaner.PreselectAgentOptions = true;
|
||||
settingsManager.ConfigurationData.TextContentCleaner.PreselectedAgentProvider = AGENT_PROVIDER_ID;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, ASSISTANT_PROVIDER_ID, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(AGENT_PROVIDER_ID), "A model picked for the cleaner is the whole point of picking one, so it outranks the assistant's.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks that the switch above the cleaner's provider field really turns that provider off.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The provider id stays in the settings when the switch goes off, so the only thing saying it
|
||||
/// must not be used is this one flag. A component which reads the stored id instead of asking
|
||||
/// here would keep using a provider the user switched away from.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void ContentCleanerIgnoresItsOwnProviderWhenPreselectionIsOff()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
settingsManager.ConfigurationData.TextContentCleaner.PreselectAgentOptions = false;
|
||||
settingsManager.ConfigurationData.TextContentCleaner.PreselectedAgentProvider = AGENT_PROVIDER_ID;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, ASSISTANT_PROVIDER_ID, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(ASSISTANT_PROVIDER_ID), "With its preselection switched off, the cleaner has to fall back to the assistant's model.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a model too untrusted for the cleaner is not used just because it is there.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is the case the user meets as a hint next to the cleaner switch: a model is selected in
|
||||
/// the assistant, and the cleaner still has none. Under TRUST_ALL every provider reaches MEDIUM
|
||||
/// and a self-hosted one reaches HIGH, so a global minimum of HIGH separates the two.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void ContentCleanerRejectsAnAssistantProviderBelowTheGlobalMinimum()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
settingsManager.ConfigurationData.Confidence.EnforceGlobalMinimumConfidence = true;
|
||||
settingsManager.ConfigurationData.Confidence.GlobalMinimumConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, ASSISTANT_PROVIDER_ID, true);
|
||||
|
||||
Assert.That(provider, Is.EqualTo(AIStudio.Settings.Provider.NONE), "A provider the organization ruled out must not reach the cleaner through the assistant.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentCleanerAcceptsAnAssistantProviderMeetingTheGlobalMinimum()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.SELF_HOSTED);
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
settingsManager.ConfigurationData.Confidence.EnforceGlobalMinimumConfidence = true;
|
||||
settingsManager.ConfigurationData.Confidence.GlobalMinimumConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_TEXT_CONTENT_CLEANER, ASSISTANT_PROVIDER_ID, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(ASSISTANT_PROVIDER_ID), "A provider which clears the bar has to be handed over, or the hint would never go away.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks that the audit agent's provider needs no switch to be used.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Unlike the content cleaner, the audit agent has no "preselect options" flag: an organization
|
||||
/// rolls its provider out and that is what audits run with. A test which assumed the two agents
|
||||
/// behaved alike would pass here for the wrong reason.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void AuditAgentUsesItsOwnProviderWithoutAPreselectionSwitch()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
AddProvider(settingsManager, APP_DEFAULT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
settingsManager.ConfigurationData.App.PreselectedProvider = APP_DEFAULT_PROVIDER_ID;
|
||||
settingsManager.ConfigurationData.AssistantPluginAudit.PreselectedAgentProvider = AGENT_PROVIDER_ID;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_ASSISTANT_PLUGIN_AUDIT, null, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(AGENT_PROVIDER_ID), "A provider rolled out for audits outranks the app-wide default.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AuditAgentFallsBackToTheAppDefault()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, APP_DEFAULT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
settingsManager.ConfigurationData.App.PreselectedProvider = APP_DEFAULT_PROVIDER_ID;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_ASSISTANT_PLUGIN_AUDIT, null, true);
|
||||
|
||||
Assert.That(provider.Id, Is.EqualTo(APP_DEFAULT_PROVIDER_ID), "Without a dedicated audit provider, the app-wide default is what audits run with.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the state the audit dialog was useless in before it offered a provider itself.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void AuditAgentEndsUpWithNothingWhenNeitherIsConfigured()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
AddProvider(settingsManager, AGENT_PROVIDER_ID, LLMProviders.MISTRAL);
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_ASSISTANT_PLUGIN_AUDIT, null, true);
|
||||
|
||||
Assert.That(provider, Is.EqualTo(AIStudio.Settings.Provider.NONE), "Two configured providers are not a choice: without one being named for audits, the agent has none.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AuditAgentRejectsAnAppDefaultBelowTheGlobalMinimum()
|
||||
{
|
||||
var settingsManager = CreateSettingsManager();
|
||||
AddProvider(settingsManager, ASSISTANT_PROVIDER_ID, LLMProviders.SELF_HOSTED);
|
||||
AddProvider(settingsManager, APP_DEFAULT_PROVIDER_ID, LLMProviders.OPEN_AI);
|
||||
settingsManager.ConfigurationData.App.PreselectedProvider = APP_DEFAULT_PROVIDER_ID;
|
||||
settingsManager.ConfigurationData.Confidence.EnforceGlobalMinimumConfidence = true;
|
||||
settingsManager.ConfigurationData.Confidence.GlobalMinimumConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
var provider = settingsManager.GetPreselectedProvider(AIStudio.Tools.Components.AGENT_ASSISTANT_PLUGIN_AUDIT, null, true);
|
||||
|
||||
Assert.That(provider, Is.EqualTo(AIStudio.Settings.Provider.NONE), "The app-wide default is not exempt from what the organization enforces.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a settings manager the way these tests need it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The rust service is handed in as null on purpose: resolving a provider never asks it
|
||||
/// anything. It reads the configured providers, the confidence scheme and the preselections,
|
||||
/// all of which are plain settings. Should that change, the test says so by failing loudly
|
||||
/// rather than by quietly measuring something else.
|
||||
/// </remarks>
|
||||
private static SettingsManager CreateSettingsManager() => new(NullLogger<SettingsManager>.Instance, null!);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a provider to the settings.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every test here configures at least two of them, and not for variety: with exactly one
|
||||
/// configured provider, resolving takes a shortcut and returns it without looking at any
|
||||
/// preselection. A single-provider test would pass no matter what the fallback does.
|
||||
/// </remarks>
|
||||
private static void AddProvider(SettingsManager settingsManager, string id, LLMProviders llmProvider)
|
||||
{
|
||||
var providers = settingsManager.ConfigurationData.Providers;
|
||||
providers.Add(new((uint)providers.Count + 1, id, $"Instance {providers.Count + 1}", llmProvider, new("test-model", null)));
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace AIStudio.Tests.Settings;
|
||||
/// <remarks>
|
||||
/// The settings are reached through Program.SERVICE_PROVIDER, as in the app, because a managed
|
||||
/// setting writes its value and its lock there. Names are written out in full where a short one
|
||||
/// would find a namespace of this assembly first, see PreselectedProviderTests.
|
||||
/// would find a namespace of this assembly first, see AIOperationProviderResolverTests.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ProhibitedProvidersTests
|
||||
|
||||
Reference in new issue
Block a user