Skip to content

Commit 0857d8f

Browse files
committed
Prevent duplicate team agents and update agent retrieval
Ensures no duplicate team agents are added by deleting existing entries before insertion in CosmosDBClient. Updates SQL query to select all fields for team agent retrieval. Refactors agent initialization in lifecycle.py to use correct parameter names and agent ID source, and adds a note to narrow exception handling.
1 parent ac64b2d commit 0857d8f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/backend/common/database/cosmosdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ async def get_agent_messages(self, plan_id: str) -> List[AgentMessageData]:
495495

496496
async def add_team_agent(self, team_agent: CurrentTeamAgent) -> None:
497497
"""Add an agent message to the database."""
498+
await self.delete_team_agent(team_agent.team_id, team_agent.agent_name) # Ensure no duplicates
498499
await self.add_item(team_agent)
499500

500501
async def delete_team_agent(self, team_id: str, agent_name: str) -> None:
@@ -525,7 +526,7 @@ async def get_team_agent(
525526
self, team_id: str, agent_name: str
526527
) -> Optional[CurrentTeamAgent]:
527528
"""Retrieve a team agent by team_id and agent_name."""
528-
query = "SELECT c.id, c.session_id FROM c WHERE c.team_id=@team_id AND c.data_type=@data_type AND c.agent_name=@agent_name"
529+
query = "SELECT * FROM c WHERE c.team_id=@team_id AND c.data_type=@data_type AND c.agent_name=@agent_name"
529530
params = [
530531
{"name": "@team_id", "value": team_id},
531532
{"name": "@agent_name", "value": agent_name},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ async def get_database_team_agent(self) -> Optional[CurrentTeamAgent]:
143143
)
144144
if currentAgent and currentAgent.agent_foundry_id:
145145
agent = self.client.get_agent(
146-
id=currentAgent.agent_foundry_id
146+
agent_id=currentAgent.agent_foundry_id
147147
)
148148

149-
except Exception as ex:
149+
except Exception as ex: # Consider narrowing this to specific exceptions if possible
150150
self.logger.error("Failed to initialize ReasoningAgentTemplate: %s", ex)
151151
return agent
152152

@@ -157,7 +157,7 @@ async def save_database_team_agent(self) -> None:
157157
team_id=self.team_config.team_id,
158158
team_name=self.team_config.name,
159159
agent_name=self.agent_name,
160-
agent_foundry_id=self._agent.id,
160+
agent_foundry_id=self._agent.chat_client.agent_id,
161161
agent_description=self.agent_description,
162162
agent_instructions=self.agent_instructions,
163163
)

0 commit comments

Comments
 (0)