anthropics / anthropics/anthropic-sdk-csharp

AsAITool(BetaToolUnion) returns the union type instead of the tool name

Abierto
#249 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C#
Estrellas
322
Forks
105
Merge medio
1 d 6 h
PR fusionados (30 d)
9

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.