Skip to content

Python: [Bug]: Foundry Hosting - User messages added to conversation chat history for failed requests #7630

Open

Description

Description

If a user sends a message to a hosted agent that the agent cannot process while using a conversation, the input messages will be saved to the chat history for that conversation. This means that the every subsequent request using that conversation will fail, because the "bad" message will now be stored in the conversation's chat history.

Code Sample

First, deploy a hosted agent to Foundry (also occurs when running locally)

from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential

endpoint = "https://<RESOURCE>.services.ai.azure.com/api/projects/<PROJECT>"
agent_name = "<AGENT_NAME>"

with (
    DefaultAzureCredential() as credential,
    AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
):
    client = project_client.get_openai_client(agent_name=agent_name)
    conversation = client.conversations.create()

    response = client.responses.create(
        input=[
            {
                "role": "user",
                "content": "Hello, how are you?",
            },
            {
                "type": "function_call_output",
                "call_id": "call_12345abc",
                "output": "example function call output",
            },
        ],
        conversation=conversation.id,
    )

    if response.error:
        print(f"Error: {response.error}")
    else:
        print(f"Output: {response.output_text}")

    response2 = client.responses.create(
        input="Hello, how are you?",
        conversation=conversation.id,
    )

    if response2.error:
        print(f"Error: {response2.error}")
    else:
        print(f"Output: {response2.output_text}")
Error: ResponseError(code='server_error', message='("<class \'agent_framework_foundry._chat_client.FoundryChatClient\'> service failed to complete the prompt: Error code: 400 - {\'error\': {\'message\': \'No tool call found for function call output with call_id call_12345abc.\', \'type\': \'invalid_request_error\', \'param\': \'input\', \'code\': None}}", BadRequestError("Error code: 400 - {\'error\': {\'message\': \'No tool call found for function call output with call_id call_12345abc.\', \'type\': \'invalid_request_error\', \'param\': \'input\', \'code\': None}}"))')
Error: ResponseError(code='server_error', message='("<class \'agent_framework_foundry._chat_client.FoundryChatClient\'> service failed to complete the prompt: Error code: 400 - {\'error\': {\'message\': \'No tool call found for function call output with call_id call_12345abc.\', \'type\': \'invalid_request_error\', \'param\': \'input\', \'code\': None}}", BadRequestError("Error code: 400 - {\'error\': {\'message\': \'No tool call found for function call output with call_id call_12345abc.\', \'type\': \'invalid_request_error\', \'param\': \'input\', \'code\': None}}"))')
  • The first request fails, as expected, as this is a new conversation and there is no assistant tool call with ID call_12345abc in the conversation
  • However, the second request, which is valid, should succeed, however it doesn't because the input messages from the first request are now saved to the conversation.

While this is a contrived example, it shows that input messages should not be saved to a conversation unless the request was successful, otherwise the conversation cannot be used again. This is the case when using the Azure OpenAI.

Error Messages / Stack Traces

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.14

Additional Context

No response

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Aug 12, 2026
  2. github-actions commented on Aug 12, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    Repro: The orchestrator in azure.ai.agentserver.responses.hosting._orchestrator persists input items for ALL responses (including failed ones) via create_response, and InMemoryResponseProvider.get_history_item_ids (store/_memory.py:317-324) returns items from all non-deleted responses without checking status. The fix location is in _handle_inner_agent (packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py, around line 459's finally block) or in the orchestrator's terminal persistence logic — either skip persisting input_items when status is "failed", or filter them out in get_history_item_ids. Minimal repro: send a request with conversation_id where agent.run raises, then send a second request in the same conversation and observe that the failed input appears in history.

    • Failing test: python/packages/foundry_hosting/tests/test_repro_7630.py
    • Files examined: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py, python/.venv/lib/python3.13/site-packages/azure/ai/agentserver/responses/hosting/_orchestrator.py, python/.venv/lib/python3.13/site-packages/azure/ai/agentserver/responses/store/_memory.py, python/.venv/lib/python3.13/site-packages/azure/ai/agentserver/responses/_response_context.py, python/packages/foundry_hosting/tests/test_responses.py
    • Tests run: packages/foundry_hosting/tests/test_repro_7630.py::TestIssue7630FailedRequestHistoryPollution::test_failed_request_input_not_in_subsequent_history, packages/foundry_hosting/tests/test_repro_7630.py::TestIssue7630FailedRequestHistoryPollution::test_failed_request_input_items_stored_in_conversation
    • Reported version: 1.0.0b260730
    • Current version: 1.0.0b260730
  3. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Aug 12, 2026
  4. added
    hostingUsage: [Issues, PRs], Target: all hosting related solutions
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Aug 13, 2026
  5. moonbox3 commented on Sep 9, 2026

    @moonbox3
    Contributor

    This should be handled in Azure/azure-sdk-for-python#48929. Please do not open a PR in MAF. Leaving open to track the dependency work/fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

hostingUsage: [Issues, PRs], Target: all hosting related solutionspythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions