From 1d93a697ad82c4088c31588cdc69428f5a3bc587 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 22 Feb 2025 20:00:23 +0100 Subject: [PATCH] Added the retrieval context to the retrieval context validation result --- .../Agents/AgentRetrievalContextValidation.cs | 15 ++++++++------- .../Agents/RetrievalContextValidationResult.cs | 5 ++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/MindWork AI Studio/Agents/AgentRetrievalContextValidation.cs b/app/MindWork AI Studio/Agents/AgentRetrievalContextValidation.cs index c197eb84..1077df55 100644 --- a/app/MindWork AI Studio/Agents/AgentRetrievalContextValidation.cs +++ b/app/MindWork AI Studio/Agents/AgentRetrievalContextValidation.cs @@ -180,7 +180,7 @@ public sealed class AgentRetrievalContextValidation (ILogger(json, JSON_SERIALIZER_OPTIONS); + var result = JsonSerializer.Deserialize(json, JSON_SERIALIZER_OPTIONS); + return result with { RetrievalContext = dataContext }; } catch { logger.LogWarning("The agent answered with an invalid or unexpected JSON format."); - return new(false, "The agent answered with an invalid or unexpected JSON format.", 1.0f); + return new(false, "The agent answered with an invalid or unexpected JSON format.", 1.0f, dataContext); } } case { ContentType: ContentType.TEXT }: logger.LogWarning("The agent answered with an unexpected inner content type."); - return new(false, "The agent answered with an unexpected inner content type.", 1.0f); + return new(false, "The agent answered with an unexpected inner content type.", 1.0f, dataContext); case { ContentType: ContentType.NONE }: logger.LogWarning("The agent did not return a response."); - return new(false, "The agent did not return a response.", 1.0f); + return new(false, "The agent did not return a response.", 1.0f, dataContext); default: logger.LogWarning($"The agent answered with an unexpected content type '{aiResponse.ContentType}'."); - return new(false, $"The agent answered with an unexpected content type '{aiResponse.ContentType}'.", 1.0f); + return new(false, $"The agent answered with an unexpected content type '{aiResponse.ContentType}'.", 1.0f, dataContext); } } diff --git a/app/MindWork AI Studio/Agents/RetrievalContextValidationResult.cs b/app/MindWork AI Studio/Agents/RetrievalContextValidationResult.cs index 418e59ee..826c3430 100644 --- a/app/MindWork AI Studio/Agents/RetrievalContextValidationResult.cs +++ b/app/MindWork AI Studio/Agents/RetrievalContextValidationResult.cs @@ -1,3 +1,5 @@ +using AIStudio.Tools.RAG; + namespace AIStudio.Agents; /// @@ -6,4 +8,5 @@ namespace AIStudio.Agents; /// Whether the retrieval context is useful or not. /// The reason for the decision. /// The confidence of the decision. -public readonly record struct RetrievalContextValidationResult(bool Decision, string Reason, float Confidence) : IConfidence; \ No newline at end of file +/// The retrieval context that was validated. +public readonly record struct RetrievalContextValidationResult(bool Decision, string Reason, float Confidence, IRetrievalContext? RetrievalContext) : IConfidence; \ No newline at end of file