@@ -124,10 +124,17 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
124124 kernel , memory_store = await initialize_runtime_and_context (
125125 input_task .session_id , user_id
126126 )
127+ client = None
128+ try :
129+ client = config .get_ai_project_client ()
130+ except Exception as client_exc :
131+ logging .error (f"Error creating AIProjectClient: { client_exc } " )
132+
127133 agents = await AgentFactory .create_all_agents (
128134 session_id = input_task .session_id ,
129135 user_id = user_id ,
130136 memory_store = memory_store ,
137+ client = client ,
131138 )
132139
133140 group_chat_manager = agents [AgentType .GROUP_CHAT_MANAGER .value ]
@@ -161,7 +168,11 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
161168 "description" : input_task .description ,
162169 },
163170 )
164-
171+ if client :
172+ try :
173+ client .close ()
174+ except Exception as e :
175+ logging .error (f"Error sending to AIProjectClient: { e } " )
165176 return {
166177 "status" : f"Plan created with ID: { plan .id } " ,
167178 "session_id" : input_task .session_id ,
@@ -249,8 +260,18 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
249260 kernel , memory_store = await initialize_runtime_and_context (
250261 human_feedback .session_id , user_id
251262 )
263+
264+ client = None
265+ try :
266+ client = config .get_ai_project_client ()
267+ except Exception as client_exc :
268+ logging .error (f"Error creating AIProjectClient: { client_exc } " )
269+
252270 agents = await AgentFactory .create_all_agents (
253- session_id = human_feedback .session_id , user_id = user_id , memory_store = memory_store
271+ session_id = human_feedback .session_id ,
272+ user_id = user_id ,
273+ memory_store = memory_store ,
274+ client = client ,
254275 )
255276
256277 # Send the feedback to the human agent
@@ -267,7 +288,11 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
267288 "step_id" : human_feedback .step_id ,
268289 },
269290 )
270-
291+ if client :
292+ try :
293+ client .close ()
294+ except Exception as e :
295+ logging .error (f"Error sending to AIProjectClient: { e } " )
271296 return {
272297 "status" : "Feedback received" ,
273298 "session_id" : human_feedback .session_id ,
@@ -333,10 +358,16 @@ async def human_clarification_endpoint(
333358 kernel , memory_store = await initialize_runtime_and_context (
334359 human_clarification .session_id , user_id
335360 )
361+ client = None
362+ try :
363+ client = config .get_ai_project_client ()
364+ except Exception as client_exc :
365+ logging .error (f"Error creating AIProjectClient: { client_exc } " )
336366 agents = await AgentFactory .create_all_agents (
337367 session_id = human_clarification .session_id ,
338368 user_id = user_id ,
339369 memory_store = memory_store ,
370+ client = client ,
340371 )
341372
342373 # Send the feedback to the human agent
@@ -354,7 +385,11 @@ async def human_clarification_endpoint(
354385 "session_id" : human_clarification .session_id ,
355386 },
356387 )
357-
388+ if client :
389+ try :
390+ client .close ()
391+ except Exception as e :
392+ logging .error (f"Error sending to AIProjectClient: { e } " )
358393 return {
359394 "status" : "Clarification received" ,
360395 "session_id" : human_clarification .session_id ,
@@ -427,17 +462,28 @@ async def approve_step_endpoint(
427462 kernel , memory_store = await initialize_runtime_and_context (
428463 human_feedback .session_id , user_id
429464 )
465+ client = None
466+ try :
467+ client = config .get_ai_project_client ()
468+ except Exception as client_exc :
469+ logging .error (f"Error creating AIProjectClient: { client_exc } " )
430470 agents = await AgentFactory .create_all_agents (
431471 session_id = human_feedback .session_id ,
432472 user_id = user_id ,
433473 memory_store = memory_store ,
474+ client = client ,
434475 )
435476
436477 # Send the approval to the group chat manager
437478 group_chat_manager = agents [AgentType .GROUP_CHAT_MANAGER .value ]
438479
439480 await group_chat_manager .handle_human_feedback (human_feedback )
440481
482+ if client :
483+ try :
484+ client .close ()
485+ except Exception as e :
486+ logging .error (f"Error sending to AIProjectClient: { e } " )
441487 # Return a status message
442488 if human_feedback .step_id :
443489 track_event_if_configured (
0 commit comments