a2aproject / a2aproject/a2a-dotnet

[Feat]: .NET Service Discovery support

Open
#473 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
262
Forks
64
Avg merge
5d 2h
Merged PRs (30d)
31

Description

### Is your feature request related to a problem? Please describe.

I'd like to use [.NET Service Discovery](https://learn.microsoft.com/en-us/dotnet/core/extensions/service-discovery?tabs=dotnet-cli) to be able to [refer to services in .NET Aspire by their name](https://aspire.dev/fundamentals/service-discovery/) instead of having to manually configure addresses.

### Describe the solution you'd like

A2A libraries resolve service names to URLs. The following code works without crashing:

```csharp
// Initialize a resolver pointing at the remote agent's host.
A2ACardResolver itHelpdeskAgentResolver = new(new Uri("https+http://itservices-agent-api"));

// Resolve the agent card and create an AIAgent in one step.
AIAgent itHelpdeskAgent = await itHelpdeskAgentResolver.GetAIAgentAsync();
```

Reference: https://learn.microsoft.com/en-us/agent-framework/integrations/by-component/agent-services/a2a?pivots=programming-language-csharp#well-known-uri

### Describe alternatives you've considered

_No response_

### Additional context

Using the following code leads to a crash:

```csharp
// Initialize a resolver pointing at the remote agent's host.
A2ACardResolver itHelpdeskAgentResolver = new(new Uri("https+http://itservices-agent-api"));

// Resolve the agent card and create an AIAgent in one step.
AIAgent itHelpdeskAgent = await itHelpdeskAgentResolver.GetAIAgentAsync();
```

```
Unhandled exception. System.NotSupportedException: The 'https+http' scheme is not supported.
7
at System.Net.Http.SocketsHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
8
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
9
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
10
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
11
at A2A.A2ACardResolver.GetAgentCardAsync(CancellationToken cancellationToken)
12
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
13
at A2A.A2ACardResolver.GetAgentCardAsync(CancellationToken cancellationToken)
14
at A2A.A2ACardResolverExtensions.GetAIAgentAsync(A2ACardResolver resolver, HttpClient httpClient, A2AClientOptions options, ILoggerFactory loggerFactory, CancellationToken cancellationToken)
15
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
16
at A2A.A2ACardResolverExtensions.GetAIAgentAsync(A2ACardResolver resolver, HttpClient httpClient, A2AClientOptions options, ILoggerFactory loggerFactory, CancellationToken cancellationToken)
17
at Program.$(String[] args) in /workspaces/wsi-super-agent/backend/src/SuperAgentV2.AgentService/Program.cs:line 32
18
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
19
at Program.$(String[] args)
20
at Program.(String[] args)
21
--- End of stack trace from previous location ---
22
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
23
at A2A.A2ACardResolver.GetAgentCardAsync(CancellationToken cancellationToken)
24
at A2A.A2ACardResolverExtensions.GetAIAgentAsync(A2ACardResolver resolver, HttpClient httpClient, A2AClientOptions options, ILoggerFactory loggerFactory, CancellationToken cancellationToken)
```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

The issue is about adding support for the 'https+http' URI scheme used by .NET Service Discovery. Start by examining the A2ACardResolver constructor and the HttpClient usage in the codebase, likely in the A2A.A2ACardResolver class. Look for where URI schemes are validated or where HttpClient is configured. The goal is to modify the HTTP client to handle the 'https+http' scheme, possibly by customizing the HttpClientHandler or the URI resolution logic. Check existing tests for A2ACardResolver to understand the expected behavior and add tests for the new scheme.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.