@@ -223,18 +223,15 @@ async def event_loop_cycle(
223223
224224 tracer .end_event_loop_cycle_span (cycle_span , message )
225225 yield EventLoopStopEvent (stop_reason , message , agent .event_loop_metrics , invocation_state ["request_state" ])
226- except StructuredOutputException as e :
226+ except (
227+ StructuredOutputException ,
228+ EventLoopException ,
229+ ContextWindowOverflowException ,
230+ MaxTokensReachedException ,
231+ ) as e :
232+ # These exceptions should bubble up directly rather than get wrapped in an EventLoopException
227233 tracer .end_span_with_error (cycle_span , str (e ), e )
228234 raise
229- except EventLoopException as e :
230- tracer .end_span_with_error (cycle_span , str (e ), e )
231- # Don't yield or log the exception - we already did it when we
232- # raised the exception and we don't need that duplication.
233- raise
234- except (ContextWindowOverflowException , MaxTokensReachedException ) as e :
235- # Special cased exceptions which we want to bubble up rather than get wrapped in an EventLoopException
236- tracer .end_span_with_error (cycle_span , str (e ), e )
237- raise e
238235 except Exception as e :
239236 tracer .end_span_with_error (cycle_span , str (e ), e )
240237 # Handle any other exceptions
0 commit comments