anthropics / anthropics/anthropic-sdk-csharp
AsAITool(BetaToolUnion) returns the union type instead of the tool name
- Vorherrschende Sprache
- C#
- Sterne
- 322
- Forks
- 105
- Ø Merge
- 1 T. 6 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
## 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
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.