使用 maf重构
This commit is contained in:
53
Service/AgentFramework/AgentFrameworkExtensions.cs
Normal file
53
Service/AgentFramework/AgentFrameworkExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Agents.AI;
|
||||
|
||||
namespace Service.AgentFramework;
|
||||
|
||||
/// <summary>
|
||||
/// Agent Framework 依赖注入扩展
|
||||
/// </summary>
|
||||
public static class AgentFrameworkExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册 Agent Framework 相关服务
|
||||
/// </summary>
|
||||
public static IServiceCollection AddAgentFramework(this IServiceCollection services)
|
||||
{
|
||||
// 注册 Tool Registry (Singleton - 无状态,全局共享)
|
||||
services.AddSingleton<IToolRegistry, ToolRegistry>();
|
||||
|
||||
// 注册 Tools (Scoped - 因为依赖 Scoped Repository)
|
||||
services.AddSingleton<ITransactionQueryTools, TransactionQueryTools>();
|
||||
services.AddSingleton<ITextProcessingTools, TextProcessingTools>();
|
||||
services.AddSingleton<IAITools, AITools>();
|
||||
|
||||
// 注册 Agents (Scoped - 因为依赖 Scoped Tools)
|
||||
services.AddSingleton<ClassificationAgent>();
|
||||
services.AddSingleton<ParsingAgent>();
|
||||
services.AddSingleton<ImportAgent>();
|
||||
|
||||
// 注册 Service Facade (Scoped - 避免生命周期冲突)
|
||||
services.AddSingleton<ISmartHandleServiceV2, SmartHandleServiceV2>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 Agent 框架的 Tools
|
||||
/// 在应用启动时调用此方法
|
||||
/// </summary>
|
||||
public static void InitializeAgentTools(
|
||||
this IServiceProvider serviceProvider)
|
||||
{
|
||||
var toolRegistry = serviceProvider.GetRequiredService<IToolRegistry>();
|
||||
var logger = serviceProvider.GetRequiredService<ILogger<IToolRegistry>>();
|
||||
|
||||
logger.LogInformation("开始初始化 Agent Tools...");
|
||||
|
||||
// 这里可以注册更多的 Tool
|
||||
// 目前大部分 Tool 被整合到了工具类中,后续可根据需要扩展
|
||||
|
||||
logger.LogInformation("Agent Tools 初始化完成");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user