-
Notifications
You must be signed in to change notification settings - Fork 826
Description
Background and motivation
Currently the existing HostedCodeInterpreterTool
type is lacking the concept of resources/files.
As we see an increasing adoption of the Code Interpretation Tooling support most notably by Agentic API's from different providers like below, seems reasonable to bring this to the abstraction level.
- OpenAI Assistants (https://platform.openai.com/docs/assistants/tools/code-interpreter)
- Azure Persistent Agents (https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.agents.persistent-readme?view=azure-dotnet#create-message-with-code-interpreter-attachment)
- Amazon Bedrock (https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test-code-interpretation.html)
API Proposal
Start as immutable files/resources for minimal API public exposure.
Using the therm "File" which seems to be common so far.
public class HostedCodeInterpreterTool : AITool
{
/// <summary>Initializes a new instance of the <see cref="HostedCodeInterpreterTool"/> class.</summary>
public HostedCodeInterpreterTool(IReadOnlyCollection<AIContent> files)
{
Files = files;
}
public IReadOnlyCollection<AIContent> Files { get; }
}
Additional HostedFile
Content
public class HostedFileContent : AIContent
{
// The Id is required for any hosted file
public HostedFileContent (string id)
{
Id = id;
}
// Represents the fully qualified identifier for the hosted file to be found
public string Id { get; set; }
}
API Usage
End user usage.
// Preparing to invoke a ChatClient
var files =
[
new UrlContent("https://public-facing-resource"),
new HostedFileContent("Hosted file UID"),
new DataContent(fileByteArray, "text/csv")
];
chatOptions.Tools = [new HostedCodeInterpreterTool(files)];
Library implementers usage
// Within a ChatClient GetResponse/GetResponseStream impl.
// Can be multiple code tools, but for sample brevity, using single
var hciTool = chatOptinos.Tools.Single(tool => tool is HostedCodeInterpreterTool);
foreach (AIContent file in hciTool.Files)
{
switch (file)
{
case UrlContent urlContent:
// providers logic
break;
case HostedFileContent hostedFileContent:
// providers logic
break;
case DataContent dataContent:
// providers logic
break;
case TextContent rawTextContent:
// providers logic
break;
}
}
Alternative Designs
We may consider files to be mutable in the tool if proven useful.
Risks
This leaves freedom for the caller to create different resources in the Files
that may not be supported by the underline providers which may surprise the caller with a Exception
or ignored depending on how Providers will handle unexpected/unsupported AIContent
s passed into the tool.Files
.