Skip to content

"Unrecognized" LLM completion with OpenAI Agents SDK + Streamed Chat Completions #1585

@reuank

Description

@reuank

Description

Hey there,

when I use the OpenAI Agents SDK (v0.6.4) together with the Chat Completions API and in streaming mode, I get an "Unrecognised" section in Logfire. This does not happen when using streaming with the Responses API.

Image

Repro script:

import asyncio

import logfire
from agents import Agent, RawResponsesStreamEvent, Runner, set_default_openai_api
from dotenv import load_dotenv
from logfire import ConsoleOptions
from openai.types.responses import ResponseCompletedEvent


async def main():
    agent = Agent(
        name="Weather Agent",
        instructions="Your job is to always answer with random weather predictions..",
    )

    # Streamed
    result = Runner.run_streamed(agent, input="What's the weather in Berlin?")
    async for event in result.stream_events():
        if isinstance(event, RawResponsesStreamEvent) and isinstance(event.data, ResponseCompletedEvent):
            print(event.data.response.output[0].content[0].text)

    # Non-streamed
    result = await Runner.run(agent, input="What's the weather in Berlin?")
    print(result.final_output)


if __name__ == "__main__":
    _ = load_dotenv()
    _ = logfire.configure(
        console=ConsoleOptions(min_log_level="info"),
        service_name="cc-test",
    )
    set_default_openai_api("chat_completions")
    logfire.instrument_openai_agents()
    asyncio.run(main())

Any ideas what could cause that? Is the issue on the Logfire or the Agents SDK side?

Thanks for your help!

Python, Logfire & OS Versions, related packages (not required)

$ logfire info
logfire="4.16.0"
platform="macOS-15.4.1-arm64-arm-64bit"
python="3.12.2 (main, Feb 25 2024, 03:55:42) [Clang 17.0.6 ]"
[related_packages]
requests="2.32.5"
pydantic="2.12.5"
openai="2.13.0"
protobuf="5.29.5"
rich="14.2.0"
executing="2.2.1"
opentelemetry-api="1.39.1"
opentelemetry-exporter-otlp-proto-common="1.39.1"
opentelemetry-exporter-otlp-proto-http="1.39.1"
opentelemetry-instrumentation="0.60b1"
opentelemetry-proto="1.39.1"
opentelemetry-sdk="1.39.1"
opentelemetry-semantic-conventions="0.60b1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions