Added tool calling support (#731)

Co-authored-by: krut_ni <nils.kruthoff@dlr.de>
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-09-04 15:48:07 +02:00
1 parent b00c3f9ab3
commit 4d8d30e15e
266 files changed
+11186 -740

No files matched your search

@@ -106,7 +106,9 @@ else
<ConfigurationMinConfidenceSelection Disabled="@(() => this.IsNoPolicySelectedOrProtected)" RestrictToGlobalMinimumConfidence="true" SelectedValue="@(() => this.policyMinimumProviderConfidence)" SelectionUpdateAsync="@(async level => await this.PolicyMinimumConfidenceWasChangedAsync(level))" />
<ConfigurationProviderSelection Component="Components.DOCUMENT_ANALYSIS_ASSISTANT" Data="@this.availableLLMProviders" Disabled="@(() => this.IsNoPolicySelectedOrProtected)" SelectedValue="@(() => this.policyPreselectedProviderId)" SelectionUpdate="@(providerId => this.PolicyPreselectedProviderWasChanged(providerId))" ExplicitMinimumConfidence="@this.GetPolicyMinimumConfidenceLevel()"/>
<ToolSelectionField Component="@this.Component" SelectedToolIds="@this.policyAllowedToolIds" SelectedToolIdsChanged="@this.PolicyAllowedToolsWasChangedAsync" Disabled="@this.IsNoPolicySelectedOrProtected" Label="@T("Tools this policy permits")" Help="@T("Only the tools selected here can be used by the AI for an analysis with this policy. Every tool still has to meet the confidence requirements of the selected provider, so a tool may remain unavailable even when this policy permits it.")"/>
<ConfigurationProviderSelection Component="Components.DOCUMENT_ANALYSIS_ASSISTANT" Data="@this.availableLLMProviders" Disabled="@(() => this.IsNoPolicySelectedOrProtected)" SelectedValue="@(() => this.policyPreselectedProviderId)" SelectionUpdate="@this.PolicyPreselectedProviderWasChanged" ExplicitMinimumConfidence="@this.GetPolicyMinimumConfidenceLevel()"/>
<ConfigurationSelect OptionDescription="@T("Preselect a profile")" Disabled="@(() => this.IsNoPolicySelected)" SelectedValue="@(() => this.policyPreselectedProfile)" Data="@ConfigurationSelectDataFactory.GetComponentProfilesData(this.SettingsManager.ConfigurationData.Profiles)" SelectionUpdateAsync="@(async selection => await this.PolicyPreselectedProfileWasChangedAsync(selection))" OptionHelp="@T("Choose whether the policy should use the app default profile, no profile, or a specific profile.")"/>
@@ -170,4 +172,7 @@ else
</MudExpansionPanels>
}
@* The warning sits right at the provider selection, because choosing another provider resolves it: *@
<ManagedToolsWarning Component="@this.Component" ToolIds="@this.policyAllowedToolIds" ProviderSettings="@this.ProviderSettings"/>
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider" ExplicitMinimumConfidence="@this.GetPolicyMinimumConfidenceLevel()"/>
@@ -23,7 +23,18 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
private IDialogService DialogService { get; init; } = null!;
protected override Tools.Components Component => Tools.Components.DOCUMENT_ANALYSIS_ASSISTANT;
/// <summary>
/// The policy decides which tools its analysis uses; the user does not pick them.
/// </summary>
/// <remarks>
/// Two ways of working, one answer: someone writing a policy for themselves settles the tools
/// while writing it, and a policy rolled out by an organization arrives ready to use, with the
/// tools its authors tested it with. Either way there is nothing left for the user to switch,
/// which is why the tool selection does not appear in this assistant.
/// </remarks>
protected override IReadOnlySet<string> AssistantManagedToolIds => this.policyAllowedToolIds;
protected override string Title => T("Document Analysis Assistant");
protected override string Description => T("The document analysis assistant helps you to analyze and extract information from documents based on predefined policies. You can create, edit, and manage document analysis policies that define how documents should be processed and what information should be extracted. Some policies might be protected by your organization and cannot be modified or deleted.");
@@ -178,6 +189,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
this.policyAnalysisRules = string.Empty;
this.policyOutputRules = string.Empty;
this.policyMinimumProviderConfidence = ConfidenceLevel.NONE;
this.policyAllowedToolIds = [];
this.policyPreselectedProviderId = string.Empty;
this.policyPreselectedProfile = ProfilePreselection.NoProfile;
}
@@ -205,6 +217,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
this.policyAnalysisRules = this.selectedPolicy.AnalysisRules;
this.policyOutputRules = this.selectedPolicy.OutputRules;
this.policyMinimumProviderConfidence = this.selectedPolicy.MinimumProviderConfidence;
this.policyAllowedToolIds = [..this.selectedPolicy.AllowedToolIds];
this.policyPreselectedProviderId = this.selectedPolicy.PreselectedProvider;
this.policyPreselectedProfile = ProfilePreselection.FromStoredValue(this.selectedPolicy.PreselectedProfile);
@@ -262,6 +275,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
this.selectedPolicy.AnalysisRules = this.policyAnalysisRules;
this.selectedPolicy.OutputRules = this.policyOutputRules;
this.selectedPolicy.MinimumProviderConfidence = this.policyMinimumProviderConfidence;
this.selectedPolicy.AllowedToolIds = [..this.policyAllowedToolIds];
}
await this.SettingsManager.StoreSettings();
@@ -276,6 +290,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
private string policyAnalysisRules = string.Empty;
private string policyOutputRules = string.Empty;
private ConfidenceLevel policyMinimumProviderConfidence = ConfidenceLevel.NONE;
private HashSet<string> policyAllowedToolIds = [];
private string policyPreselectedProviderId = string.Empty;
private ProfilePreselection policyPreselectedProfile = ProfilePreselection.NoProfile;
private HashSet<FileAttachment> loadedDocumentPaths = [];
@@ -528,6 +543,15 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
return this.SettingsManager.GetAppPreselectedProfile();
}
/// <summary>
/// Takes over the tools this policy permits.
/// </summary>
private async Task PolicyAllowedToolsWasChangedAsync(HashSet<string> allowedToolIds)
{
this.policyAllowedToolIds = allowedToolIds;
await this.AutoSave();
}
private async Task PolicyMinimumConfidenceWasChangedAsync(ConfidenceLevel level)
{
this.policyMinimumProviderConfidence = level;
@@ -813,10 +837,26 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
}
await this.AutoSave();
await this.Form!.Validate();
if (!this.InputIsValid)
//
// Only what the export actually writes is checked. Validating the whole form would demand
// a selected provider, which the export does not contain: it describes the policy, not the
// way one user happens to run it.
//
var policyIssues = this.GetPolicyExportIssues();
if (policyIssues.Count > 0)
{
await this.MessageBus.SendError(new (Icons.Material.Filled.Policy, this.T("The selected policy contains invalid data. Please fix the issues before exporting the policy.")));
//
// Name the issues in both places. A message saying only that something is invalid
// leaves the user searching a long form, and leaves us without a clue in the log:
//
this.Logger.LogWarning(
"Was not able to export the document analysis policy '{PolicyName}'. It has {IssueCount} validation issue(s): {Issues}",
this.selectedPolicy?.PolicyName,
policyIssues.Count,
string.Join(" | ", policyIssues));
await this.MessageBus.SendError(new (Icons.Material.Filled.Policy, $"{this.T("The selected policy contains invalid data. Please fix the issues before exporting the policy.")} {string.Join(" ", policyIssues)}"));
return;
}
@@ -824,6 +864,27 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
await this.RustService.CopyText2Clipboard(luaCode);
}
/// <summary>
/// Checks the fields the export writes, using the same rules the form applies to them.
/// </summary>
private List<string> GetPolicyExportIssues()
{
List<string> issues = [];
foreach (var issue in new[]
{
this.ValidatePolicyName(this.policyName),
this.ValidatePolicyDescription(this.policyDescription),
this.ValidateAnalysisRules(this.policyAnalysisRules),
this.ValidateOutputRules(this.policyOutputRules),
})
{
if (!string.IsNullOrWhiteSpace(issue))
issues.Add(issue);
}
return issues;
}
private string GenerateLuaPolicyExport()
{
if(this.selectedPolicy is null)
@@ -832,6 +893,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
var preselectedProvider = string.IsNullOrWhiteSpace(this.selectedPolicy.PreselectedProvider) ? string.Empty : this.selectedPolicy.PreselectedProvider;
var preselectedProfile = string.IsNullOrWhiteSpace(this.selectedPolicy.PreselectedProfile) ? string.Empty : this.selectedPolicy.PreselectedProfile;
var id = string.IsNullOrWhiteSpace(this.selectedPolicy.Id) ? Guid.NewGuid().ToString() : this.selectedPolicy.Id;
var allowedToolIds = string.Join(", ", this.selectedPolicy.AllowedToolIds.OrderBy(x => x, StringComparer.Ordinal).Select(x => LuaTools.ToLuaStringLiteral(x)));
return $$"""
CONFIG["DOCUMENT_ANALYSIS_POLICIES"][#CONFIG["DOCUMENT_ANALYSIS_POLICIES"]+1] = {
@@ -847,6 +909,12 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
-- Allowed values are: NONE, VERY_LOW, LOW, MODERATE, MEDIUM, HIGH
["MinimumProviderConfidence"] = "{{this.selectedPolicy.MinimumProviderConfidence}}",
-- The tools an analysis with this policy may use, by tool ID.
-- This is a limit, not a preselection: a tool which is not listed here cannot
-- be used for this policy. An empty list means no tools. A listed tool must
-- still meet the confidence requirements of the provider in use.
["AllowedToolIds"] = { {{allowedToolIds}} },
-- Optional: preselect a provider or profile by ID.
-- The IDs must exist in CONFIG["LLM_PROVIDERS"] or CONFIG["PROFILES"].
["PreselectedProvider"] = "{{preselectedProvider}}",