@@ -268,6 +268,50 @@ public async Task<AgentExecutionResult> ExecuteAsync(
268268 "Agent execution timed out after {DurationMs}ms" ,
269269 stopwatch . ElapsedMilliseconds ) ;
270270 }
271+ catch ( InvalidOperationException ex )
272+ {
273+ stopwatch . Stop ( ) ;
274+ result . Success = false ;
275+ result . Error = ex . Message ;
276+ result . Duration = stopwatch . Elapsed ;
277+
278+ activity ? . SetStatus ( ActivityStatusCode . Error , ex . Message ) ;
279+ activity ? . AddEvent ( new ActivityEvent ( "exception" ,
280+ tags : new ActivityTagsCollection
281+ {
282+ { "exception.type" , ex . GetType ( ) . FullName } ,
283+ { "exception.message" , ex . Message }
284+ } ) ) ;
285+ activity ? . SetTag ( "error.type" , "invalid_operation" ) ;
286+
287+ TelemetryConfig . AgentExecutionErrorsCounter . Add ( 1 ,
288+ new KeyValuePair < string , object ? > ( "agent.id" , spec . AgentId ) ,
289+ new KeyValuePair < string , object ? > ( "error.type" , "invalid_operation" ) ) ;
290+
291+ _logger . LogError ( ex , "Invalid operation during agent execution after {DurationMs}ms" , stopwatch . ElapsedMilliseconds ) ;
292+ }
293+ catch ( TimeoutException ex )
294+ {
295+ stopwatch . Stop ( ) ;
296+ result . Success = false ;
297+ result . Error = ex . Message ;
298+ result . Duration = stopwatch . Elapsed ;
299+
300+ activity ? . SetStatus ( ActivityStatusCode . Error , ex . Message ) ;
301+ activity ? . AddEvent ( new ActivityEvent ( "exception" ,
302+ tags : new ActivityTagsCollection
303+ {
304+ { "exception.type" , ex . GetType ( ) . FullName } ,
305+ { "exception.message" , ex . Message }
306+ } ) ) ;
307+ activity ? . SetTag ( "error.type" , "timeout" ) ;
308+
309+ TelemetryConfig . AgentExecutionErrorsCounter . Add ( 1 ,
310+ new KeyValuePair < string , object ? > ( "agent.id" , spec . AgentId ) ,
311+ new KeyValuePair < string , object ? > ( "error.type" , "timeout" ) ) ;
312+
313+ _logger . LogError ( ex , "Agent execution timeout after {DurationMs}ms" , stopwatch . ElapsedMilliseconds ) ;
314+ }
271315 catch ( Exception ex )
272316 {
273317 stopwatch . Stop ( ) ;
@@ -288,7 +332,7 @@ public async Task<AgentExecutionResult> ExecuteAsync(
288332 new KeyValuePair < string , object ? > ( "agent.id" , spec . AgentId ) ,
289333 new KeyValuePair < string , object ? > ( "error.type" , ex . GetType ( ) . Name ) ) ;
290334
291- _logger . LogError ( ex , "Agent execution failed after {DurationMs}ms" , stopwatch . ElapsedMilliseconds ) ;
335+ _logger . LogError ( ex , "Unexpected agent execution failure after {DurationMs}ms" , stopwatch . ElapsedMilliseconds ) ;
292336 }
293337
294338 return result ;
0 commit comments