// Copyright (c) Microsoft. All rights reserved. using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Microsoft.Agents.AI; using Microsoft.Agents.AI.A2A; using Microsoft.Extensions.Logging; namespace A2A; /// /// Provides extension methods for /// to simplify the creation of A2A agents. /// /// /// These extensions bridge the gap between A2A SDK client objects /// and the Microsoft Agent Framework. /// /// They allow developers to easily create AI agents that can interact /// with A2A agents by handling the conversion from A2A clients to /// instances that implement the interface. /// /// public static class A2ACardResolverExtensions { /// /// Retrieves an instance of for an existing A2A agent. /// /// /// This method can be used to access A2A agents that support the /// Well-Known URI /// discovery mechanism. /// /// The to use for the agent creation. /// The to use for HTTP requests. /// /// Optional controlling protocol binding preference. /// When not provided, defaults to preferring HTTP+JSON first, with JSON-RPC as fallback. /// /// The logger factory for enabling logging within the agent. /// The to monitor for cancellation requests. The default is . /// An instance backed by the A2A agent. public static async Task GetAIAgentAsync(this A2ACardResolver resolver, HttpClient? httpClient = null, A2AClientOptions? options = null, ILoggerFactory? loggerFactory = null, CancellationToken cancellationToken = default) { // Obtain the agent card from the resolver. var agentCard = await resolver.GetAgentCardAsync(cancellationToken).ConfigureAwait(false); return agentCard.AsAIAgent(httpClient, options, loggerFactory); } }