Skip to content

.NET: [Bug]: Tool calls do not work without providing them in tools array #3855

@KornelijusS

Description

@KornelijusS

Description

When using GetAIAgentAsync without providing the tools list, the tools are being map in tool map using AsAITool, which instead of getting the real function anem and description OpenAIResponsesChatClient.ResponseToolAITool(tool), which uses Name => Tool.GetType().Name this means that the tool will always have the worng name in the map and will never be invocated. The reason I need this is beacause I am trying to resolve the function calls my self, but function invocation never reaches the FunctionInvoker as toolMap.TryGetValue is always false. The correct information remain inside AITool.Tool

The main problem is that there is no way to manually resolve the tool calls without always providing their method in tools array, so even manually handlem is not an options as middleware also does not get it

Code Sample

IChatClient GetChatClient(IChatClient chatClient)
{
    var functionClient = new FunctionInvokingChatClient(chatClient);
    functionClient.FunctionInvoker = FunctionInvoker;
    functionClient.TerminateOnUnknownCalls = false;
    return functionClient;
}

ValueTask<object?> FunctionInvoker(FunctionInvocationContext context, CancellationToken token)
{
    if (context.Function.Name == "GetWeather")
    {
        return new ValueTask<object?>(
            $"The weather in {context.Arguments.GetValueOrDefault("location")} is cloudy with a high of 15°C.");
    }

    return new ValueTask<object?>(DateTimeOffset.UtcNow);
}
var modifiedAgent =
    await aiProjectClient.GetAIAgentAsync("TestKS", clientFactory: GetChatClient);

Error Messages / Stack Traces

Error: Requested function "GetWeather" not found.

Package Versions

Azure.AI.Projects 1.2.0-beta.5; Microsoft.Agents.AI.AzureAI 1.0.0-preview.260205.1

.NET Version

.NET10.0

Additional Context

No response

Metadata

Metadata

Assignees

Labels

.NETagentsIssues related to single agentsbugSomething isn't workingv1.0Features being tracked for the version 1.0 GA

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions