Skip to content

Duplicated function_call entries when using openai responses api #5136

@wodwiii

Description

@wodwiii

Bug Description

When using the OpenAI Responses API, function_call items from a previous response are duplicated in subsequent requests.

This results in the same tool call appearing multiple times in the OpenAI logs for a single turn.

Expected Behavior

  • Each tool call should appear only once in OpenAI logs

Reproduction Steps

1. Configure the agent LLM to use openai response api:

llm = openai.responses.LLM(
    model="gpt-5.4",
    temperature=0.4,
)

2. Ask the agent anything that triggers a tool call.
3. Inspect the OpenAI logs for the request.

Operating System

macOS Tahoe

Models Used

GPT 5.4

Package Versions

livekit-agents[openai]==1.4.6

Session/Room/Call IDs

No response

Proposed Solution

Filter out previously emitted function_call items when previous_response_id is present:

    async def _run_impl(self) -> None:
        self._response_completed = False
        chat_ctx, _ = self._chat_ctx.to_provider_format(format="openai.responses")

        if "previous_response_id" in self._extra_kwargs and self._llm._pending_tool_calls:
            chat_ctx = [
                item for item in chat_ctx
                if not (
                    isinstance(item, dict)
                    and item.get("type") == "function_call"
                    and item.get("call_id") in self._llm._pending_tool_calls
                )
            ]

Additional Context

No response

Screenshots and Recordings

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions