Added the retrieval context to the retrieval context validation result

This commit is contained in:
Thorsten Sommer 2025-02-22 20:00:23 +01:00
parent 4838904b77
commit 1d93a697ad
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 12 additions and 8 deletions

View File

@ -180,7 +180,7 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
if (string.IsNullOrWhiteSpace(lastPromptContent)) if (string.IsNullOrWhiteSpace(lastPromptContent))
{ {
logger.LogWarning("The last prompt is empty. The AI cannot validate the retrieval context."); logger.LogWarning("The last prompt is empty. The AI cannot validate the retrieval context.");
return new(false, "The last prompt was empty.", 1.0f); return new(false, "The last prompt was empty.", 1.0f, dataContext);
} }
// //
@ -222,7 +222,7 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
if(aiResponse.Content is null) if(aiResponse.Content is null)
{ {
logger.LogWarning("The agent did not return a response."); 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);
} }
switch (aiResponse) switch (aiResponse)
@ -246,26 +246,27 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
try try
{ {
return JsonSerializer.Deserialize<RetrievalContextValidationResult>(json, JSON_SERIALIZER_OPTIONS); var result = JsonSerializer.Deserialize<RetrievalContextValidationResult>(json, JSON_SERIALIZER_OPTIONS);
return result with { RetrievalContext = dataContext };
} }
catch catch
{ {
logger.LogWarning("The agent answered with an invalid or unexpected JSON format."); 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 }: case { ContentType: ContentType.TEXT }:
logger.LogWarning("The agent answered with an unexpected inner content type."); 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 }: case { ContentType: ContentType.NONE }:
logger.LogWarning("The agent did not return a response."); 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: default:
logger.LogWarning($"The agent answered with an unexpected content type '{aiResponse.ContentType}'."); 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);
} }
} }

View File

@ -1,3 +1,5 @@
using AIStudio.Tools.RAG;
namespace AIStudio.Agents; namespace AIStudio.Agents;
/// <summary> /// <summary>
@ -6,4 +8,5 @@ namespace AIStudio.Agents;
/// <param name="Decision">Whether the retrieval context is useful or not.</param> /// <param name="Decision">Whether the retrieval context is useful or not.</param>
/// <param name="Reason">The reason for the decision.</param> /// <param name="Reason">The reason for the decision.</param>
/// <param name="Confidence">The confidence of the decision.</param> /// <param name="Confidence">The confidence of the decision.</param>
public readonly record struct RetrievalContextValidationResult(bool Decision, string Reason, float Confidence) : IConfidence; /// <param name="RetrievalContext">The retrieval context that was validated.</param>
public readonly record struct RetrievalContextValidationResult(bool Decision, string Reason, float Confidence, IRetrievalContext? RetrievalContext) : IConfidence;