33import logging
44
55# Converted import path (agent_framework version of FoundryAgentTemplate)
6+ from common .database .database_base import DatabaseBase
7+ from common .models .messages_af import TeamConfiguration
8+ from v4 .common .services .team_service import TeamService
69from v4 .magentic_agents .foundry_agent import FoundryAgentTemplate # formerly v4.magentic_agents.foundry_agent
710from v4 .config .agent_registry import agent_registry
811from common .config .app_config import config
912logging .basicConfig (level = logging .INFO )
1013
11-
12- async def create_RAI_agent () -> FoundryAgentTemplate :
14+ async def find_first_available_team (team_service : TeamService , user_id : str ) -> str :
15+ """
16+ Check teams in priority order (4 to 1) and return the first available team ID.
17+ Priority: RFP (4) -> Retail (3) -> Marketing (2) -> HR (1)
18+ """
19+ team_priority_order = [
20+ "00000000-0000-0000-0000-000000000004" , # RFP
21+ "00000000-0000-0000-0000-000000000003" , # Retail
22+ "00000000-0000-0000-0000-000000000002" , # Marketing
23+ "00000000-0000-0000-0000-000000000001" , # HR
24+ ]
25+
26+ for team_id in team_priority_order :
27+ try :
28+ team_config = await team_service .get_team_configuration (team_id , user_id )
29+ if team_config is not None :
30+ print (f"Found available team: { team_id } " )
31+ return team_id
32+ except Exception as e :
33+ print (f"Error checking team { team_id } : { str (e )} " )
34+ continue
35+
36+ print ("No teams found in priority order" )
37+ return None
38+
39+ async def create_RAI_agent (team : TeamConfiguration , memory_store : DatabaseBase ) -> FoundryAgentTemplate :
1340 """Create and initialize a FoundryAgentTemplate for Responsible AI (RAI) checks."""
1441 agent_name = "RAIAgent"
1542 agent_description = "A comprehensive research assistant for integration testing"
@@ -26,7 +53,11 @@ async def create_RAI_agent() -> FoundryAgentTemplate:
2653 "- Is completely meaningless, incoherent, or appears to be spam\n "
2754 "Respond with 'TRUE' if the input violates any rules and should be blocked, otherwise respond with 'FALSE'."
2855 )
56+
2957 model_deployment_name = config .AZURE_OPENAI_DEPLOYMENT_NAME
58+ team .team_id = "rai_team" # Use a fixed team ID for RAI agent
59+ team .name = "RAI Team"
60+ team .description = "Team responsible for Responsible AI checks"
3061 agent = FoundryAgentTemplate (
3162 agent_name = agent_name ,
3263 agent_description = agent_description ,
@@ -36,6 +67,8 @@ async def create_RAI_agent() -> FoundryAgentTemplate:
3667 project_endpoint = config .AZURE_AI_PROJECT_ENDPOINT ,
3768 mcp_config = None ,
3869 search_config = None ,
70+ team_config = team ,
71+ memory_store = memory_store ,
3972 )
4073
4174 await agent .open ()
@@ -78,14 +111,14 @@ async def _get_agent_response(agent: FoundryAgentTemplate, query: str) -> str:
78111 return "TRUE" # Default to blocking on error
79112
80113
81- async def rai_success (description : str ) -> bool :
114+ async def rai_success (description : str , team_config : TeamConfiguration , memory_store : DatabaseBase ) -> bool :
82115 """
83116 Run a RAI compliance check on the provided description using the RAIAgent.
84117 Returns True if content is safe (should proceed), False if it should be blocked.
85118 """
86119 agent : FoundryAgentTemplate | None = None
87120 try :
88- agent = await create_RAI_agent ()
121+ agent = await create_RAI_agent (team_config , memory_store )
89122 if not agent :
90123 logging .error ("Failed to instantiate RAIAgent." )
91124 return False
@@ -112,7 +145,7 @@ async def rai_success(description: str) -> bool:
112145 pass
113146
114147
115- async def rai_validate_team_config (team_config_json : dict ) -> tuple [bool , str ]:
148+ async def rai_validate_team_config (team_config_json : dict , team_config : TeamConfiguration , memory_store : DatabaseBase ) -> tuple [bool , str ]:
116149 """
117150 Validate a team configuration for RAI compliance.
118151
@@ -154,7 +187,7 @@ async def rai_validate_team_config(team_config_json: dict) -> tuple[bool, str]:
154187 if not combined :
155188 return False , "Team configuration contains no readable text content."
156189
157- if not await rai_success (combined ):
190+ if not await rai_success (combined , team_config , memory_store ):
158191 return (
159192 False ,
160193 "Team configuration contains inappropriate content and cannot be uploaded." ,
0 commit comments