@@ -129,17 +129,10 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
129129 kernel , memory_store = await initialize_runtime_and_context (
130130 input_task .session_id , user_id
131131 )
132- client = None
133- try :
134- client = config .get_ai_project_client ()
135- except Exception as client_exc :
136- logging .error (f"Error creating AIProjectClient: { client_exc } " )
137-
138132 agents = await AgentFactory .create_all_agents (
139133 session_id = input_task .session_id ,
140134 user_id = user_id ,
141135 memory_store = memory_store ,
142- client = client ,
143136 )
144137
145138 group_chat_manager = agents [AgentType .GROUP_CHAT_MANAGER .value ]
@@ -173,11 +166,7 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
173166 "description" : input_task .description ,
174167 },
175168 )
176- if client :
177- try :
178- client .close ()
179- except Exception as e :
180- logging .error (f"Error sending to AIProjectClient: { e } " )
169+
181170 return {
182171 "status" : f"Plan created with ID: { plan .id } " ,
183172 "session_id" : input_task .session_id ,
@@ -265,31 +254,12 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
265254 kernel , memory_store = await initialize_runtime_and_context (
266255 human_feedback .session_id , user_id
267256 )
268-
269- client = None
270- try :
271- client = config .get_ai_project_client ()
272- except Exception as client_exc :
273- logging .error (f"Error creating AIProjectClient: { client_exc } " )
274-
275- human_agent = await AgentFactory .create_agent (
276- agent_type = AgentType .HUMAN ,
277- session_id = human_feedback .session_id ,
278- user_id = user_id ,
279- memory_store = memory_store ,
280- client = client ,
257+ agents = await AgentFactory .create_all_agents (
258+ session_id = human_feedback .session_id , user_id = user_id , memory_store = memory_store
281259 )
282260
283- if human_agent is None :
284- track_event_if_configured (
285- "AgentNotFound" ,
286- {
287- "status" : "Agent not found" ,
288- "session_id" : human_feedback .session_id ,
289- "step_id" : human_feedback .step_id ,
290- },
291- )
292- raise HTTPException (status_code = 404 , detail = "Agent not found" )
261+ # Send the feedback to the human agent
262+ human_agent = agents [AgentType .HUMAN .value ]
293263
294264 # Use the human agent to handle the feedback
295265 await human_agent .handle_human_feedback (human_feedback = human_feedback )
@@ -302,11 +272,7 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
302272 "step_id" : human_feedback .step_id ,
303273 },
304274 )
305- if client :
306- try :
307- client .close ()
308- except Exception as e :
309- logging .error (f"Error sending to AIProjectClient: { e } " )
275+
310276 return {
311277 "status" : "Feedback received" ,
312278 "session_id" : human_feedback .session_id ,
@@ -372,30 +338,14 @@ async def human_clarification_endpoint(
372338 kernel , memory_store = await initialize_runtime_and_context (
373339 human_clarification .session_id , user_id
374340 )
375- client = None
376- try :
377- client = config .get_ai_project_client ()
378- except Exception as client_exc :
379- logging .error (f"Error creating AIProjectClient: { client_exc } " )
380-
381- human_agent = await AgentFactory .create_agent (
382- agent_type = AgentType .HUMAN ,
341+ agents = await AgentFactory .create_all_agents (
383342 session_id = human_clarification .session_id ,
384343 user_id = user_id ,
385344 memory_store = memory_store ,
386- client = client ,
387345 )
388346
389- if human_agent is None :
390- track_event_if_configured (
391- "AgentNotFound" ,
392- {
393- "status" : "Agent not found" ,
394- "session_id" : human_clarification .session_id ,
395- "step_id" : human_clarification .step_id ,
396- },
397- )
398- raise HTTPException (status_code = 404 , detail = "Agent not found" )
347+ # Send the feedback to the human agent
348+ human_agent = agents [AgentType .HUMAN .value ]
399349
400350 # Use the human agent to handle the feedback
401351 await human_agent .handle_human_clarification (
@@ -409,11 +359,7 @@ async def human_clarification_endpoint(
409359 "session_id" : human_clarification .session_id ,
410360 },
411361 )
412- if client :
413- try :
414- client .close ()
415- except Exception as e :
416- logging .error (f"Error sending to AIProjectClient: { e } " )
362+
417363 return {
418364 "status" : "Clarification received" ,
419365 "session_id" : human_clarification .session_id ,
@@ -486,28 +432,17 @@ async def approve_step_endpoint(
486432 kernel , memory_store = await initialize_runtime_and_context (
487433 human_feedback .session_id , user_id
488434 )
489- client = None
490- try :
491- client = config .get_ai_project_client ()
492- except Exception as client_exc :
493- logging .error (f"Error creating AIProjectClient: { client_exc } " )
494435 agents = await AgentFactory .create_all_agents (
495436 session_id = human_feedback .session_id ,
496437 user_id = user_id ,
497438 memory_store = memory_store ,
498- client = client ,
499439 )
500440
501441 # Send the approval to the group chat manager
502442 group_chat_manager = agents [AgentType .GROUP_CHAT_MANAGER .value ]
503443
504444 await group_chat_manager .handle_human_feedback (human_feedback )
505445
506- if client :
507- try :
508- client .close ()
509- except Exception as e :
510- logging .error (f"Error sending to AIProjectClient: { e } " )
511446 # Return a status message
512447 if human_feedback .step_id :
513448 track_event_if_configured (
0 commit comments