Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
14cc39c
add space for test
NirajC-Microsoft Oct 3, 2025
b488db5
Remove unused imports, blanks spaces, and trailing spaces
NirajC-Microsoft Oct 3, 2025
92b74e5
Remove unused imports, blanks spaces, and trailing spaces- part 2
NirajC-Microsoft Oct 3, 2025
cbfb35d
Remove unused imports, blanks spaces, and trailing spaces- part 3
NirajC-Microsoft Oct 3, 2025
f6c0bcd
Remove unused imports, blanks spaces, and trailing spaces- part 4
NirajC-Microsoft Oct 3, 2025
ba44ff5
Remove unused imports, blanks spaces, and trailing spaces- part 5
NirajC-Microsoft Oct 3, 2025
7680b01
Remove unused imports, blanks spaces, and trailing spaces- part 6
NirajC-Microsoft Oct 3, 2025
14bf1ad
Remove unused imports, blanks spaces, and trailing spaces- part 7
NirajC-Microsoft Oct 3, 2025
9d63a99
Remove unused imports, blanks spaces, and trailing spaces- part 8
NirajC-Microsoft Oct 3, 2025
0cef43c
Remove unused imports, blanks spaces, and trailing spaces- part 9
NirajC-Microsoft Oct 3, 2025
58bf44f
Remove unused imports, blanks spaces, and trailing spaces- part
NirajC-Microsoft Oct 3, 2025
c40ac40
change path of import
NirajC-Microsoft Oct 6, 2025
1c638b3
change import path in test files
NirajC-Microsoft Oct 6, 2025
e8d821b
add change
NirajC-Microsoft Oct 6, 2025
9eb9e85
add change 1
NirajC-Microsoft Oct 6, 2025
2422910
add change 1
NirajC-Microsoft Oct 6, 2025
662e80e
add change 5
NirajC-Microsoft Oct 6, 2025
09f48a9
add change 6
NirajC-Microsoft Oct 6, 2025
65cf09e
add change 7
NirajC-Microsoft Oct 6, 2025
708eb9a
Update requirements.txt by removing mcp dependency
NirajC-Microsoft Oct 6, 2025
8e01154
Refactor import paths in test_auth_utils.py
NirajC-Microsoft Oct 6, 2025
09da665
Fix logger assertion in test_auth_utils.py
NirajC-Microsoft Oct 6, 2025
8985916
Fix import path for sample_user in test file
NirajC-Microsoft Oct 6, 2025
065735a
Refactor health check tests for clarity and organization
NirajC-Microsoft Oct 6, 2025
302a889
Fix assertion for health check response text
NirajC-Microsoft Oct 6, 2025
5ff7666
Refactor imports and update test assertions
NirajC-Microsoft Oct 6, 2025
d29df6f
Refactor environment variable setup in tests
NirajC-Microsoft Oct 6, 2025
233c5e8
Update test_foundry_integration.py
NirajC-Microsoft Oct 6, 2025
4452ff4
Update test_utils.py
NirajC-Microsoft Oct 6, 2025
97ae9cf
Update import paths in test_hr_service.py
NirajC-Microsoft Oct 6, 2025
8e15465
Fix import path and ensure tool count assertion
NirajC-Microsoft Oct 6, 2025
36425ed
Remove ActionRequest and HumanFeedback classes
NirajC-Microsoft Oct 7, 2025
dd8133f
Merge branch 'dev-v3' into dev-v3
NirajC-Microsoft Oct 7, 2025
ef9a184
Update messages_kernel.py
NirajC-Microsoft Oct 7, 2025
ad6d484
Simplify initialization of plan_subscriptions
NirajC-Microsoft Oct 7, 2025
9cf9d53
Update src/backend/v3/magentic_agents/common/lifecycle.py
NirajC-Microsoft Oct 7, 2025
103ccc5
Update src/backend/v3/magentic_agents/foundry_agent.py
NirajC-Microsoft Oct 7, 2025
3b06767
Update src/backend/v3/magentic_agents/models/agent_models.py
NirajC-Microsoft Oct 7, 2025
463b463
Refactor database_base.py with new abstract methods
NirajC-Microsoft Oct 7, 2025
f542044
Refactor health check test and add helper function
NirajC-Microsoft Oct 7, 2025
ed07a04
Remove pass statements from abstract methods
NirajC-Microsoft Oct 7, 2025
8f181a0
Remove duplicate get_agent_messages method
NirajC-Microsoft Oct 7, 2025
7bea0ea
Update messages_kernel.py
NirajC-Microsoft Oct 8, 2025
2bf198c
Refactor AgentMessageType enum values
NirajC-Microsoft Oct 8, 2025
42fba59
Fix formatting of steps and next_steps fields
NirajC-Microsoft Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/backend/app_kernel.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# app_kernel.py
import asyncio
import logging
import os
# Azure monitoring
import re
import uuid
from typing import Dict, List, Optional

from azure.monitor.opentelemetry import configure_azure_monitor
from common.config.app_config import config
from common.models.messages_kernel import UserLanguage

# FastAPI imports
from fastapi import FastAPI, Query, Request
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware

# Local imports
from middleware.health_check import HealthCheckMiddleware
from v3.api.router import app_v3

# Azure monitoring

# Semantic Kernel imports
from v3.orchestration.orchestration_manager import OrchestrationManager

# Check if the Application Insights Instrumentation Key is set in the environment variables
connection_string = config.APPLICATIONINSIGHTS_CONNECTION_STRING
Expand Down Expand Up @@ -104,4 +102,11 @@ async def user_browser_language_endpoint(user_language: UserLanguage, request: R
if __name__ == "__main__":
import uvicorn

uvicorn.run("app_kernel:app", host="127.0.0.1", port=8000, reload=True, log_level="info", access_log=False)
uvicorn.run(
"app_kernel:app",
host="127.0.0.1",
port=8000,
reload=True,
log_level="info",
access_log=False,
)
23 changes: 16 additions & 7 deletions src/backend/common/config/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,23 @@ def __init__(self):
# Optional MCP server endpoint (for local MCP server or remote)
# Example: http://127.0.0.1:8000/mcp
self.MCP_SERVER_ENDPOINT = self._get_optional("MCP_SERVER_ENDPOINT")
self.MCP_SERVER_NAME = self._get_optional("MCP_SERVER_NAME", "MCPGreetingServer")
self.MCP_SERVER_DESCRIPTION = self._get_optional("MCP_SERVER_DESCRIPTION", "MCP server with greeting and planning tools")
self.MCP_SERVER_NAME = self._get_optional(
"MCP_SERVER_NAME", "MCPGreetingServer"
)
self.MCP_SERVER_DESCRIPTION = self._get_optional(
"MCP_SERVER_DESCRIPTION", "MCP server with greeting and planning tools"
)
self.TENANT_ID = self._get_optional("AZURE_TENANT_ID")
self.CLIENT_ID = self._get_optional("AZURE_CLIENT_ID")
self.AZURE_AI_SEARCH_CONNECTION_NAME = self._get_optional("AZURE_AI_SEARCH_CONNECTION_NAME")
self.AZURE_AI_SEARCH_INDEX_NAME = self._get_optional("AZURE_AI_SEARCH_INDEX_NAME")
self.AZURE_AI_SEARCH_CONNECTION_NAME = self._get_optional(
"AZURE_AI_SEARCH_CONNECTION_NAME"
)
self.AZURE_AI_SEARCH_INDEX_NAME = self._get_optional(
"AZURE_AI_SEARCH_INDEX_NAME"
)
self.AZURE_AI_SEARCH_ENDPOINT = self._get_optional("AZURE_AI_SEARCH_ENDPOINT")
self.AZURE_AI_SEARCH_API_KEY = self._get_optional("AZURE_AI_SEARCH_API_KEY")
# self.BING_CONNECTION_NAME = self._get_optional("BING_CONNECTION_NAME")
# self.BING_CONNECTION_NAME = self._get_optional("BING_CONNECTION_NAME")

test_team_json = self._get_optional("TEST_TEAM_JSON")

Expand Down Expand Up @@ -117,7 +125,7 @@ def get_azure_credential(self, client_id=None):
) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
else:
return ManagedIdentityCredential(client_id=client_id)

def get_azure_credentials(self):
"""Retrieve Azure credentials, either from environment variables or managed identity."""
if self._azure_credentials is None:
Expand Down Expand Up @@ -192,7 +200,8 @@ def get_cosmos_database_client(self):
try:
if self._cosmos_client is None:
self._cosmos_client = CosmosClient(
self.COSMOSDB_ENDPOINT, credential=self.get_azure_credential(self.AZURE_CLIENT_ID)
self.COSMOSDB_ENDPOINT,
credential=self.get_azure_credential(self.AZURE_CLIENT_ID),
)

if self._cosmos_database is None:
Expand Down
53 changes: 22 additions & 31 deletions src/backend/common/database/cosmosdb.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
"""CosmosDB implementation of the database interface."""

import json
import logging
import uuid

import datetime
import logging
from typing import Any, Dict, List, Optional, Type

from azure.cosmos import PartitionKey, exceptions
import v3.models.messages as messages
from azure.cosmos.aio import CosmosClient
from azure.cosmos.aio._database import DatabaseProxy
from azure.cosmos.exceptions import CosmosResourceExistsError
import v3.models.messages as messages

from common.models.messages_kernel import (
AgentMessage,
Plan,
Step,
TeamConfiguration,
)
from common.utils.utils_date import DateTimeEncoder

from .database_base import DatabaseBase
from ..models.messages_kernel import (
AgentMessage,
AgentMessageData,
BaseDataModel,
DataType,
Plan,
Step,
AgentMessage,
TeamConfiguration,
DataType,
UserCurrentTeam,
)
from .database_base import DatabaseBase


class CosmosDBClient(DatabaseBase):
Expand Down Expand Up @@ -189,7 +176,6 @@ async def delete_item(self, item_id: str, partition_key: str) -> None:
self.logger.error("Failed to delete item from CosmosDB: %s", str(e))
raise


# Plan Operations
async def add_plan(self, plan: Plan) -> None:
"""Add a plan to CosmosDB."""
Expand All @@ -199,7 +185,6 @@ async def update_plan(self, plan: Plan) -> None:
"""Update a plan in CosmosDB."""
await self.update_item(plan)


async def get_plan_by_plan_id(self, plan_id: str) -> Optional[Plan]:
"""Retrieve a plan by plan_id."""
query = "SELECT * FROM c WHERE c.id=@plan_id AND c.data_type=@data_type"
Expand Down Expand Up @@ -234,8 +219,9 @@ async def get_all_plans_by_team_id(self, team_id: str) -> List[Plan]:
]
return await self.query_items(query, parameters, Plan)


async def get_all_plans_by_team_id_status(self, user_id: str,team_id: str, status: str) -> List[Plan]:
async def get_all_plans_by_team_id_status(
self, user_id: str, team_id: str, status: str
) -> List[Plan]:
"""Retrieve all plans for a specific team."""
query = "SELECT * FROM c WHERE c.team_id=@team_id AND c.data_type=@data_type and c.user_id=@user_id and c.overall_status=@status ORDER BY c._ts DESC"
parameters = [
Expand All @@ -245,6 +231,7 @@ async def get_all_plans_by_team_id_status(self, user_id: str,team_id: str, statu
{"name": "@status", "value": status},
]
return await self.query_items(query, parameters, Plan)

# Step Operations
async def add_step(self, step: Step) -> None:
"""Add a step to CosmosDB."""
Expand Down Expand Up @@ -414,8 +401,6 @@ async def get_current_team(self, user_id: str) -> Optional[UserCurrentTeam]:
teams = await self.query_items(query, parameters, UserCurrentTeam)
return teams[0] if teams else None



async def delete_current_team(self, user_id: str) -> bool:
"""Delete the current team for a user."""
query = "SELECT c.id, c.session_id FROM c WHERE c.user_id=@user_id AND c.data_type=@data_type"
Expand All @@ -429,9 +414,13 @@ async def delete_current_team(self, user_id: str) -> bool:
if items:
async for doc in items:
try:
await self.container.delete_item(doc["id"], partition_key=doc["session_id"])
await self.container.delete_item(
doc["id"], partition_key=doc["session_id"]
)
except Exception as e:
self.logger.warning("Failed deleting current team doc %s: %s", doc.get("id"), e)
self.logger.warning(
"Failed deleting current team doc %s: %s", doc.get("id"), e
)

return True

Expand All @@ -457,9 +446,13 @@ async def delete_plan_by_plan_id(self, plan_id: str) -> bool:
if items:
async for doc in items:
try:
await self.container.delete_item(doc["id"], partition_key=doc["session_id"])
await self.container.delete_item(
doc["id"], partition_key=doc["session_id"]
)
except Exception as e:
self.logger.warning("Failed deleting current team doc %s: %s", doc.get("id"), e)
self.logger.warning(
"Failed deleting current team doc %s: %s", doc.get("id"), e
)

return True

Expand All @@ -471,7 +464,6 @@ async def update_mplan(self, mplan: messages.MPlan) -> None:
"""Update a team configuration in the database."""
await self.update_item(mplan)


async def get_mplan(self, plan_id: str) -> Optional[messages.MPlan]:
"""Retrieve a mplan configuration by mplan_id."""
query = "SELECT * FROM c WHERE c.plan_id=@plan_id AND c.data_type=@data_type"
Expand All @@ -481,7 +473,6 @@ async def get_mplan(self, plan_id: str) -> Optional[messages.MPlan]:
]
results = await self.query_items(query, parameters, messages.MPlan)
return results[0] if results else None


async def add_agent_message(self, message: AgentMessageData) -> None:
"""Add an agent message to the database."""
Expand All @@ -499,4 +490,4 @@ async def get_agent_messages(self, plan_id: str) -> List[AgentMessageData]:
{"name": "@data_type", "value": DataType.m_plan_message},
]

return await self.query_items(query, parameters, AgentMessageData)
return await self.query_items(query, parameters, AgentMessageData)
Loading
Loading