豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 996be13

Browse files
Aditya SinghAditya Singh
authored andcommitted
fix: address CodeRabbit review comments on PR #3
- Import ResponseCreatedEvent and reset _reasoning_snapshot to "" when a ResponseCreatedEvent is received inside the retry stream loop, fixing the bug where snapshot text would be duplicated across retries - In test_reasoning_delta_event_type_field: add found=False flag and assert found after the loop so the test properly fails when no ReasoningDeltaEvent is emitted
1 parent e5baab1 commit 996be13

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/agents/run_internal/run_loop.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Awaitable, Callable, Mapping
1212
from typing import Any, TypeVar, cast
1313

14-
from openai.types.responses import Response, ResponseCompletedEvent, ResponseOutputItemDoneEvent
14+
from openai.types.responses import Response, ResponseCompletedEvent, ResponseCreatedEvent, ResponseOutputItemDoneEvent
1515
from openai.types.responses.response_reasoning_text_delta_event import (
1616
ResponseReasoningTextDeltaEvent,
1717
)
@@ -1295,6 +1295,12 @@ async def rewind_model_request() -> None:
12951295
async for event in retry_stream:
12961296
streamed_result._event_queue.put_nowait(RawResponsesStreamEvent(data=event))
12971297

1298+
# Reset the reasoning snapshot at the start of each new response attempt
1299+
# (e.g., after a retry) so the snapshot field never contains stale text
1300+
# from a failed previous attempt.
1301+
if isinstance(event, ResponseCreatedEvent):
1302+
_reasoning_snapshot = ""
1303+
12981304
# Emit a ReasoningDeltaEvent for reasoning/thinking deltas so consumers don't have
12991305
# to unwrap the raw event themselves.
13001306
if isinstance(event, ResponseReasoningSummaryTextDeltaEvent):

tests/test_reasoning_delta_stream_event.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ async def test_reasoning_delta_event_type_field() -> None:
9797
agent = Agent(name="A", model=model)
9898
result = Runner.run_streamed(agent, input="hi")
9999

100+
found = False
100101
async for event in result.stream_events():
101102
if isinstance(event, ReasoningDeltaEvent):
102103
assert event.type == "reasoning_delta"
104+
found = True
103105
break
106+
assert found, "Expected at least one ReasoningDeltaEvent but none were emitted"
104107

105108

106109
@pytest.mark.asyncio

0 commit comments

Comments
 (0)