Skip to content

Commit 1f495af

Browse files
committed
remove client pass at the api level
1 parent adfc30e commit 1f495af

File tree

2 files changed

+11
-86
lines changed

2 files changed

+11
-86
lines changed

src/backend/app_kernel.py

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

src/backend/kernel_agents/agent_factory.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ async def create_agent(
158158

159159
# Build the agent definition (functions schema)
160160
definition = None
161+
client = None
161162

162163
try:
163164
if client is None:
@@ -238,7 +239,6 @@ async def create_all_agents(
238239
user_id: str,
239240
temperature: float = 0.0,
240241
memory_store: Optional[CosmosMemoryContext] = None,
241-
client: Optional[Any] = None,
242242
) -> Dict[AgentType, BaseAgent]:
243243
"""Create all agent types for a session in a specific order.
244244
@@ -265,13 +265,6 @@ async def create_all_agents(
265265
planner_agent_type = AgentType.PLANNER
266266
group_chat_manager_type = AgentType.GROUP_CHAT_MANAGER
267267

268-
try:
269-
if client is None:
270-
# Create the AIProjectClient instance using the config
271-
# This is a placeholder; replace with actual client creation logic
272-
client = config.get_ai_project_client()
273-
except Exception as client_exc:
274-
logger.error(f"Error creating AIProjectClient: {client_exc}")
275268
# Initialize cache for this session if it doesn't exist
276269
if session_id not in cls._agent_cache:
277270
cls._agent_cache[session_id] = {}
@@ -287,7 +280,6 @@ async def create_all_agents(
287280
session_id=session_id,
288281
user_id=user_id,
289282
temperature=temperature,
290-
client=client,
291283
memory_store=memory_store,
292284
)
293285

@@ -313,7 +305,6 @@ async def create_all_agents(
313305
user_id=user_id,
314306
temperature=temperature,
315307
agent_instances=agent_instances, # Pass agent instances to the planner
316-
client=client,
317308
response_format=ResponseFormatJsonSchemaType(
318309
json_schema=ResponseFormatJsonSchema(
319310
name=PlannerResponsePlan.__name__,
@@ -333,7 +324,6 @@ async def create_all_agents(
333324
session_id=session_id,
334325
user_id=user_id,
335326
temperature=temperature,
336-
client=client,
337327
agent_instances=agent_instances, # Pass agent instances to the planner
338328
)
339329
agents[group_chat_manager_type] = group_chat_manager

0 commit comments

Comments
 (0)