Description
An agent mapped to a Responses API endpoint with app.MapOpenAIResponses(agent) never produces a function call for tools defined in the request body, even when the request includes those tools and sets tool_choice: "required".
Minimal reproduction
Register and map an agent:
// Program.cs
builder.AddOpenAIResponses();
IChatClient chatClient = new OpenAIClient(apiKey).GetChatClient(modelId).AsIChatClient();
var agent = builder.AddAIAgent("openai-agent-from-chat-client", instructions: null, chatClient: chatClient);
var app = builder.Build();
app.MapOpenAIResponses(agent);
Call the Responses endpoint with a tool and tool_choice: "required":
curl --location 'https://localhost:7205/openai-agent-from-chat-client/v1/responses' \
--header 'Content-Type: application/json' \
--data '{
"stream": false,
"input": [
{ "role": "user", "content": "What'\''s the current weather in Valencia? Use celsius and the get_weather tool" }
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "Retrieves current weather for the given location.",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "City and country e.g. Bogotá, Colombia" },
"units": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Units the temperature will be returned in." }
},
"required": ["location", "units"],
"additionalProperties": false
},
"strict": true
}
],
"tool_choice": "required"
}'
Expected behavior
The agent requests the get_weather function call (the response contains a function call item).
Actual behavior
No function call is ever emitted. The response is a plain text answer and the tools / tool_choice from the request appear to be ignored.
E.g:
"output": [
{
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Calling weather tool for Valencia, Celsius.\nI'm unable to call the weather tool in this environment right now.\n\nIf you'd like, I can:\n- show you how to check Valencia weather in Celsius quickly, or\n- help interpret a weather report if you paste it here.",
"annotations": [],
"logprobs": []
}
],
"type": "message",
"status": "completed",
"id": "msg_U3lQzbV6GbpqKgnwoCZEst4H9qwPv6PQEZdZBn8e19GoRHM3"
}
],
Environment
- OS: Windows 11 (x64)
- .NET 10
Reproduce using the following versions in 2 separate tests:
| Package |
Test A |
Test B |
Microsoft.Agents.AI |
1.9.0 |
1.6.1 |
Microsoft.Agents.AI.OpenAI |
1.9.0 |
1.6.1 |
Microsoft.Agents.AI.Hosting.OpenAI |
1.9.0-alpha.260603.1 |
1.7.0-alpha.260526.1 |
Code Sample
Error Messages / Stack Traces
Package Versions
Microsoft.Agents.AI: 1.9.0, Microsoft.Agents.AI.OpenAI: 1.9.0, Microsoft.Agents.AI.Hosting.OpenAI: 1.9.0-alpha.260603.1
.NET Version
.NET 10
Additional Context
The same request body sent directly to OpenAI (https://api.openai.com/v1/responses) does return a function_call:
"output": [
{
"id": "fc_0a6aa1d6b09e8366006a28014c4e6c8191bd92c7a54b751d16",
"type": "function_call",
"status": "completed",
"arguments": "{\"location\":\"Valencia, Spain\",\"units\":\"celsius\"}",
"call_id": "call_sPjLPnyYIgwhyl6fXZRROIGH",
"name": "get_weather"
}
]
Also, I tried this using the same agent mapped to a Chat Completions endpoint with app.MapOpenAIChatCompletions(agent) and it does use tools defined in the request body (using an equivalent request adapted for chat completions).
I also observed that the AIAgentResponseExecutor (
|
var chatOptions = new ChatOptions |
) doesn't map the tools received in the requests to the
ChatOptions object that's later used to run the agent. Not sure if that's the only thing causing this issue, but I'd be happy to try and send a PR!
Reference repo with the full reproduction: https://github.com/pawap90/AgentFramework.Hosting.OpenAI.Tests
Description
An agent mapped to a Responses API endpoint with
app.MapOpenAIResponses(agent)never produces a function call for tools defined in the request body, even when the request includes thosetoolsand setstool_choice: "required".Minimal reproduction
Register and map an agent:
Call the Responses endpoint with a tool and
tool_choice: "required":Expected behavior
The agent requests the
get_weatherfunction call (the response contains a function call item).Actual behavior
No function call is ever emitted. The response is a plain text answer and the
tools/tool_choicefrom the request appear to be ignored.E.g:
Environment
Reproduce using the following versions in 2 separate tests:
Microsoft.Agents.AIMicrosoft.Agents.AI.OpenAIMicrosoft.Agents.AI.Hosting.OpenAICode Sample
Error Messages / Stack Traces
Package Versions
Microsoft.Agents.AI: 1.9.0, Microsoft.Agents.AI.OpenAI: 1.9.0, Microsoft.Agents.AI.Hosting.OpenAI: 1.9.0-alpha.260603.1
.NET Version
.NET 10
Additional Context
The same request body sent directly to OpenAI (
https://api.openai.com/v1/responses) does return afunction_call:Also, I tried this using the same agent mapped to a Chat Completions endpoint with
app.MapOpenAIChatCompletions(agent)and it does use tools defined in the request body (using an equivalent request adapted for chat completions).I also observed that the
AIAgentResponseExecutor(agent-framework/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/AIAgentResponseExecutor.cs
Line 38 in 96d242f
ChatOptionsobject that's later used to run the agent. Not sure if that's the only thing causing this issue, but I'd be happy to try and send a PR!Reference repo with the full reproduction: https://github.com/pawap90/AgentFramework.Hosting.OpenAI.Tests