.NET API
TruncatingAIFunction
Tracon.Core.dllWraps an AI.AIFunction so a result over a byte limit is trimmed
and handed to the model inside an envelope that states how many bytes were
dropped, instead of running unbounded.
public sealed class TruncatingAIFunction : DelegatingAIFunctionInheritance
Section titled “Inheritance”object ← AITool ← AIFunctionDeclaration ← AIFunction ← DelegatingAIFunction ← TruncatingAIFunction
Inherited Members
Section titled “Inherited Members”DelegatingAIFunction.ToString(), DelegatingAIFunction.GetService(Type, object?), DelegatingAIFunction.Name, DelegatingAIFunction.Description, DelegatingAIFunction.JsonSchema, DelegatingAIFunction.ReturnJsonSchema, DelegatingAIFunction.JsonSerializerOptions, DelegatingAIFunction.UnderlyingMethod, DelegatingAIFunction.AdditionalProperties, AIFunction.InvokeAsync(AIFunctionArguments?, CancellationToken), AIFunction.AsDeclarationOnly(), AIFunction.UnderlyingMethod, AIFunction.JsonSerializerOptions, AIFunctionDeclaration.JsonSchema, AIFunctionDeclaration.ReturnJsonSchema, AITool.ToString(), AITool.GetService(Type, object?), AITool.GetService<TService>(object?), AITool.Name, AITool.Description, AITool.AdditionalProperties, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”Installed by the tool registry as the layer directly around the
real function — inside ApprovalRequiredAIFunction: trimming
must see only the tool’s own output, never the pending-approval signal
that wrapper produces instead of running the body.
Bounding the output inside the tool’s own body is always better: the tool knows its data, this only counts bytes. This class is the last defence for the day that bound is forgotten.
Constructors
Section titled “Constructors”TruncatingAIFunction(AIFunction, int)
Section titled “ TruncatingAIFunction(AIFunction, int)”Creates a new output-trimming wrapper.
public TruncatingAIFunction(AIFunction innerFunction, int maxOutputBytes)Parameters
Section titled “Parameters”innerFunction AIFunction
The tool to wrap.
maxOutputBytes int
The most bytes (UTF-8) a result may carry before it is trimmed.
Exceptions
Section titled “Exceptions”maxOutputBytes is below TruncatingAIFunction.MinimumEnvelopeBytes.
Fields
Section titled “Fields”MinimumEnvelopeBytes
Section titled “ MinimumEnvelopeBytes”The largest an empty-content envelope can ever be — the worst case is
Int32.MaxValue for the dropped-byte count, since that
value is bounded by Encoding.UTF8’s own
int-typed byte count.
public static readonly int MinimumEnvelopeBytesField Value
Section titled “Field Value”Remarks
Section titled “Remarks”A maxOutputBytes below this value is rejected by the
constructor: below it, no input could ever be represented by a
compliant envelope, and the alternative would be a silent budget
violation instead of a startup-time error.
Methods
Section titled “Methods”InvokeCoreAsync(AIFunctionArguments, CancellationToken)
Section titled “ InvokeCoreAsync(AIFunctionArguments, CancellationToken)”Invokes the AI.AIFunction and returns its result.
protected override ValueTask<object?> InvokeCoreAsync(AIFunctionArguments arguments, CancellationToken cancellationToken)Parameters
Section titled “Parameters”arguments AIFunctionArguments
The arguments to pass to the function’s invocation.
cancellationToken CancellationToken
The CancellationToken to monitor for cancellation requests.
Returns
Section titled “Returns”The result of the function’s execution.