Repository navigation
Python: [Bug]: Duplicate function call in Foundry Hosted agent when streaming #7485
Copy link
Copy link
Closed
Copy link
Labels
pythonUsage: [Issues, PRs], Target: PythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
Description
Description
If a Foundry Hosted agent calls a declaration-only function, there will be two function calls with the same ID in the response sent back to the user, with the second call having no arguments. This only occurs when streaming.
Code Sample
import os
from agent_framework import Agent, FunctionTool
from agent_framework.foundry import FoundryChatClient, ResponsesHostServer
from azure.identity import DefaultAzureCredential
from pydantic import BaseModel
class AddNumbersInput(BaseModel):
a: float
b: float
tool = FunctionTool(
name="add_numbers",
description="Adds two numbers together.",
input_model=AddNumbersInput,
)
def main():
client = FoundryChatClient(credential=DefaultAzureCredential())
agent = Agent(
client=client,
instructions="You are an assistant that performs calculations.",
tools=[tool],
default_options={"store": False},
)
server = ResponsesHostServer(agent)
server.run()
if __name__ == "__main__":
main()$ curl http://localhost:8088/responses -d '{"input": "Add 2+2", "stream": true}'
event: response.created
data: {"type": "response.created", "response": {"id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "object": "response", "output": [], "created_at": 1785763615, "model": "", "status": "in_progress", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": {}, "agent_session_id": "0922dfbc70ce049f403ffc9b0ec4694701412f3a96c802df5dfd1e931ee9973"}, "sequence_number": 0}
event: response.in_progress
data: {"type": "response.in_progress", "response": {"id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "object": "response", "output": [], "created_at": 1785763615, "model": "", "status": "in_progress", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": {}, "agent_session_id": "0922dfbc70ce049f403ffc9b0ec4694701412f3a96c802df5dfd1e931ee9973"}, "sequence_number": 1}
event: response.output_item.added
data: {"type": "response.output_item.added", "output_index": 0, "item": {"type": "function_call", "id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "call_id": "call_r6M1vyNq7enQTx3C0fxWM3fj", "name": "add_numbers", "arguments": "", "status": "in_progress", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": null}, "sequence_number": 2}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "{\"", "sequence_number": 3}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "a", "sequence_number": 4}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "\":", "sequence_number": 5}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "2", "sequence_number": 6}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": ",\"", "sequence_number": 7}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "b", "sequence_number": 8}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "\":", "sequence_number": 9}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "2", "sequence_number": 10}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "delta": "}", "sequence_number": 11}
event: response.function_call_arguments.done
data: {"type": "response.function_call_arguments.done", "item_id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "output_index": 0, "name": "add_numbers", "arguments": "{\"a\":2,\"b\":2}", "sequence_number": 12}
event: response.output_item.done
data: {"type": "response.output_item.done", "output_index": 0, "item": {"type": "function_call", "id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "call_id": "call_r6M1vyNq7enQTx3C0fxWM3fj", "name": "add_numbers", "arguments": "{\"a\":2,\"b\":2}", "status": "completed", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": null}, "sequence_number": 13}
event: response.output_item.added
data: {"type": "response.output_item.added", "output_index": 1, "item": {"type": "function_call", "id": "fc_4d8d7c08af3167e700jS1Mvwuxa2kItGS5QFjpaaetf3QlcKVC", "call_id": "call_r6M1vyNq7enQTx3C0fxWM3fj", "name": "add_numbers", "arguments": "", "status": "in_progress", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": null}, "sequence_number": 14}
event: response.function_call_arguments.delta
data: {"type": "response.function_call_arguments.delta", "item_id": "fc_4d8d7c08af3167e700jS1Mvwuxa2kItGS5QFjpaaetf3QlcKVC", "output_index": 1, "delta": "", "sequence_number": 15}
event: response.function_call_arguments.done
data: {"type": "response.function_call_arguments.done", "item_id": "fc_4d8d7c08af3167e700jS1Mvwuxa2kItGS5QFjpaaetf3QlcKVC", "output_index": 1, "name": "add_numbers", "arguments": "", "sequence_number": 16}
event: response.output_item.done
data: {"type": "response.output_item.done", "output_index": 1, "item": {"type": "function_call", "id": "fc_4d8d7c08af3167e700jS1Mvwuxa2kItGS5QFjpaaetf3QlcKVC", "call_id": "call_r6M1vyNq7enQTx3C0fxWM3fj", "name": "add_numbers", "arguments": "", "status": "completed", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": null}, "sequence_number": 17}
event: response.completed
data: {"type": "response.completed", "response": {"id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "object": "response", "output": [{"type": "function_call", "id": "fc_4d8d7c08af3167e700WmCo1b0kSwIguAqHhGrzYh7x2HSHtI11", "call_id": "call_r6M1vyNq7enQTx3C0fxWM3fj", "name": "add_numbers", "arguments": "{\"a\":2,\"b\":2}", "status": "completed", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": null}, {"type": "function_call", "id": "fc_4d8d7c08af3167e700jS1Mvwuxa2kItGS5QFjpaaetf3QlcKVC", "call_id": "call_r6M1vyNq7enQTx3C0fxWM3fj", "name": "add_numbers", "arguments": "", "status": "completed", "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": null}], "created_at": 1785763615, "model": "", "status": "completed", "completed_at": 1785763625, "response_id": "caresp_4d8d7c08af3167e700VtUMAgrxQwKp6OWy5slewxER3YefSc99", "agent_reference": {}, "agent_session_id": "0922dfbc70ce049f403ffc9b0ec4694701412f3a96c802df5dfd1e931ee9973"}, "sequence_number": 18}Package Versions
agent-framework-core: 1.13.0, agent-framework-foundry: 1.10.4, agent-framework-foundry-hosting: 1.0.0b260730 agent-framework-openai: 1.12.0
Python Version
3.13
Additional Context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
pythonUsage: [Issues, PRs], Target: PythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Aug 4, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
Repro: _OutputItemTracker.handle() in packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py closes the active function_call builder when a non-delta Content (e.g. usage from response.completed) triggers the else branch at line 1034-1036. After that, the FunctionInvocationLayer re-emits the declaration-only call (from _handle_function_call_results in packages/core/agent_framework/_tools.py:2679-2692), and the tracker opens a second function_call builder with empty arguments. Minimal repro: stream an agent with a declaration-only FunctionTool where a usage Content arrives between the argument deltas and the post-stream re-emit.
python/packages/foundry_hosting/tests/test_responses_duplicate_fc.pyagent-framework-core: 1.13.0, agent-framework-foundry: 1.10.4, agent-framework-foundry-hosting: 1.0b260730agent-framework-foundry-hosting: 1.0b260730