Skip to content
12 changes: 12 additions & 0 deletions python/packages/core/agent_framework/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,12 @@ async def _finalize_stream() -> None:
from ._types import ChatResponse

try:
if not result_stream._consumed:
# Stream did not complete normally (e.g., it errored). Skip
# get_final_response() to avoid firing result hooks such as
# after_run context providers on error paths. The span is
# still closed in the finally block below.
Comment thread
droideronline marked this conversation as resolved.
Outdated
return
response: ChatResponse[Any] = await result_stream.get_final_response()
duration = duration_state.get("duration")
response_attributes = _get_response_attributes(attributes, response)
Expand Down Expand Up @@ -1579,6 +1585,12 @@ async def _finalize_stream() -> None:
from ._types import AgentResponse

try:
if not result_stream._consumed:
# Stream did not complete normally (e.g., it errored). Skip
# get_final_response() to avoid firing result hooks such as
# after_run context providers on error paths. The span is
# still closed in the finally block below.
return
response: AgentResponse[Any] = await result_stream.get_final_response()
Comment thread
droideronline marked this conversation as resolved.
Outdated
duration = duration_state.get("duration")
response_attributes = _get_response_attributes(
Expand Down