Skip to content

Commit db83fd2

Browse files
committed
Refactor agent factory import and RAI check logic
Moved MagenticAgentFactory import to module level in orchestration_manager.py to avoid circular imports. Cleaned up unused agent instance cache and improved RAI verdict handling in utils_af.py by checking for 'TRUE' substring and simplifying response logic.
1 parent 3fed251 commit db83fd2

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/backend/af/orchestration/orchestration_manager.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
from af.config.settings import connection_config, orchestration_config
2525
from af.models.messages import WebsocketMessageType
2626
from af.orchestration.human_approval_manager import HumanApprovalMagenticManager
27-
27+
from af.magentic_agents.magentic_agent_factory import (
28+
MagenticAgentFactory,
29+
)
2830

2931
class OrchestrationManager:
3032
"""Manager for handling orchestration logic using agent_framework Magentic workflow."""
@@ -195,11 +197,6 @@ async def get_current_or_new_orchestration(
195197
except Exception as e: # noqa: BLE001
196198
cls.logger.error("Error closing agent: %s", e)
197199

198-
# Build new participants via existing factory)
199-
from af.magentic_agents.magentic_agent_factory import (
200-
MagenticAgentFactory,
201-
) # local import to avoid circular
202-
203200
factory = MagenticAgentFactory()
204201
agents = await factory.get_agents(
205202
user_id=user_id, team_config_input=team_config

src/backend/common/utils/utils_af.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010
logging.basicConfig(level=logging.INFO)
1111

12-
# Cache for agent instances by session (if you later need multi-session reuse)
13-
agent_instances: Dict[str, Dict[str, Any]] = {}
14-
# Removed azure_agent_instances (agent framework AzureAIAgent cache) since SK is deprecated.
15-
16-
1712
async def create_RAI_agent() -> FoundryAgentTemplate:
1813
"""Create and initialize a FoundryAgentTemplate for Responsible AI (RAI) checks."""
1914
agent_name = "RAIAgent"
@@ -66,12 +61,12 @@ async def _get_agent_response(agent: FoundryAgentTemplate, query: str) -> str:
6661
"""
6762
parts: list[str] = []
6863
try:
69-
async for update in agent.invoke(query):
64+
async for message in agent.invoke(query):
7065
# Prefer direct text
71-
if hasattr(update, "text") and update.text:
72-
parts.append(str(update.text))
66+
if hasattr(message, "text") and message.text:
67+
parts.append(str(message.text))
7368
# Fallback to contents (tool calls, chunks)
74-
contents = getattr(update, "contents", None)
69+
contents = getattr(message, "contents", None)
7570
if contents:
7671
for item in contents:
7772
txt = getattr(item, "text", None)
@@ -98,15 +93,13 @@ async def rai_success(description: str) -> bool:
9893
response_text = await _get_agent_response(agent, description)
9994
verdict = response_text.strip().upper()
10095

101-
if verdict == "TRUE":
96+
if "TRUE" in verdict: # any true in the response
10297
logging.warning("RAI check failed (blocked). Sample: %s...", description[:60])
10398
return False
104-
if verdict == "FALSE":
99+
else:
105100
logging.info("RAI check passed.")
106101
return True
107102

108-
logging.warning("Unexpected RAI response '%s' — defaulting to block.", verdict)
109-
return False
110103
except Exception as e: # noqa: BLE001
111104
logging.error("RAI check error: %s — blocking by default.", e)
112105
return False

0 commit comments

Comments
 (0)