Skip to content

Streaming Output issue got unnecesory text in output #824

Open
@dongxiaohuang

Description

@dongxiaohuang

I am using deepseek model in litellmModel, but got an unexpected warning.

from __future__ import annotations

import asyncio
from openai.types.responses import ResponseContentPartDoneEvent, ResponseTextDeltaEvent

from agents import Agent, Runner, RawResponsesStreamEvent, function_tool, set_tracing_disabled
from agents.extensions.models.litellm_model import LitellmModel
set_tracing_disabled(disabled=True)

@function_tool
def get_weather(city: str):
    print(f"[debug] getting weather for {city}")
    return f"The weather in {city} is sunny."


async def main():
    agent = Agent(
        name="Assistant",
        instructions="You only respond in haikus.",
        model=LitellmModel(
            base_url=BASE_URL,
            api_key=API_KEY,
            model="deepseek/deepseek-chat",
        ),
        tools=[get_weather],
    )

    result = Runner.run_streamed(agent, "What's the weather in Tokyo?")
    async for event in result.stream_events():
        if not isinstance(event, RawResponsesStreamEvent):
            continue
        data = event.data
     
        if isinstance(data, ResponseTextDeltaEvent):
            print(data.delta, end="", flush=True)


if __name__ == "__main__":
    # First try to get model/api key from args
    asyncio.run(main())

Got unexpected warning:

[debug] getting weather for Tokyo
Tokyo's sky so bright,
Sunny day with golden light,
Warm and clear delight.Unclosed client session

client_session: <aiohttp.client.ClientSession object at 0x7fd47e1db3d0>
Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x7fd482a1af20>, 855889.472732536)])']
connector: <aiohttp.connector.TCPConnector object at 0x7fd47e1dbfa0>

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