Refactor A2A client API and migrate to AIAgent integration#1345
Refactor A2A client API and migrate to AIAgent integration#1345
Conversation
Introduce a CreateClientAsync client cache and migrate A2AService to the new A2A SDK surface (new message/request/response types, streaming StreamResponse, task subscribe/send request objects). Update IA2AService signatures accordingly (streaming callbacks, push notification now requires taskId). Update Directory.Packages.props to A2A 1.0.0-preview. Update appsettings.json to use gpt-4.1 model and switch test agent config to OpenClaw with the local A2A endpoint; mirror agent name/description change in test data.
Migrate A2A implementation to the newer Microsoft.Agents.AI AIAgent-based APIs: add Microsoft.Agents.AI package and project reference, replace low-level A2AClient usage with AIAgent and A2ACard resolver, and implement continuation token/session caching for runs. Update streaming and send methods signatures to use AgentResponseUpdate/RunStreaming, update IA2AService accordingly, and add logging and error handling when resolving remote agent cards. Minor behavioral tweaks: set StopCompletion in delegation function, adjust function parameter construction in the agent hook. Also bump A2A package version, update test agent LLM provider/model to azure-openai gpt-4.1, and add a .vscode settings file.
Review Summary by QodoMigrate A2A integration to AIAgent API with session caching and improved error handling
WalkthroughsDescription• Migrate A2A service to AIAgent-based APIs with session caching • Replace low-level A2AClient with high-level AIAgent and A2ACardResolver • Update streaming interface to use AgentResponseUpdate instead of SSE types • Add error handling and logging for agent card resolution • Remove legacy task/event APIs and push notification methods • Set StopCompletion flag after A2A delegation Diagramflowchart LR
A["Low-level A2AClient"] -->|"Migrate to"| B["AIAgent + A2ACardResolver"]
B -->|"Cache"| C["AIAgent Cache"]
B -->|"Session Management"| D["Continuation Token Cache"]
E["SSE-based Streaming"] -->|"Replace with"| F["AgentResponseUpdate Streaming"]
G["Legacy Task APIs"] -->|"Remove"| H["Simplified Interface"]
I["A2AAgentHook"] -->|"Add"| J["Error Handling & Logging"]
File Changes1. src/Infrastructure/BotSharp.Core.A2A/Services/A2AService.cs
|
Code Review by Qodo
1.
|
Store A2A ResponseContinuationToken in conversation state so continuation can survive service scopes. Adds SHA256-hashed state keys, Read/Persist helpers, and caches continuation tokens back into the in-memory cache. Also adds endpoint URI validation, safer JSON/argument handling in A2ADelegationFn, and null/empty safeguards when building user message parts. Logs and corrupted-token handling now remove invalid state and emit warnings. Includes unit tests (A2AServiceContinuationTokenTests) and updates the test project reference to include the A2A project.
This pull request introduces significant improvements to the A2A integration, focusing on updating dependencies, enhancing error handling, modernizing the A2A service implementation, and cleaning up legacy code. The changes improve reliability, maintainability, and compatibility with the latest A2A protocol and Microsoft Agents AI libraries.
A2A Integration and Service Improvements:
Microsoft.Agents.AI.A2Adependency in bothDirectory.Packages.propsandBotSharp.Core.A2A.csprojto support the latest protocol and features. [1] [2]A2AServiceto use high-level A2A v1 APIs, including caching, session management, and improved message sending and streaming methods. Removed or replaced legacy methods for task/event handling and push notifications. [1] [2] [3]IA2AServiceand implementation to useAgentResponseUpdateinstead of legacy SSE types, aligning with the new A2A protocol. [1] [2]Error Handling and Logging Enhancements:
A2AAgentHookby catching exceptions during agent card resolution and logging warnings, ensuring graceful fallback to configured metadata. [1] [2] [3]ILoggerin bothA2AAgentHookandA2AServicefor better observability and diagnostics. [1] [2]Behavioral and Configuration Updates:
StopCompletion = trueinA2ADelegationFn.cs..vscode/settings.jsonto suppress the Aspire settings file prompt on startup, improving developer experience.