Skip to content

Commit 07cbe52

Browse files
committed
comment out azure monitor
1 parent 449fe35 commit 07cbe52

File tree

2 files changed

+98
-23
lines changed

2 files changed

+98
-23
lines changed

src/backend/app_kernel.py

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@
4343
from utils_kernel import get_agents, initialize_runtime_and_context, rai_success
4444

4545
# # Check if the Application Insights Instrumentation Key is set in the environment variables
46-
connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
47-
if connection_string:
48-
# Configure Application Insights if the Instrumentation Key is found
49-
configure_azure_monitor(connection_string=connection_string)
50-
logging.info(
51-
"Application Insights configured with the provided Instrumentation Key"
52-
)
53-
else:
54-
# Log a warning if the Instrumentation Key is not found
55-
logging.warning(
56-
"No Application Insights Instrumentation Key found. Skipping configuration"
57-
)
46+
# connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
47+
# if connection_string:
48+
# # Configure Application Insights if the Instrumentation Key is found
49+
# configure_azure_monitor(connection_string=connection_string)
50+
# logging.info(
51+
# "Application Insights configured with the provided Instrumentation Key"
52+
# )
53+
# else:
54+
# # Log a warning if the Instrumentation Key is not found
55+
# logging.warning(
56+
# "No Application Insights Instrumentation Key found. Skipping configuration"
57+
# )
5858

5959
# Configure logging
6060
logging.basicConfig(level=logging.INFO)
@@ -129,10 +129,17 @@ 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+
132138
agents = await AgentFactory.create_all_agents(
133139
session_id=input_task.session_id,
134140
user_id=user_id,
135141
memory_store=memory_store,
142+
client=client,
136143
)
137144

138145
group_chat_manager = agents[AgentType.GROUP_CHAT_MANAGER.value]
@@ -166,7 +173,11 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
166173
"description": input_task.description,
167174
},
168175
)
169-
176+
if client:
177+
try:
178+
client.close()
179+
except Exception as e:
180+
logging.error(f"Error sending to AIProjectClient: {e}")
170181
return {
171182
"status": f"Plan created with ID: {plan.id}",
172183
"session_id": input_task.session_id,
@@ -254,12 +265,31 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
254265
kernel, memory_store = await initialize_runtime_and_context(
255266
human_feedback.session_id, user_id
256267
)
257-
agents = await AgentFactory.create_all_agents(
258-
session_id=human_feedback.session_id, user_id=user_id, memory_store=memory_store
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,
259281
)
260282

261-
# Send the feedback to the human agent
262-
human_agent = agents[AgentType.HUMAN.value]
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")
263293

264294
# Use the human agent to handle the feedback
265295
await human_agent.handle_human_feedback(human_feedback=human_feedback)
@@ -272,7 +302,11 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
272302
"step_id": human_feedback.step_id,
273303
},
274304
)
275-
305+
if client:
306+
try:
307+
client.close()
308+
except Exception as e:
309+
logging.error(f"Error sending to AIProjectClient: {e}")
276310
return {
277311
"status": "Feedback received",
278312
"session_id": human_feedback.session_id,
@@ -338,14 +372,30 @@ async def human_clarification_endpoint(
338372
kernel, memory_store = await initialize_runtime_and_context(
339373
human_clarification.session_id, user_id
340374
)
341-
agents = await AgentFactory.create_all_agents(
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,
342383
session_id=human_clarification.session_id,
343384
user_id=user_id,
344385
memory_store=memory_store,
386+
client=client,
345387
)
346388

347-
# Send the feedback to the human agent
348-
human_agent = agents[AgentType.HUMAN.value]
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")
349399

350400
# Use the human agent to handle the feedback
351401
await human_agent.handle_human_clarification(
@@ -359,7 +409,11 @@ async def human_clarification_endpoint(
359409
"session_id": human_clarification.session_id,
360410
},
361411
)
362-
412+
if client:
413+
try:
414+
client.close()
415+
except Exception as e:
416+
logging.error(f"Error sending to AIProjectClient: {e}")
363417
return {
364418
"status": "Clarification received",
365419
"session_id": human_clarification.session_id,
@@ -432,17 +486,28 @@ async def approve_step_endpoint(
432486
kernel, memory_store = await initialize_runtime_and_context(
433487
human_feedback.session_id, user_id
434488
)
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}")
435494
agents = await AgentFactory.create_all_agents(
436495
session_id=human_feedback.session_id,
437496
user_id=user_id,
438497
memory_store=memory_store,
498+
client=client,
439499
)
440500

441501
# Send the approval to the group chat manager
442502
group_chat_manager = agents[AgentType.GROUP_CHAT_MANAGER.value]
443503

444504
await group_chat_manager.handle_human_feedback(human_feedback)
445505

506+
if client:
507+
try:
508+
client.close()
509+
except Exception as e:
510+
logging.error(f"Error sending to AIProjectClient: {e}")
446511
# Return a status message
447512
if human_feedback.step_id:
448513
track_event_if_configured(

src/backend/kernel_agents/agent_factory.py

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

159159
# Build the agent definition (functions schema)
160160
definition = None
161-
client = None
162161

163162
try:
164163
if client is None:
@@ -239,6 +238,7 @@ async def create_all_agents(
239238
user_id: str,
240239
temperature: float = 0.0,
241240
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,6 +265,13 @@ 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}")
268275
# Initialize cache for this session if it doesn't exist
269276
if session_id not in cls._agent_cache:
270277
cls._agent_cache[session_id] = {}
@@ -280,6 +287,7 @@ async def create_all_agents(
280287
session_id=session_id,
281288
user_id=user_id,
282289
temperature=temperature,
290+
client=client,
283291
memory_store=memory_store,
284292
)
285293

@@ -305,6 +313,7 @@ async def create_all_agents(
305313
user_id=user_id,
306314
temperature=temperature,
307315
agent_instances=agent_instances, # Pass agent instances to the planner
316+
client=client,
308317
response_format=ResponseFormatJsonSchemaType(
309318
json_schema=ResponseFormatJsonSchema(
310319
name=PlannerResponsePlan.__name__,
@@ -324,6 +333,7 @@ async def create_all_agents(
324333
session_id=session_id,
325334
user_id=user_id,
326335
temperature=temperature,
336+
client=client,
327337
agent_instances=agent_instances, # Pass agent instances to the planner
328338
)
329339
agents[group_chat_manager_type] = group_chat_manager

0 commit comments

Comments
 (0)