Skip to content

Commit d4cd3f6

Browse files
committed
Add team agent management to database layer
Introduces methods to add, delete, and retrieve team agents in both the CosmosDBClient and DatabaseBase classes. Also renames the model class CurrentAgent to CurrentTeamAgent for clarity and updates references accordingly.
1 parent bf7a29b commit d4cd3f6

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

src/backend/common/database/cosmosdb.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
AgentMessage,
1313
AgentMessageData,
1414
BaseDataModel,
15+
CurrentTeamAgent,
1516
DataType,
1617
Plan,
1718
Step,
@@ -491,3 +492,45 @@ async def get_agent_messages(self, plan_id: str) -> List[AgentMessageData]:
491492
]
492493

493494
return await self.query_items(query, parameters, AgentMessageData)
495+
496+
async def add_team_agent(self, team_agent: CurrentTeamAgent) -> None:
497+
"""Add an agent message to the database."""
498+
await self.add_item(team_agent)
499+
500+
async def delete_team_agent(self, team_id: str, agent_name: str) -> None:
501+
"""Delete the current team for a user."""
502+
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"
503+
504+
params = [
505+
{"name": "@team_id", "value": team_id},
506+
{"name": "@agent_name", "value": agent_name},
507+
{"name": "@data_type", "value": DataType.current_team_agent},
508+
]
509+
items = self.container.query_items(query=query, parameters=params)
510+
print("Items to delete:", items)
511+
if items:
512+
async for doc in items:
513+
try:
514+
await self.container.delete_item(
515+
doc["id"], partition_key=doc["session_id"]
516+
)
517+
except Exception as e:
518+
self.logger.warning(
519+
"Failed deleting current team doc %s: %s", doc.get("id"), e
520+
)
521+
522+
return True
523+
524+
async def get_team_agent(
525+
self, team_id: str, agent_name: str
526+
) -> Optional[CurrentTeamAgent]:
527+
"""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+
params = [
530+
{"name": "@team_id", "value": team_id},
531+
{"name": "@agent_name", "value": agent_name},
532+
{"name": "@data_type", "value": DataType.current_team_agent},
533+
]
534+
535+
results = await self.query_items(query, params, CurrentTeamAgent)
536+
return results[0] if results else None

src/backend/common/database/database_base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..models.messages_af import (
99
AgentMessageData,
1010
BaseDataModel,
11+
CurrentTeamAgent,
1112
Plan,
1213
Step,
1314
TeamConfiguration,
@@ -231,3 +232,20 @@ async def update_agent_message(self, message: AgentMessageData) -> None:
231232
async def get_agent_messages(self, plan_id: str) -> Optional[AgentMessageData]:
232233
"""Retrieve agent messages by plan_id."""
233234
pass
235+
236+
@abstractmethod
237+
async def add_team_agent(self, team_agent: CurrentTeamAgent) -> None:
238+
"""Add an agent message to the database."""
239+
pass
240+
241+
@abstractmethod
242+
async def delete_team_agent(self, team_id: str, agent_name: str) -> None:
243+
"""Delete a team agent from the database."""
244+
pass
245+
246+
@abstractmethod
247+
async def get_team_agent(
248+
self, team_id: str, agent_name: str
249+
) -> Optional[CurrentTeamAgent]:
250+
"""Retrieve a team agent by team_id and agent_name."""
251+
pass

src/backend/common/models/messages_af.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class UserCurrentTeam(BaseDataModel):
112112
user_id: str
113113
team_id: str
114114

115-
class CurrentAgent(BaseDataModel):
115+
class CurrentTeamAgent(BaseDataModel):
116116
"""Represents the current agent of a user."""
117117
data_type: Literal[DataType.current_team_agent] = DataType.current_team_agent
118118
team_id: str

0 commit comments

Comments
 (0)