Set IsError on CallToolResponse to true when result is ErrorContent (#394)
* Set IsError on CallToolResponse to true when result is ErrorContent * Updated the `IsError` determination for a list of AIContent to require that all items in `contentItems` are instances of `ErrorContent` and that the collection is not empty * Introduce ConvertAiContentEnumerableToCallToolResponse to transform an IEnumerable<AIContent> into a CallToolResponse * Move location of ConvertAIContentEnumerableToCallToolResponse helper function --------- Co-authored-by: Andy Tagg <antagg@microsoft.com>
This commit is contained in:
parent
c750f09e97
commit
47de86ab91
1 changed files with 26 additions and 5 deletions
|
|
@ -253,7 +253,8 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
||||||
{
|
{
|
||||||
AIContent aiContent => new()
|
AIContent aiContent => new()
|
||||||
{
|
{
|
||||||
Content = [aiContent.ToContent()]
|
Content = [aiContent.ToContent()],
|
||||||
|
IsError = aiContent is ErrorContent
|
||||||
},
|
},
|
||||||
|
|
||||||
null => new()
|
null => new()
|
||||||
|
|
@ -276,10 +277,7 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
||||||
Content = [.. texts.Select(x => new Content() { Type = "text", Text = x ?? string.Empty })]
|
Content = [.. texts.Select(x => new Content() { Type = "text", Text = x ?? string.Empty })]
|
||||||
},
|
},
|
||||||
|
|
||||||
IEnumerable<AIContent> contentItems => new()
|
IEnumerable<AIContent> contentItems => ConvertAIContentEnumerableToCallToolResponse(contentItems),
|
||||||
{
|
|
||||||
Content = [.. contentItems.Select(static item => item.ToContent())]
|
|
||||||
},
|
|
||||||
|
|
||||||
IEnumerable<Content> contents => new()
|
IEnumerable<Content> contents => new()
|
||||||
{
|
{
|
||||||
|
|
@ -299,4 +297,27 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CallToolResponse ConvertAIContentEnumerableToCallToolResponse(IEnumerable<AIContent> contentItems)
|
||||||
|
{
|
||||||
|
List<Content> contentList = [];
|
||||||
|
bool allErrorContent = true;
|
||||||
|
bool hasAny = false;
|
||||||
|
|
||||||
|
foreach (var item in contentItems)
|
||||||
|
{
|
||||||
|
contentList.Add(item.ToContent());
|
||||||
|
hasAny = true;
|
||||||
|
|
||||||
|
if (allErrorContent && item is not ErrorContent)
|
||||||
|
{
|
||||||
|
allErrorContent = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Content = contentList,
|
||||||
|
IsError = allErrorContent && hasAny
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue