@@ -119,6 +119,67 @@ public async Task<AgentExecutionResult> ExecuteAsync(
119119 _logger . LogInformation ( "Agent execution completed successfully in {Duration}ms" ,
120120 stopwatch . ElapsedMilliseconds ) ;
121121 }
122+ catch ( OperationCanceledException )
123+ {
124+ stopwatch . Stop ( ) ;
125+ result . Success = false ;
126+ result . Error = "Execution was cancelled" ;
127+ result . Duration = stopwatch . Elapsed ;
128+
129+ activity ? . SetStatus ( ActivityStatusCode . Error , "Cancelled" ) ;
130+ _logger . LogWarning ( "Agent execution cancelled" ) ;
131+ }
132+ catch ( TimeoutException ex )
133+ {
134+ stopwatch . Stop ( ) ;
135+ result . Success = false ;
136+ result . Error = $ "Execution timeout: { ex . Message } ";
137+ result . Duration = stopwatch . Elapsed ;
138+
139+ activity ? . SetStatus ( ActivityStatusCode . Error , ex . Message ) ;
140+ activity ? . AddEvent ( new ActivityEvent ( "exception" ,
141+ tags : new ActivityTagsCollection
142+ {
143+ { "exception.type" , ex . GetType ( ) . FullName } ,
144+ { "exception.message" , ex . Message }
145+ } ) ) ;
146+
147+ _logger . LogError ( ex , "Agent execution timeout" ) ;
148+ }
149+ catch ( InvalidOperationException ex )
150+ {
151+ stopwatch . Stop ( ) ;
152+ result . Success = false ;
153+ result . Error = ex . Message ;
154+ result . Duration = stopwatch . Elapsed ;
155+
156+ activity ? . SetStatus ( ActivityStatusCode . Error , ex . Message ) ;
157+ activity ? . AddEvent ( new ActivityEvent ( "exception" ,
158+ tags : new ActivityTagsCollection
159+ {
160+ { "exception.type" , ex . GetType ( ) . FullName } ,
161+ { "exception.message" , ex . Message }
162+ } ) ) ;
163+
164+ _logger . LogError ( ex , "Invalid operation during agent execution" ) ;
165+ }
166+ catch ( NotImplementedException ex )
167+ {
168+ stopwatch . Stop ( ) ;
169+ result . Success = false ;
170+ result . Error = $ "Not implemented: { ex . Message } ";
171+ result . Duration = stopwatch . Elapsed ;
172+
173+ activity ? . SetStatus ( ActivityStatusCode . Error , ex . Message ) ;
174+ activity ? . AddEvent ( new ActivityEvent ( "exception" ,
175+ tags : new ActivityTagsCollection
176+ {
177+ { "exception.type" , ex . GetType ( ) . FullName } ,
178+ { "exception.message" , ex . Message }
179+ } ) ) ;
180+
181+ _logger . LogError ( ex , "Feature not implemented for agent execution" ) ;
182+ }
122183 catch ( Exception ex )
123184 {
124185 stopwatch . Stop ( ) ;
@@ -134,7 +195,7 @@ public async Task<AgentExecutionResult> ExecuteAsync(
134195 { "exception.message" , ex . Message }
135196 } ) ) ;
136197
137- _logger . LogError ( ex , "Agent execution failed " ) ;
198+ _logger . LogError ( ex , "Unexpected error during agent execution " ) ;
138199 }
139200
140201 return result ;
@@ -168,9 +229,19 @@ public async Task<bool> ValidateAgentAsync(string agentId, CancellationToken can
168229 _logger . LogInformation ( "Agent {AgentId} validation successful" , agentId ) ;
169230 return true ;
170231 }
232+ catch ( InvalidOperationException ex )
233+ {
234+ _logger . LogError ( ex , "Invalid operation validating agent {AgentId}" , agentId ) ;
235+ return false ;
236+ }
237+ catch ( ArgumentException ex )
238+ {
239+ _logger . LogError ( ex , "Invalid argument validating agent {AgentId}" , agentId ) ;
240+ return false ;
241+ }
171242 catch ( Exception ex )
172243 {
173- _logger . LogError ( ex , "Error validating agent {AgentId}" , agentId ) ;
244+ _logger . LogError ( ex , "Unexpected error validating agent {AgentId}" , agentId ) ;
174245 return false ;
175246 }
176247 }
0 commit comments