Skip to content

Commit e33e1e6

Browse files
fix: closing streaming contexts for reasoning at done event
1 parent 8b721d5 commit e33e1e6

File tree

2 files changed

+15
-5
lines changed
  • examples/tutorials/10_agentic/10_temporal/010_agent_chat/project
  • src/agentex/lib/core/services/adk/providers

2 files changed

+15
-5
lines changed

examples/tutorials/10_agentic/10_temporal/010_agent_chat/project/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
241241
# Ask the model to include a short reasoning summary
242242
reasoning=Reasoning(effort="medium", summary="detailed"),
243243
),
244-
tools=[CALCULATOR_TOOL],
244+
# tools=[CALCULATOR_TOOL],
245245
)
246246
if self._state:
247247
# Update the state with the final input list if available

src/agentex/lib/core/services/adk/providers/openai.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,16 +830,26 @@ async def run_agent_streamed_auto_send(
830830
item_id = event.data.item_id
831831
summary_index = event.data.summary_index
832832

833-
# Note: We don't close the streaming context here since there might be more deltas
834-
# The context will be closed when the reasoning item is completely done
833+
# Finish the streaming context for this reasoning item
834+
if item_id in item_id_to_streaming_context and item_id in unclosed_item_ids:
835+
streaming_context = item_id_to_streaming_context[
836+
item_id
837+
]
838+
await streaming_context.close()
839+
unclosed_item_ids.remove(item_id)
835840

836841
elif isinstance(event.data, ResponseReasoningTextDoneEvent):
837842
# Handle reasoning content text completion
838843
item_id = event.data.item_id
839844
content_index = event.data.content_index
840845

841-
# Note: We don't close the streaming context here since there might be more deltas
842-
# The context will be closed when the reasoning item is completely done
846+
# Finish the streaming context for this reasoning item
847+
if item_id in item_id_to_streaming_context and item_id in unclosed_item_ids:
848+
streaming_context = item_id_to_streaming_context[
849+
item_id
850+
]
851+
await streaming_context.close()
852+
unclosed_item_ids.remove(item_id)
843853

844854
elif isinstance(event.data, ResponseOutputItemDoneEvent):
845855
# Handle item completion

0 commit comments

Comments
 (0)