Skip to content

Tool calling fails with 'Duplicate function declaration found' #189

@sharpomatic

Description

@sharpomatic

Environment details

  • Programming language: C#
  • OS: Win11
  • Language runtime version: .NET 10
  • Package version: 0.13.1

Steps to reproduce

  1. Take you example code from the README for tool calling. Like this.
using Google.GenAI;
using Microsoft.Extensions.AI;
using System.ComponentModel

// assuming credentials are set up in environment variables as instructed above.
IChatClient chatClient = new Client().AsIChatClient("gemini-2.0-flash")
    .AsBuilder()
    .UseFunctionInvocation()
    .UseOpenTelemetry()
    .Build();

ChatOptions options = new()
{
    Tools = [AIFunctionFactory.Create(([Description("The name of the person whose age is to be retrieved")] string personName) => personName switch
    {
        "Alice" => 30,
        "Bob" => 25,
        _ => 35
    }, "get_person_age", "Gets the age of the specified person");
};

await foreach (var update in chatClient.GetStreamingResponseAsync("How much older is Alice than Bob?", options))
{
    Console.Write(update);
}
  1. Modify the ChatOptions so it has a GenerateContentConfig instance.
var generateContentConfig = new Google.GenAI.Types.GenerateContentConfig();

ChatOptions options = new()
{
    RawRepresentationFactory = (_) => generateContentConfig,
    Tools = [AIFunctionFactory.Create(([Description("The name of the person whose age is to be retrieved")] string personName) => personName switch
    {
        "Alice" => 30,
        "Bob" => 25,
        _ => 35
    }, "get_person_age", "Gets the age of the specified person");
};

Having the RawRepresentationFactory will cause the tool calling to now fail with an error of 'Duplicate function declaration found:'. Remove that entry in ChatOptions and it works again.

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions