anthropics / anthropics/anthropic-sdk-csharp
AsAITool(BetaToolUnion) returns the union type instead of the tool name
- Lingua principale
- C#
- Stelle
- 322
- Fork
- 105
- Merge medio
- 1g 6h
- PR unite (30g)
- 9
Descrizione
## Bug Description
`AsAITool(BetaToolUnion)` exposes the CLR union variant name through `AITool.Name`.
For custom `BetaTool` values, every wrapped tool reports `"BetaTool"` instead of its actual model-visible name. This can cause generic Microsoft.Extensions.AI middleware to treat distinct tools as duplicates.
## Reproduction
```csharp
using Anthropic.Models.Beta.Messages;
using Microsoft.Extensions.AI;
AITool first = new BetaToolUnion(new BetaTool
{
Name = "first_tool",
InputSchema = new InputSchema(),
}).AsAITool();
AITool second = new BetaToolUnion(new BetaTool
{
Name = "second_tool",
InputSchema = new InputSchema(),
}).AsAITool();
Console.WriteLine(first.Name); // BetaTool
Console.WriteLine(second.Name); // BetaTool
```
## Expected Behavior
```text
first_tool
second_tool
```
## Root Cause
The wrapper currently returns the variant's CLR type:
```csharp
public override string Name =>
tool.Value?.GetType().Name ?? base.Name;
```
For custom tools, it should return `BetaTool.Name`.
The underlying union is serialized correctly; this issue only affects the `AITool` metadata exposed to middleware.
## Environment
- Anthropic 12.42.0
- .NET 10
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.