a2aproject / a2aproject/a2a-dotnet

[Feat]: .NET Service Discovery support

Aperta
#473 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
262
Fork
64
Merge medio
5g 2h
PR unite (30g)
31

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.