Skip to content

migrating from SK framework to MAF#17

Merged
MayueCif merged 22 commits intomainfrom
feat/agent_framework
Dec 12, 2025
Merged

migrating from SK framework to MAF#17
MayueCif merged 22 commits intomainfrom
feat/agent_framework

Conversation

@MayueCif
Copy link
Member

migrating from SK framework to MAF

MayueCif and others added 20 commits October 19, 2025 23:18
- 新增 `MigrationPhase1Complete.md`,详细记录了从 Semantic Kernel 迁移到 Microsoft Agent Framework 的主要变更,包括依赖更新、对话历史管理、API 调用和MCP工具集成。
- 新增 `MigrationPlan.md`,概述了迁移计划的各个阶段和步骤,确保项目结构和功能的顺利过渡。
- 更新 `MarketAssistant.csproj`,添加 Microsoft Agent Framework 相关依赖。
- 重构 `MarketChatAgent`,使用新的聊天客户端和对话管理逻辑。
- 更新测试文件 `MarketChatAgentTest.cs`,确保与新架构的兼容性。
- 新增多个工厂类以支持新的代理创建和工具配置。

构建状态:当前构建存在3个编译错误,需确认API方法名称并更新调用。下一步将进行方法调用的修正与测试验证。
- 完成 `MarketChatSession`(原 `MarketChatAgent`)的迁移到 Microsoft Agent Framework,更新了相关文档以反映主要变更。
- 新增命名重构部分,详细记录了类名、文件名及工厂接口的更改。
- 更新 `MigrationPlan.md`,确保迁移计划与实际变更一致。
- 删除不再使用的 `McpPlugin`,并重构相关逻辑以使用新的 `McpService`。
- 更新测试文件 `MarketChatSessionTest.cs`,确保与新架构的兼容性。

构建状态:迁移与重构已完成,构建验证通过。
- 成功将 `StockSelectionManager` 重构为基于 Microsoft Agent Framework Workflows 的 `StockSelectionWorkflow`,实现了确定性三步骤选股流程。
- 新增多个 Executor 类,分别负责生成筛选条件、执行股票筛选和分析筛选结果。
- 更新 `StockSelectionService` 以使用新的工作流,确保接口兼容性。
- 新增完整的单元测试,验证工作流的功能与稳定性。
- 更新相关文档,详细描述工作流的架构设计、使用方式及核心优势。

构建状态:重构与测试已完成,构建验证通过。
- 新增 `StockScreenerService`,实现股票筛选功能,支持多种筛选条件。
- 新增多个模型类,如 `ScreenerStockInfo` 和 `StockCriteria`,用于描述筛选结果和筛选条件。
- 更新 `StockSelection` 相关逻辑,整合新服务以提升选股效率。
- 删除不再使用的解析器和相关测试,简化代码结构。

构建状态:新功能已完成,构建验证通过。
移除对 Microsoft.SemanticKernel 的依赖,转而使用 Microsoft.Extensions.AI。重构多个插件,移除 KernelFunction 特性,添加 GetFunctions 方法。更新 MarketAssistant.csproj 中的包版本,移除不再使用的包。重构测试基类和方法,使用新的依赖注入方式。简化 McpService,移除 GetKernelFunctionsAsync 方法。更新多个 YAML 模板和视图文件。
Upgraded project to .NET 10 and Avalonia UI 11.3.8. Updated build and test configurations to reflect the new .NET version. Simplified `MarketChatSession` logic by replacing `UpdateStockContextAsync` with `SetStockCode` and removing unused methods. Added macOS-specific configurations to fix WebView issues.

Refactored test cases to streamline naming conventions, remove redundant tests, and focus on core functionality. Removed `ChatCompletionTest` and JSON deserialization tests. Updated dependencies and improved validation strategies in `AGENTS.md`.

Breaking changes:
- Dropped support for .NET 9.
Enhanced JSON deserialization with case-insensitive support.
Refactored workflow logic in `MarketAnalysisWorkflow` for clarity.
Removed legacy `ScreenerStockInfo` and `StockScreeningCriteria` classes.
Deleted outdated YAML templates for stock criteria generation.
Improved logging in `AnalyzeStocksExecutor` and added JSON output.
Simplified environment variable parsing in `MCPConfigPageViewModel`.
Removed unused logging in `StockWebChartView`.
Updated tests to use stricter exception assertions.

Breaking changes:
- Removed `ScreenerStockInfo` and `StockScreeningCriteria` classes.
- Deleted YAML templates: `news_analysis_to_stock_criteria.yaml` and `user_requirement_to_stock_criteria.yaml`.
- 在 `AnalyzeStocksExecutor.cs` 中:
  - 添加 `System.Text` 和 `System.Text.Json` 支持。
  - 重构 `GetAnalysisInstructions` 方法,统一分析指令。
  - 强调多维度评估,严格约束 JSON 输出格式。

- 在 `StockRecommendation.cs` 中:
  - 为字段添加 `[Description]` 特性,增强文档说明。
  - 新增可选字段(如持有期限、目标价格等)。
  - 删除冗余字段,简化类结构。

- 在 `StockSelectionResult.cs` 中:
  - 添加字段描述,明确字段用途和约束。
  - 删除不必要字段,新增置信度评分等关键字段。
  - 优化推荐股票和分析报告的结构化输出。

- 整体改进:
  - 提升代码可读性和可维护性。
  - 统一输出格式,增强灵活性和扩展性。
  - 确保生成结果更加规范和易解析。
- Added `JsonSerializerOptions` for serialization consistency.
- Introduced `ValidateResult` for `StockSelectionResult` validation.
- Refactored `MarketType` and `IndustryType` to enums with descriptions.
- Enhanced data models with validation attributes (e.g., `Range`).
- Redesigned UI for stock recommendations with detailed metrics.
- Added `EnumExtensions` and converters for nullable values.
- Updated tests for new enums and validation logic.
- Improved logging with descriptive enum values.
- Updated AI model to `deepseek-ai/DeepSeek-V3.2-Exp`.
- Fixed `roediluted` field name typo.
…l, technical, sentiment, and news event analyses

- Added new models for structured analysis results, including `FinancialAnalysisResult`, `FundamentalAnalysisResult`, `TechnicalAnalysisResult`, `MarketSentimentAnalysisResult`, and `NewsEventAnalysisResult`.
- Implemented enums for various analysis dimensions, such as `InvestmentRating`, `OperationRecommendation`, and `ImpactDirection`.
- Established scoring standards for consistent evaluation across analyses.
- Removed outdated YAML templates for agents, streamlining the codebase.
- Enhanced documentation with detailed descriptions for new models and properties.
- Removed the `MarketAnalysisModels.cs` file and its associated classes to simplify the codebase.
- Introduced a new `CoordinatorResult` model to encapsulate structured analysis results, enhancing clarity and usability.
- Updated the `AnalysisReportViewModel` to utilize the new `CoordinatorResult` model, improving data binding and presentation.
- Deleted the outdated YAML template for the `CoordinatorAnalystAgent`, reducing clutter in the project.
- Refactored the project file to remove unnecessary references and ensure compatibility with the latest structure.
- Added structured response formats for various analysis agents, including financial, technical, fundamental, sentiment, and news event analyses.
- Updated `MarketAnalysisWorkflow` to utilize the new response formats, improving data handling and clarity.
- Introduced `WorkflowStateKeys` for managing shared state in the workflow, enhancing maintainability.
- Refactored `AnalysisDispatcherExecutor` and `AnalysisAggregatorExecutor` to streamline message handling and improve logging.
- Removed outdated models and consolidated analysis request handling to simplify the codebase.
- Replaced complex parsers with AI-generated structured JSON output.
- Updated `AnalystResult` model with new structured fields.
- Refactored `AnalysisAggregatorExecutor` to handle message lists.
- Enforced JSON output format, removing fallback logic.
- Migrated `MarketAnalysisWorkflow` to Agent Framework Workflows.
- Updated `AnalysisAgent` to use enumeration class pattern.
- Introduced state management for workflow configuration sharing.
- Replaced `ChatClientAgent` with `AIAgent` for tool integration.
- Removed legacy code, reducing codebase complexity.
- Added new tests for agent tool configuration and execution.

BREAKING CHANGE: Removed backward compatibility with old parser system.
Closes #123
重构代码以引入新的 `AnalystType` 枚举,替换旧的 `AnalysisAgent` 类,优化分析师代理的创建和管理。引入 `AnalystAgentBase` 基类,并为每种分析师类型创建具体代理类,整合工具配置逻辑。重命名插件类为工具类,调整命名空间。更新 `AnalystAgentFactory` 以支持新枚举。移除旧测试类,新增 `ToolsIntegrationTest`。项目中添加 `AdaptiveCards` 引用,并进行代码清理。
…for financial and market sentiment tools

- Updated TextSearchResult instantiation in RetrievalOrchestrator to use named parameters.
- Replaced Microsoft.SemanticKernel.Text.TextChunker with a custom implementation in TextChunkingService.
- Enhanced unit tests for AnalystAgentFactory to validate financial analysis, market sentiment analysis, and technical analysis.
- Modified integration tests for StockFinancialTools to reflect updated method names and added tests for MarketSentimentTools.
移除 `AnalystType` 枚举,改用反射和属性标记动态管理分析师类型,增加 `RequiredAnalystAttribute` 属性。重构 `CoordinatorExecutor` 和 `MarketAnalysisWorkflow` 类,使用泛型方法和反射获取分析师类型。更新 `UserSetting` 类,使用字典管理分析师角色。重构 `AnalystAgentFactory`,使用依赖注入创建代理实例。增加 `NavigationService` 的路由注册和导航消息处理功能。重构 `SettingsPageViewModel`,使用 `AnalystRoleViewModel` 管理角色信息。实现 `INavigationAware` 接口于 `StockPageViewModel` 和 `AgentAnalysisViewModel`。改进 `PlaywrightService` 的资源释放。统一 UI 样式文件,提升界面一致性。调整 `StockSelectionPageView.axaml`、`MainWindow.axaml` 和 `NotificationWindow.axaml` 的样式,使用静态资源替代硬编码值。重构测试代码,使用 `Assert.ThrowsExactlyAsync` 确保异常类型匹配。
…unctionality

- Updated SettingsPageView.axaml to enhance the layout with a Grid structure,
  added EnumDescriptionConverter, and reorganized sections for better clarity.
- Modified StockPageView.axaml to optimize the display of stock information,
  including a new layout for stock name, code, and price, and improved button styles.
- Enhanced StockSelectionPageView.axaml to include icons in strategy cards for better visual representation.
- Updated models.yaml to reflect changes in supported AI models, removing deprecated entries.
- Adjusted AnalystAgentFactoryTest.cs to simulate conflict scenarios in analyst reports, ensuring comprehensive analysis.
- Cleaned up logging configuration in BaseAgentTest.cs by removing unnecessary console logging.
- Modified MarketAnalysisWorkflowTest.cs to streamline progress event handling and assertions.
Copilot AI review requested due to automatic review settings December 10, 2025 14:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the application from the Semantic Kernel (SK) framework to the Microsoft Agent Framework (MAF), representing a significant architectural shift in how the AI agents and chat functionality are implemented.

Key changes:

  • Migration from SK to MAF for agent orchestration and chat services
  • Replacement of SK-based parsing with structured JSON responses and Adaptive Cards
  • Removal of legacy parsing infrastructure and migration to native Agent Framework patterns
  • Updates to .NET 10.0 and modernized package dependencies

Reviewed changes

Copilot reviewed 167 out of 267 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/ViewModels/MCPConfigPageViewModel.cs Updated MCP configuration to use new dialog services and navigation awareness
src/ViewModels/HomePageViewModel.cs Simplified navigation with StockNavigationParameter record
src/ViewModels/ChatSidebarViewModel.cs Migrated from SK ChatAgent to MAF MarketChatSession
src/ViewModels/ChatMessageAdapter.cs Updated to support Adaptive Cards and MAF ChatMessage
src/ViewModels/AgentAnalysisViewModel.cs Replaced MarketAnalysisAgent with MarketAnalysisWorkflow
src/ViewModels/AnalysisReportViewModel.cs Refactored to use structured MarketAnalysisReport
src/Services/Mcp/McpService.cs New service for Model Context Protocol integration
src/Services/Cache/AnalysisCacheService.cs Updated to cache MarketAnalysisReport instead of AnalystResult
src/Services/StockScreener/ Moved and updated stock screening services with strong typing
src/Infrastructure/Factories/ New factories for ChatClient and AnalystAgent creation
src/Infrastructure/AdaptiveCards/ New Adaptive Card parsers for structured analysis results
src/Rag/Services/ Removed SK dependencies, ported TextChunker logic
src/MarketAssistant.csproj Updated to .NET 10.0 and MAF packages
Deleted files Removed SK-based parsers, filters, and legacy analysis models
Comments suppressed due to low confidence (3)

src/ViewModels/ChatMessageAdapter.cs:1

  • The comment appears to contain garbled Chinese characters. The intended text should be '消息状态枚举' (Message status enumeration).
using AdaptiveCards;

src/ViewModels/ChatMessageAdapter.cs:1

  • The comment appears to contain garbled Chinese characters. The intended text should be 'ChatMessage的MVVM适配器,支持UI绑定'.
using AdaptiveCards;

src/ViewModels/ChatMessageAdapter.cs:1

  • The comment contains garbled Chinese characters. The intended text should be '用户' and '助手'.
using AdaptiveCards;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (service == null)
{
service = new McpService();
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback creates a temporary McpService without a logger, which differs from the injected service behavior. Consider either requiring _mcpService to be non-null, or ensure the temporary service receives proper configuration for consistency.

Suggested change
service = new McpService();
service = new McpService(Logger);

Copilot uses AI. Check for mistakes.
Logger?.LogInformation($"已加载模拟分析数据,股票代码:{StockSymbol}");
}
/// <summary>
/// 评分百分比 (0.0 - 1.0),用于进度条
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property comment states 'for progress bar' but doesn't clarify the expected range. Consider adding bounds documentation: '评分百分比 (0.0 - 1.0),用于进度条,假设最大分数为10分'.

Suggested change
/// 评分百分比 (0.0 - 1.0),用于进度条
/// 评分百分比 (0.0 - 1.0),用于进度条。假设最大分数为 10 分,ScorePercentage = Score / 10.0。

Copilot uses AI. Check for mistakes.
- CoordinatorAnalystAgent 注释搜索工具注入,移除无用 using
- StockKLineService 动态获取 ZhiTuApiToken,支持设置实时生效
- ChatClientFactory 缓存 AI 配置,优化客户端重建与错误处理
- PlaywrightService 支持浏览器路径变更自动重启
- AnalysisReportViewModel 移除 ScorePercentage 属性,简化数据模型
升级部分依赖包版本,提升兼容性和功能。CoordinatorAnalystAgent 现暂不启用 AI 工具,避免资源浪费。AgentAnalysisPageView 移除 Loaded 事件及相关数据加载逻辑,简化页面初始化。
@MayueCif MayueCif merged commit ada67b1 into main Dec 12, 2025
3 checks passed
@MayueCif MayueCif deleted the feat/agent_framework branch December 12, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants