Skip to content

.NET: Opt in to client function forwarding for Responses hosting - #7844

Merged
Roger Barreto (rogerbarreto) merged 8 commits into
mainfrom
copilot/fix-tools-in-responses-api
Sep 9, 2026
Merged

.NET: Opt in to client function forwarding for Responses hosting#7844
Roger Barreto (rogerbarreto) merged 8 commits into
mainfrom
copilot/fix-tools-in-responses-api

Conversation

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

Hosted agents exposed over the OpenAI Responses protocol reject client-provided tools by default. Applications sometimes need to supply function declarations through the conventional tools request field so the model can request functions executed by the calling application.

This proposal adds an explicit experimental opt-in without promising conflict resolution in the hosting layer. Client function names, descriptions, and schemas can steer the model away from hosted functions and cause arguments or data to be returned to the caller.

Description & Review Guide

  • What are the major changes?

OpenAIResponsesMapOptions.DangerouslyAllowClientFunctionTools is an experimental boolean, defaulting to false. When enabled without a custom factory, it selects a built-in mapping that converts function declarations into ChatClientAgentRunOptions.ChatOptions.Tools, preserving name, description, parameter schema, and optional strict.

#pragma warning disable MAAI001
var mapOptions = new OpenAIResponsesMapOptions
{
    DangerouslyAllowClientFunctionTools = true
};
#pragma warning restore MAAI001

app.MapOpenAIResponses(agent, responsesPath: null, mapOptions);

RunOptionsFactory is the single mapping entry point. A custom factory receives the complete request settings, including raw Tools, replaces the built-in mapping, and returns options that the hosting layer does not modify. The boolean has no effect on a custom factory. The existing OpenAIResponses.ToAgentRunRequest(body, mapOptions) helper uses the same factory; no agent-aware overload is needed.

The previous conflict behavior types, name checks, deduplication, conflict decorator, and parallel-call override have been removed. The internal converter returns a named tuple (ClientTools, RemainingTools) and does not assign a support policy to entries it leaves unconverted.

  • What is the impact of these changes?

Default endpoints still reject client tools. The opt-in enables only function declarations; it does not enable request tool_choice or other unsupported request settings. Non-function tools remain rejected by the built-in mapping.

Duplicate names are forwarded without resolving collisions. The downstream ChatClient and provider determine whether duplicates are accepted and which function is selected. The hosting layer does not guarantee hosted-function precedence and does not change the developer's parallel-call configuration.

The mapping produces ChatClientAgentRunOptions, not a provider-neutral tool contract. Other agent implementations may ignore those options; the hosting layer does not reject agents by type or add function support to them. Developers can supply a custom factory for their agent's contract.

The existing MapOpenAIResponses limitation on subsequent function_call_output input items is not addressed here. This proposal covers declaration forwarding and returned function calls, not the complete client function result continuation flow.

  • What do you want reviewers to focus on?

The explicit boolean opt-in and risk documentation; the single mapping contract and custom-factory precedence; declaration fidelity; and leaving collision handling, execution, and parallelism to downstream components. Coverage includes default rejection, raw request preservation, duplicate forwarding, custom factories, hosted functions and MCP tools, non-chat agents, and a credential-gated live OpenAI scenario.

Related Issue

Related to #6416. This proposal addresses opt-in declaration forwarding, but does not implement request tool_choice or client function result continuation, so it does not automatically close the full issue.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Copilot AI balanced review requested due to automatic review settings August 24, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix hosted agents ignoring tools in Responses API .NET: Forward opted-in Responses API function tools Aug 24, 2026
@rogerbarreto

Copy link
Copy Markdown
Member

Closing this, not ready as a draft, just for analysis.

@rogerbarreto Roger Barreto (rogerbarreto) changed the title .NET: Forward opted-in Responses API function tools .NET: Safely opt in to Responses API client function tools Aug 28, 2026
@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Aug 28, 2026
@rogerbarreto
Roger Barreto (rogerbarreto) marked this pull request as ready for review August 28, 2026 14:53
@github-code-quality

github-code-quality Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall line coverage in commit 196d3b7 in the copilot/fix-tools-in... branch is 84%. Line coverage data for the main branch is not yet available.

Show a line coverage summary of the most covered files.
File main copilot/fix-tools-in... 196d3b7 +/-
/home/runner/wo...valConverter.cs 100%
/home/runner/wo...entsProvider.cs 99%
/home/runner/wo...nticAnalyzer.cs 94%
/home/runner/wo...tClientAgent.cs 91%
/home/runner/wo...putConverter.cs 90%
/home/runner/wo...kflowBuilder.cs 90%
/home/runner/wo...kflowSession.cs 87%
/home/runner/wo...SkillsSource.cs 86%
/home/runner/wo...onExtensions.cs 81%
/home/runner/wo...ctionVisitor.cs 70%

Updated September 09, 2026 15:04 UTC

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2d6ca13a-3274-4167-a074-bfe4df9423ed
@rogerbarreto

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (7 commit(s)): 817af2d50f55, 50aa41849948, 41c68b25e1d3, bc86a5305cf8, 01193fb78ca8, 2790966322f7, 87f357a78cb1
Model: gpt-5.6-sol-fast

Overview

The PR preserves default rejection, converts opted-in client functions to declaration-only tools, disables parallel tool calls, and applies conflict checks both before execution and after normal ChatOptions merging. Tests cover the three policies for statically discoverable ChatClientAgent tools and preserve hosted MCP behavior. Residual gaps remain for non-chat agents, tools hidden inside a custom ChatClientFactory, and conflicts introduced late by an AIContextProvider.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (3 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/OpenAIResponseRunOptionsBuilder.cs

Comment thread dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/OpenAIResponsesMapOptions.cs Outdated
Centralize mapping in RunOptionsFactory and make dangerous opt-in a boolean. Leave conflict handling and tool execution to downstream clients.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2d6ca13a-3274-4167-a074-bfe4df9423ed
@rogerbarreto Roger Barreto (rogerbarreto) changed the title .NET: Safely opt in to Responses API client function tools .NET: Opt in to client function forwarding for Responses hosting Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Hosted agents exposed via the Responses API ignore tools defined in the request body

5 participants