-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Language: C# 13 & .Net 9
Package version: Microsoft.Agents.AI Version 1.0.0-preview.251204.1
SDK Use: Agents & Tool use on local machine with API connection to Anthropic Claude
Description of the bug
This is probably an issue with the Microsoft.Agents.AI nuget package (Version 1.0.0-preview.251204.1). in combination with the Anthropic nuget package (version 11.0.0)
Given the following code:
private async Task ProcessUserPrompt()
{
if (_userPrompts.TryDequeue(out var userPrompt))
{
if (string.IsNullOrWhiteSpace(userInput))
return;
try
{
await foreach (var update in _agent.RunStreamingAsync(userInput, _conversation))
{
if (update is null || update.Contents is null || update.Contents.Count == 0)
continue;
foreach (var content in update.Contents)
{
await _responseHandler.HandleContentUpdate(content);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"[ERROR] {ex.Message}");
}
}
}
When I submit a prompt that requires multiple tool calls, I get:
Anthropic.Exceptions.AnthropicBadRequestException: 'Status Code: BadRequest
{"type":"error","error":{"type":"invalid_request_error","message":"messages.3.content.2: tool_use ids must be unique"},"request_id":"req_011CVuhYG6F51BFJFQY2cyFG"}'
It has something to do with the AgentThread (here named _conversation) and tool calls with the same ID.
Using claude sonnet and opus (both 4.5) - I get the same exception.
Using gpt 5.1 - It works fine
Steps To Reproduce
- Use an API key to connect to claude sonnet or opus.
public IChatClient CreateLlmConnectionClient(string model, string apiKey)
{
var options = new ClientOptions
{
APIKey = apiKey
};
return new AnthropicClient(options)
.AsIChatClient(model);
}
}
- pass the llm chatClient in and create an agent
public ChatClientAgent CreateAgent(string name, IChatClient chatClient)
{
return new ChatClientAgent
(
chatClient,
new ChatClientAgentOptions
{
Name = "MyAgent",
ChatOptions = new ChatOptions
{
Instructions = Instructions,
Tools = _uniqueTools,
}
}
);
}
-
Start a new conversation thread
_conversation = _agent.GetNewThread(); -
Submit a prompt that requires multiple tool calls to achieve.
The exception occurs inside this call: _agent.RunStreamingAsync(userInput, _conversation)
Expected behavior
I should not get an exception.
Screenshots
NA
Additional context
According to Anthropic: The issue is that the Microsoft.Agents.AI package isn't properly managing tool use IDs when working with our API.
Each tool use block needs a unique ID, and when there are parallel tool calls, all tool results must be grouped in a single user message with tool_result blocks coming before any text content.
This appears to be a bug in how the Microsoft.Agents.AI package is either:
A) Generating duplicate tool use IDs
B) Improperly formatting the conversation history when handling tool results
Metadata
Metadata
Assignees
Labels
Type
Projects
Status