|
40 | 40 | from event_utils import track_event_if_configured |
41 | 41 | from models.messages_kernel import AgentType |
42 | 42 | from kernel_agents.agent_factory import AgentFactory |
| 43 | +from app_config import config |
43 | 44 |
|
44 | 45 | # # Check if the Application Insights Instrumentation Key is set in the environment variables |
45 | 46 | # instrumentation_key = os.getenv("APPLICATIONINSIGHTS_INSTRUMENTATION_KEY") |
@@ -267,15 +268,24 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques |
267 | 268 | except Exception as client_exc: |
268 | 269 | logging.error(f"Error creating AIProjectClient: {client_exc}") |
269 | 270 |
|
270 | | - agents = await AgentFactory.create_all_agents( |
| 271 | + human_agent = await AgentFactory.create_agent( |
| 272 | + agent_type=AgentType.HUMAN.value, |
271 | 273 | session_id=human_feedback.session_id, |
272 | 274 | user_id=user_id, |
273 | 275 | memory_store=memory_store, |
274 | 276 | client=client, |
275 | 277 | ) |
276 | 278 |
|
277 | | - # Send the feedback to the human agent |
278 | | - human_agent = agents[AgentType.HUMAN.value] |
| 279 | + if human_agent is None: |
| 280 | + track_event_if_configured( |
| 281 | + "AgentNotFound", |
| 282 | + { |
| 283 | + "status": "Agent not found", |
| 284 | + "session_id": human_feedback.session_id, |
| 285 | + "step_id": human_feedback.step_id, |
| 286 | + }, |
| 287 | + ) |
| 288 | + raise HTTPException(status_code=404, detail="Agent not found") |
279 | 289 |
|
280 | 290 | # Use the human agent to handle the feedback |
281 | 291 | await human_agent.handle_human_feedback(human_feedback=human_feedback) |
@@ -363,15 +373,25 @@ async def human_clarification_endpoint( |
363 | 373 | client = config.get_ai_project_client() |
364 | 374 | except Exception as client_exc: |
365 | 375 | logging.error(f"Error creating AIProjectClient: {client_exc}") |
366 | | - agents = await AgentFactory.create_all_agents( |
| 376 | + |
| 377 | + human_agent = await AgentFactory.create_agent( |
| 378 | + agent_type=AgentType.HUMAN.value, |
367 | 379 | session_id=human_clarification.session_id, |
368 | 380 | user_id=user_id, |
369 | 381 | memory_store=memory_store, |
370 | 382 | client=client, |
371 | 383 | ) |
372 | 384 |
|
373 | | - # Send the feedback to the human agent |
374 | | - human_agent = agents[AgentType.HUMAN.value] |
| 385 | + if human_agent is None: |
| 386 | + track_event_if_configured( |
| 387 | + "AgentNotFound", |
| 388 | + { |
| 389 | + "status": "Agent not found", |
| 390 | + "session_id": human_clarification.session_id, |
| 391 | + "step_id": human_clarification.step_id, |
| 392 | + }, |
| 393 | + ) |
| 394 | + raise HTTPException(status_code=404, detail="Agent not found") |
375 | 395 |
|
376 | 396 | # Use the human agent to handle the feedback |
377 | 397 | await human_agent.handle_human_clarification( |
|
0 commit comments