使用 maf重构
This commit is contained in:
101
Service/AgentFramework/IToolRegistry.cs
Normal file
101
Service/AgentFramework/IToolRegistry.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
namespace Service.AgentFramework;
|
||||
|
||||
/// <summary>
|
||||
/// Tool 的定义和元数据
|
||||
/// </summary>
|
||||
public record ToolDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool 唯一标识
|
||||
/// </summary>
|
||||
public string Name { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Tool 描述
|
||||
/// </summary>
|
||||
public string Description { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Tool 对应的委托
|
||||
/// </summary>
|
||||
public Delegate Handler { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Tool 所属类别
|
||||
/// </summary>
|
||||
public string Category { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Tool 是否可缓存
|
||||
/// </summary>
|
||||
public bool Cacheable { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tool Registry 接口 - 管理所有可用的 Tools
|
||||
/// </summary>
|
||||
public interface IToolRegistry
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册一个 Tool
|
||||
/// </summary>
|
||||
void RegisterTool<TResult>(
|
||||
string name,
|
||||
string description,
|
||||
Func<Task<TResult>> handler,
|
||||
string category = "General",
|
||||
bool cacheable = false);
|
||||
|
||||
/// <summary>
|
||||
/// 注册一个带参数的 Tool
|
||||
/// </summary>
|
||||
void RegisterTool<TParam, TResult>(
|
||||
string name,
|
||||
string description,
|
||||
Func<TParam, Task<TResult>> handler,
|
||||
string category = "General",
|
||||
bool cacheable = false);
|
||||
|
||||
/// <summary>
|
||||
/// 注册一个带多参数的 Tool
|
||||
/// </summary>
|
||||
void RegisterTool<TParam1, TParam2, TResult>(
|
||||
string name,
|
||||
string description,
|
||||
Func<TParam1, TParam2, Task<TResult>> handler,
|
||||
string category = "General",
|
||||
bool cacheable = false);
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Tool 定义
|
||||
/// </summary>
|
||||
ToolDefinition? GetToolDefinition(string name);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 Tools
|
||||
/// </summary>
|
||||
IEnumerable<ToolDefinition> GetAllTools();
|
||||
|
||||
/// <summary>
|
||||
/// 按类别获取 Tools
|
||||
/// </summary>
|
||||
IEnumerable<ToolDefinition> GetToolsByCategory(string category);
|
||||
|
||||
/// <summary>
|
||||
/// 调用无参 Tool
|
||||
/// </summary>
|
||||
Task<TResult> InvokeToolAsync<TResult>(string toolName);
|
||||
|
||||
/// <summary>
|
||||
/// 调用带参 Tool
|
||||
/// </summary>
|
||||
Task<TResult> InvokeToolAsync<TParam, TResult>(string toolName, TParam param);
|
||||
|
||||
/// <summary>
|
||||
/// 调用带多参 Tool
|
||||
/// </summary>
|
||||
Task<TResult> InvokeToolAsync<TParam1, TParam2, TResult>(
|
||||
string toolName,
|
||||
TParam1 param1,
|
||||
TParam2 param2);
|
||||
}
|
||||
Reference in New Issue
Block a user