Skip to content

Commit cf4c255

Browse files
resolve the pylint
1 parent d514c1a commit cf4c255

File tree

14 files changed

+86
-102
lines changed

14 files changed

+86
-102
lines changed

src/backend/common/utils/utils_af.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Utility functions for agent_framework-based integration and agent management (converted from agent framework )."""
22

33
import logging
4-
from typing import Any, Dict
54

65
# Converted import path (agent_framework version of FoundryAgentTemplate)
76
from v4.magentic_agents.foundry_agent import FoundryAgentTemplate # formerly v4.magentic_agents.foundry_agent
87
from v4.config.agent_registry import agent_registry
98
from common.config.app_config import config
109
logging.basicConfig(level=logging.INFO)
1110

11+
1212
async def create_RAI_agent() -> FoundryAgentTemplate:
1313
"""Create and initialize a FoundryAgentTemplate for Responsible AI (RAI) checks."""
1414
agent_name = "RAIAgent"
@@ -42,7 +42,7 @@ async def create_RAI_agent() -> FoundryAgentTemplate:
4242

4343
try:
4444
agent_registry.register_agent(agent)
45-
except Exception as registry_error:
45+
except Exception as registry_error:
4646
logging.warning(
4747
"Failed to register agent '%s' with registry: %s",
4848
agent.agent_name,
@@ -73,7 +73,7 @@ async def _get_agent_response(agent: FoundryAgentTemplate, query: str) -> str:
7373
if txt:
7474
parts.append(str(txt))
7575
return "".join(parts) if parts else ""
76-
except Exception as e:
76+
except Exception as e:
7777
logging.error("Error streaming agent response: %s", e)
7878
return "TRUE" # Default to blocking on error
7979

@@ -93,22 +93,22 @@ async def rai_success(description: str) -> bool:
9393
response_text = await _get_agent_response(agent, description)
9494
verdict = response_text.strip().upper()
9595

96-
if "FALSE" in verdict: # any false in the response
96+
if "FALSE" in verdict: # any false in the response
9797
logging.info("RAI check passed.")
9898
return True
9999
else:
100100
logging.info("RAI check failed (blocked). Sample: %s...", description[:60])
101101
return False
102102

103-
except Exception as e:
103+
except Exception as e:
104104
logging.error("RAI check error: %s — blocking by default.", e)
105105
return False
106106
finally:
107107
# Ensure we close resources
108108
if agent:
109109
try:
110110
await agent.close()
111-
except Exception:
111+
except Exception:
112112
pass
113113

114114

@@ -161,6 +161,6 @@ async def rai_validate_team_config(team_config_json: dict) -> tuple[bool, str]:
161161
)
162162

163163
return True, ""
164-
except Exception as e:
164+
except Exception as e:
165165
logging.error("Error validating team configuration content: %s", e)
166-
return False, "Unable to validate team configuration content. Please try again."
166+
return False, "Unable to validate team configuration content. Please try again."

src/backend/v4/api/router.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def find_first_available_team(team_service: TeamService, user_id: str) ->
5555
"00000000-0000-0000-0000-000000000002", # Marketing
5656
"00000000-0000-0000-0000-000000000001", # HR
5757
]
58-
58+
5959
for team_id in team_priority_order:
6060
try:
6161
team_config = await team_service.get_team_configuration(team_id, user_id)
@@ -65,7 +65,7 @@ async def find_first_available_team(team_service: TeamService, user_id: str) ->
6565
except Exception as e:
6666
print(f"Error checking team {team_id}: {str(e)}")
6767
continue
68-
68+
6969
print("No teams found in priority order")
7070
return None
7171

@@ -139,7 +139,7 @@ async def init_team(
139139
# Initialize memory store and service
140140
memory_store = await DatabaseFactory.get_database(user_id=user_id)
141141
team_service = TeamService(memory_store)
142-
142+
143143
# Find the first available team from 4 to 1, or use HR as fallback
144144
init_team_id = await find_first_available_team(team_service, user_id)
145145
if not init_team_id:

src/backend/v4/callbacks/response_handlers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def agent_response_callback(
7575
"""
7676
agent_name = getattr(message, "author_name", None) or agent_id or "Unknown Agent"
7777
role = getattr(message, "role", "assistant")
78-
78+
7979
# FIX: Properly extract text from ChatMessage
8080
# ChatMessage has a .text property that concatenates all TextContent items
8181
text = ""
@@ -84,7 +84,7 @@ def agent_response_callback(
8484
else:
8585
# Fallback for non-ChatMessage objects
8686
text = str(getattr(message, "text", ""))
87-
87+
8888
text = clean_citations(text or "")
8989

9090
if not user_id:
@@ -105,9 +105,10 @@ def agent_response_callback(
105105
)
106106
)
107107
logger.info("%s message (agent=%s): %s", str(role).capitalize(), agent_name, text[:200])
108-
except Exception as e:
108+
except Exception as e:
109109
logger.error("agent_response_callback error sending WebSocket message: %s", e)
110110

111+
111112
async def streaming_agent_response_callback(
112113
agent_id: str,
113114
update: AgentRunResponseUpdate,
@@ -157,5 +158,5 @@ async def streaming_agent_response_callback(
157158
message_type=WebsocketMessageType.AGENT_MESSAGE_STREAMING,
158159
)
159160
logger.debug("Streaming chunk (agent=%s final=%s len=%d)", agent_id, is_final, len(cleaned))
160-
except Exception as e:
161-
logger.error("streaming_agent_response_callback error: %s", e)
161+
except Exception as e:
162+
logger.error("streaming_agent_response_callback error: %s", e)

src/backend/v4/config/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# agent_framework substitutes
1616
from agent_framework.azure import AzureOpenAIChatClient
17-
#from agent_framework_azure_ai import AzureOpenAIChatClient
17+
# from agent_framework_azure_ai import AzureOpenAIChatClient
1818
from agent_framework import ChatOptions
1919

2020
from v4.models.messages import MPlan, WebsocketMessageType
@@ -341,4 +341,4 @@ def get_current_team(self, user_id: str) -> TeamConfiguration:
341341
mcp_config = MCPConfig()
342342
orchestration_config = OrchestrationConfig()
343343
connection_config = ConnectionConfig()
344-
team_config = TeamConfig()
344+
team_config = TeamConfig()

src/backend/v4/magentic_agents/common/lifecycle.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import os
43
from contextlib import AsyncExitStack
54
from typing import Any, Optional
65

@@ -29,7 +28,7 @@ def __init__(self, mcp: MCPConfig | None = None) -> None:
2928
self._stack: AsyncExitStack | None = None
3029
self.mcp_cfg: MCPConfig | None = mcp
3130
self.mcp_tool: HostedMCPTool | None = None
32-
self._agent: ChatAgent | None = None
31+
self._agent: ChatAgent | None = None
3332

3433
async def open(self) -> "MCPEnabledBase":
3534
if self._stack is not None:
@@ -47,12 +46,12 @@ async def close(self) -> None:
4746
if self._agent and hasattr(self._agent, "close"):
4847
try:
4948
await self._agent.close() # AzureAIAgentClient has async close
50-
except Exception:
49+
except Exception:
5150
pass
5251
# Unregister from registry if present
5352
try:
5453
agent_registry.unregister_agent(self)
55-
except Exception:
54+
except Exception:
5655
pass
5756
await self._stack.aclose()
5857
finally:
@@ -89,7 +88,7 @@ async def _prepare_mcp_tool(self) -> None:
8988
)
9089
await self._stack.enter_async_context(mcp_tool)
9190
self.mcp_tool = mcp_tool # Store for later use
92-
except Exception:
91+
except Exception:
9392
self.mcp_tool = None
9493

9594

@@ -106,7 +105,7 @@ def __init__(self, mcp: MCPConfig | None = None, model_deployment_name: str | No
106105
super().__init__(mcp=mcp)
107106
self.creds: Optional[DefaultAzureCredential] = None
108107
self.client: Optional[AzureAIAgentClient] = None
109-
108+
110109
self._created_ephemeral: bool = (
111110
False # reserved if you add ephemeral agent cleanup
112111
)
@@ -118,7 +117,6 @@ async def open(self) -> "AzureAgentBase":
118117
return self
119118
self._stack = AsyncExitStack()
120119

121-
122120
# Acquire credential
123121
self.creds = DefaultAzureCredential()
124122
await self._stack.enter_async_context(self.creds)
@@ -130,7 +128,7 @@ async def open(self) -> "AzureAgentBase":
130128
# async_credential=self.creds,
131129
# )
132130

133-
#Create AgentsClient
131+
# Create AgentsClient
134132
self.client = AgentsClient(
135133
endpoint=self.project_endpoint,
136134
credential=self.creds,
@@ -146,7 +144,7 @@ async def open(self) -> "AzureAgentBase":
146144
# Register agent (best effort)
147145
try:
148146
agent_registry.register_agent(self)
149-
except Exception:
147+
except Exception:
150148
pass
151149

152150
return self
@@ -170,25 +168,25 @@ async def close(self) -> None:
170168
if self._agent and hasattr(self._agent, "close"):
171169
try:
172170
await self._agent.close()
173-
except Exception:
171+
except Exception:
174172
pass
175173

176174
# Unregister from registry
177175
try:
178176
agent_registry.unregister_agent(self)
179-
except Exception:
177+
except Exception:
180178
pass
181179

182180
# Close credential and project client
183181
if self.client:
184182
try:
185183
await self.client.close()
186-
except Exception:
184+
except Exception:
187185
pass
188186
if self.creds:
189187
try:
190188
await self.creds.close()
191-
except Exception:
189+
except Exception:
192190
pass
193191

194192
finally:

src/backend/v4/magentic_agents/foundry_agent.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ def _is_azure_search_requested(self) -> bool:
6969
return True
7070
return False
7171

72-
73-
7472
async def _collect_tools(self) -> List:
7573
"""Collect tool definitions for ChatAgent (MCP path only)."""
7674
tools: List = []
7775

78-
7976
# Code Interpreter (only in MCP path per incompatibility note)
8077
if self.enable_code_interpreter:
8178
try:
@@ -114,7 +111,6 @@ async def _create_azure_search_enabled_client(self):
114111
self.logger.error("Search configuration missing.")
115112
return None
116113

117-
118114
desired_connection_name = getattr(self.search, "connection_name", None)
119115
index_name = getattr(self.search, "index_name", "")
120116
query_type = getattr(self.search, "search_query_type", "simple")
@@ -143,7 +139,7 @@ async def _create_azure_search_enabled_client(self):
143139
"connection_name=%s",
144140
desired_connection_name,
145141
)
146-
# return None
142+
# return None
147143

148144
self.logger.info(
149145
"Using Azure AI Search connection (id=%s, requested_name=%s).",
@@ -186,7 +182,7 @@ async def _create_azure_search_enabled_client(self):
186182

187183
chat_client = AzureAIAgentClient(
188184
project_client=self.project_client,
189-
#agents_client=self.client,
185+
# agents_client=self.client,
190186
agent_id=azure_agent.id,
191187
async_credential=self.creds,
192188
)
@@ -202,6 +198,7 @@ async def _create_azure_search_enabled_client(self):
202198
# -------------------------
203199
# Agent lifecycle override
204200
# -------------------------
201+
205202
async def _after_open(self) -> None:
206203
"""Initialize ChatAgent after connections are established."""
207204
try:
@@ -311,4 +308,4 @@ async def close(self) -> None:
311308

312309
# )
313310
# await agent.open()
314-
# return agent
311+
# return agent

src/backend/v4/magentic_agents/magentic_agent_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def create_agent_from_config(self, user_id: str, agent_obj: SimpleNamespac
108108
agent_description=getattr(agent_obj, "description", ""),
109109
agent_instructions=getattr(agent_obj, "system_message", ""),
110110
model_deployment_name=deployment_name,
111-
project_endpoint=project_endpoint, # type: ignore
111+
project_endpoint=project_endpoint, # type: ignore
112112
search_config=search_config,
113113
mcp_config=mcp_config,
114114
)

src/backend/v4/magentic_agents/models/agent_models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@ class SearchConfig:
6262
endpoint: str | None = None
6363
index_name: str | None = None
6464

65-
6665
@classmethod
6766
def from_env(cls, index_name: str) -> "SearchConfig":
6867
connection_name = config.AZURE_AI_SEARCH_CONNECTION_NAME
6968
index_name = index_name or config.AZURE_AI_SEARCH_INDEX_NAME
7069
endpoint = config.AZURE_AI_SEARCH_ENDPOINT
7170

72-
7371
# Raise exception if any required environment variable is missing
7472
if not all([connection_name, index_name, endpoint]):
7573
raise ValueError(

0 commit comments

Comments
 (0)