3
3
4
4
using System . Collections . Generic ;
5
5
using System . Diagnostics ;
6
+ using System . Reflection ;
7
+ using System . Text . Json ;
6
8
using System . Threading ;
7
9
using System . Threading . Tasks ;
8
10
using Microsoft . Shared . Collections ;
@@ -13,8 +15,52 @@ namespace Microsoft.Extensions.AI;
13
15
[ DebuggerDisplay ( "{DebuggerDisplay,nq}" ) ]
14
16
public abstract class AIFunction : AITool
15
17
{
16
- /// <summary>Gets metadata describing the function.</summary>
17
- public abstract AIFunctionMetadata Metadata { get ; }
18
+ /// <summary>Gets the name of the function.</summary>
19
+ public abstract string Name { get ; }
20
+
21
+ /// <summary>Gets a description of the function, suitable for use in describing the purpose to a model.</summary>
22
+ public abstract string Description { get ; }
23
+
24
+ /// <summary>Gets a JSON Schema describing the function and its input parameters.</summary>
25
+ /// <remarks>
26
+ /// <para>
27
+ /// When specified, declares a self-contained JSON schema document that describes the function and its input parameters.
28
+ /// A simple example of a JSON schema for a function that adds two numbers together is shown below:
29
+ /// </para>
30
+ /// <code>
31
+ /// {
32
+ /// "title" : "addNumbers",
33
+ /// "description": "A simple function that adds two numbers together.",
34
+ /// "type": "object",
35
+ /// "properties": {
36
+ /// "a" : { "type": "number" },
37
+ /// "b" : { "type": "number", "default": 1 }
38
+ /// },
39
+ /// "required" : ["a"]
40
+ /// }
41
+ /// </code>
42
+ /// <para>
43
+ /// The metadata present in the schema document plays an important role in guiding AI function invocation.
44
+ /// </para>
45
+ /// <para>
46
+ /// When no schema is specified, consuming chat clients should assume the "{}" or "true" schema, indicating that any JSON input is admissible.
47
+ /// </para>
48
+ /// </remarks>
49
+ public virtual JsonElement JsonSchema => AIJsonUtilities . DefaultJsonSchema ;
50
+
51
+ /// <summary>
52
+ /// Gets the underlying <see cref="MethodInfo"/> that this <see cref="AIFunction"/> might be wrapping.
53
+ /// </summary>
54
+ /// <remarks>
55
+ /// Provides additional metadata on the function and its signature. Implementations not wrapping .NET methods may return <see langword="null"/>.
56
+ /// </remarks>
57
+ public virtual MethodInfo ? UnderlyingMethod => null ;
58
+
59
+ /// <summary>Gets any additional properties associated with the function.</summary>
60
+ public virtual IReadOnlyDictionary < string , object ? > AdditionalProperties => EmptyReadOnlyDictionary < string , object ? > . Instance ;
61
+
62
+ /// <summary>Gets a <see cref="JsonSerializerOptions"/> that can be used to marshal function parameters.</summary>
63
+ public virtual JsonSerializerOptions ? JsonSerializerOptions => AIJsonUtilities . DefaultOptions ;
18
64
19
65
/// <summary>Invokes the <see cref="AIFunction"/> and returns its result.</summary>
20
66
/// <param name="arguments">The arguments to pass to the function's invocation.</param>
@@ -30,7 +76,7 @@ public abstract class AIFunction : AITool
30
76
}
31
77
32
78
/// <inheritdoc/>
33
- public override string ToString ( ) => Metadata . Name ;
79
+ public override string ToString ( ) => Name ;
34
80
35
81
/// <summary>Invokes the <see cref="AIFunction"/> and returns its result.</summary>
36
82
/// <param name="arguments">The arguments to pass to the function's invocation.</param>
@@ -42,8 +88,5 @@ public abstract class AIFunction : AITool
42
88
43
89
/// <summary>Gets the string to display in the debugger for this instance.</summary>
44
90
[ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
45
- private string DebuggerDisplay =>
46
- string . IsNullOrWhiteSpace ( Metadata . Description ) ?
47
- Metadata . Name :
48
- $ "{ Metadata . Name } ({ Metadata . Description } )";
91
+ private string DebuggerDisplay => string . IsNullOrWhiteSpace ( Description ) ? Name : $ "{ Name } ({ Description } )";
49
92
}
0 commit comments