Skip to content

Adding Tools to the Assistant ChatClient OpenAI Assistants level #6743

@rogerbarreto

Description

@rogerbarreto

Description

OpenAI Assistants has a peculiar behavior that it doesn't allow Tools override when tools are provided at the Agent/Assistant creation.

i.e:

The code below attempts to create a OpenAI Assistant with Function Tool Definition.

var assistantOptions = new AssistantCreationOptions();

// Converts and AIFunction and add as a Tool Definition
assistantOptions.Tools.Add(ToOpenAIAssistantsFunctionToolDefinition(aiFunction));

// Create Hosted Assistant Agent
var assistantCreateResult = await client.CreateAssistantAsync(model, assistantOptions).ConfigureAwait(false);

After creating an agent like above, attempting to use chatClient passing any of the AIFunction tools provided above in the chatOptions.Tools will throw the redundancy error below:

Unhandled exception. System.ClientModel.ClientResultException: HTTP 400 (invalid_request_error: )
Parameter: tools[3]

Function tools must have unique names.

Reproduction Steps

Create an Assistant Agent with tools and attempt to pass the same tools in a chatClient.GetResponseAsync call.

Expected behavior

Ideally AsIChatClient() should provide an extra set of Agent/Assistant level tools: [] parameters, so those tools can be used in GetResponseAsync or GetStreamingResponseAsync to check and remove redundancy.

Actual behavior

Creating an Assistant Agent with tools and attempt to pass the same tools in a chatClient.GetResponseAsync call gives back a 400 Bad Request with tool redudancy error

Known Workarounds

  1. Don't use hosted function calling.
  2. The caller must have to track on his side whenever he assigned tools to the agent creation, capture manually the FunctionInvokingChatClient and add those tools as AdditionalTools (for hosted function calling to work) and avoid in any further calls to the chat client to provide those tools in the chatOptions.

Metadata

Metadata

Assignees

Labels

area-aiMicrosoft.Extensions.AI libraries

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions