Skip to content

Commit 80e7e7a

Browse files
committed
Fix Live lifecycle bugs in query.py streaming
- Drop eager Live restart after a tool call, mirroring the lazy pattern used in chat.py (commit 8708fc4 applied the fix only to chat.py) - Start Live inside the try block so a synchronous raise cannot leak it
1 parent dab7379 commit 80e7e7a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

openkb/agent/query.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,22 @@ def _start_live() -> Live | None:
137137
lv.start()
138138
return lv
139139

140-
live = _start_live()
141-
140+
live: Live | None = None
142141
result = Runner.run_streamed(agent, question, max_turns=MAX_TURNS)
143142
collected: list[str] = []
144143
segment: list[str] = []
145144
try:
145+
live = _start_live()
146146
async for event in result.stream_events():
147147
if isinstance(event, RawResponsesStreamEvent):
148148
if isinstance(event.data, ResponseTextDeltaEvent):
149149
text = event.data.delta
150150
if text:
151151
collected.append(text)
152152
segment.append(text)
153-
if live:
153+
if console is not None:
154+
if live is None:
155+
live = _start_live()
154156
live.update(_make_markdown("".join(segment)))
155157
else:
156158
sys.stdout.write(text)
@@ -166,7 +168,6 @@ def _start_live() -> Live | None:
166168
sys.stdout.write(f"\n[tool call] {raw.name}({args})\n\n")
167169
sys.stdout.flush()
168170
segment = []
169-
live = _start_live()
170171
elif item.type == "tool_call_output_item":
171172
pass
172173
finally:

0 commit comments

Comments
 (0)