Skip to content

Python: [Bug]: Tool calling not working with Responses API #3304

Closed

Description

Description

When using AzureOpenAIResponsesClient, tool calling does not work, as the value of previous_response_id is not updated when submitting the tool call results back to the LLM. It seems to only work if a tool is called during the first message to the LLM.

Code Sample

from typing import Annotated

from agent_framework import ChatAgent
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import DefaultAzureCredential
from pydantic import Field


def get_weather(
    location: Annotated[str, Field(description="The location to get the weather for.")],
) -> str:
    """Get the weather for a given location."""
    return f"The weather in {location} is cloudy with a high of 15°C."


async def main():
    agent = ChatAgent(
        chat_client=AzureOpenAIResponsesClient(credential=DefaultAzureCredential()),
        instructions="You are a helpful assistant",
        tools=[get_weather],
    )

    thread = agent.get_new_thread()

    res = await agent.run("What's the weather like in New York?", thread=thread)
    print(res.text)

    res = await agent.run("What about San Francisco?", thread=thread)
    print(res.text)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Error Messages / Stack Traces

The weather in New York is currently cloudy with a high of 15°C.
Traceback (most recent call last):
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/openai/_responses_client.py", line 233, in _inner_get_response
    response = await client.responses.create(stream=False, **run_options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/openai/resources/responses/responses.py", line 2480, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
    ...<42 lines>...
    )
    ^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/openai/_base_client.py", line 1797, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/openai/_base_client.py", line 1597, in request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': 'No tool call found for function call output with call_id call_BrMzl1qz4aUhyzGgpMZgfE0L.', 'type': 'invalid_request_error', 'param': 'input', 'code': None}}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cecheta/Code/repo/main.py", line 35, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/home/cecheta/.pyenv/versions/3.13.9/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/home/cecheta/.pyenv/versions/3.13.9/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/cecheta/.pyenv/versions/3.13.9/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/cecheta/Code/repo/main.py", line 28, in main
    res = await agent.run("What about San Francisco?", thread=thread)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/_middleware.py", line 1253, in middleware_enabled_run
    return await original_run(self, normalized_messages, thread=thread, **kwargs)  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/observability.py", line 1342, in trace_run
    return await run_func(self, messages=messages, thread=thread, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/_agents.py", line 854, in run
    response = await self.chat_client.get_response(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/_tools.py", line 1927, in function_invocation_wrapper
    response = await func(self, messages=prepped_messages, options=options, **filtered_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/observability.py", line 1073, in trace_get_response
    return await func(
           ^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/_middleware.py", line 1373, in middleware_enabled_get_response
    return await original_get_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/_clients.py", line 339, in get_response
    return await self._inner_get_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/home/cecheta/Code/repo/.venv/lib/python3.13/site-packages/agent_framework/openai/_responses_client.py", line 241, in _inner_get_response
    raise ServiceResponseException(
    ...<2 lines>...
    ) from ex
agent_framework.exceptions.ServiceResponseException: <class 'agent_framework.azure._responses_client.AzureOpenAIResponsesClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': 'No tool call found for function call output with call_id call_BrMzl1qz4aUhyzGgpMZgfE0L.', 'type': 'invalid_request_error', 'param': 'input', 'code': None}}

Package Versions

agent-framework==1.0.0b260116
agent-framework-a2a==1.0.0b260116
agent-framework-ag-ui==1.0.0b260116
agent-framework-anthropic==1.0.0b260116
agent-framework-azure-ai==1.0.0b260116
agent-framework-azure-ai-search==1.0.0b260116
agent-framework-azurefunctions==1.0.0b260116
agent-framework-chatkit==1.0.0b260116
agent-framework-copilotstudio==1.0.0b260107
agent-framework-core==1.0.0b260116
agent-framework-declarative==1.0.0b260116
agent-framework-devui==1.0.0b260116
agent-framework-lab==1.0.0b251024
agent-framework-mem0==1.0.0b260116
agent-framework-ollama==1.0.0b260116
agent-framework-purview==1.0.0b260116
agent-framework-redis==1.0.0b260116

Python Version

Python 3.13.9

Additional Context

No response

Metadata

Metadata

Labels

bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)pythonUsage: [Issues, PRs], Target: Python

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions