| using System; |
| using System.Collections.Generic; |
| using Microsoft.Extensions.AI; |
| namespace OnDeviceAgent.AgentCore |
| { |
|
|
| public sealed class ToolDefinition |
| { |
| public string Name; |
|
|
| public string HandlerName; |
|
|
| public string Description; |
|
|
| public Dictionary<string, string> Properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
| } |
|
|
| public sealed class ToolRegistry |
| { |
| readonly object m_Lock = new object(); |
| readonly Dictionary<string, IAgentTool> m_Tools = new Dictionary<string, IAgentTool>(StringComparer.OrdinalIgnoreCase); |
|
|
| public void Register(IAgentTool tool) |
| { |
| if (tool == null) |
| throw new ArgumentNullException("tool"); |
|
|
| lock (m_Lock) |
| m_Tools[tool.Name] = tool; |
| } |
|
|
| public IReadOnlyList<AITool> BuildAITools( |
| bool enableBuiltins, |
| AgentToolContext context) |
| { |
| if (context == null) |
| throw new ArgumentNullException("context"); |
|
|
| var result = new List<AITool>(); |
| if (!enableBuiltins) |
| return result; |
|
|
| List<IAgentTool> snapshot; |
| lock (m_Lock) |
| snapshot = new List<IAgentTool>(m_Tools.Values); |
|
|
| foreach (var tool in snapshot) |
| result.Add(tool.ToAIFunction(context)); |
|
|
| return result; |
| } |
| } |
| } |
|
|