|
| 1 | +""" |
| 2 | +AgentsService (skeleton) |
| 3 | +
|
| 4 | +Lightweight service that receives a TeamService instance and exposes helper |
| 5 | +methods to convert a TeamConfiguration into a list/array of agent descriptors. |
| 6 | +
|
| 7 | +This is intentionally a simple skeleton — the user will later provide the |
| 8 | +implementation that wires these descriptors into Semantic Kernel / Foundry |
| 9 | +agent instances. |
| 10 | +""" |
| 11 | + |
| 12 | +from typing import Any, Dict, List, Union |
| 13 | +import logging |
| 14 | + |
| 15 | +from v3.common.services.team_service import TeamService |
| 16 | +from common.models.messages_kernel import TeamConfiguration, TeamAgent |
| 17 | + |
| 18 | + |
| 19 | +class AgentsService: |
| 20 | + """Service for building agent descriptors from a team configuration. |
| 21 | +
|
| 22 | + Responsibilities (skeleton): |
| 23 | + - Receive a TeamService instance on construction (can be used for validation |
| 24 | + or lookups when needed). |
| 25 | + - Expose a method that accepts a TeamConfiguration (or raw dict) and |
| 26 | + returns a list of agent descriptors. Descriptors are plain dicts that |
| 27 | + contain the fields required to later instantiate runtime agents. |
| 28 | +
|
| 29 | + The concrete instantiation logic (semantic kernel / foundry) is intentionally |
| 30 | + left out and should be implemented by the user later (see |
| 31 | + `instantiate_agents` placeholder). |
| 32 | + """ |
| 33 | + |
| 34 | + def __init__(self, team_service: TeamService): |
| 35 | + self.team_service = team_service |
| 36 | + self.logger = logging.getLogger(__name__) |
| 37 | + |
| 38 | + async def get_agents_from_team_config( |
| 39 | + self, team_config: Union[TeamConfiguration, Dict[str, Any]] |
| 40 | + ) -> List[Dict[str, Any]]: |
| 41 | + """Return a list of lightweight agent descriptors derived from a |
| 42 | + TeamConfiguration or a raw dict. |
| 43 | +
|
| 44 | + Each descriptor contains the basic fields from the team config and a |
| 45 | + placeholder where a future runtime/agent object can be attached. |
| 46 | +
|
| 47 | + Args: |
| 48 | + team_config: TeamConfiguration model instance or a raw dict |
| 49 | +
|
| 50 | + Returns: |
| 51 | + List[dict] -- each dict contains keys like: |
| 52 | + - input_key, type, name, system_message, description, icon, |
| 53 | + index_name, agent_obj (placeholder) |
| 54 | + """ |
| 55 | + if not team_config: |
| 56 | + return [] |
| 57 | + |
| 58 | + # Accept either the pydantic TeamConfiguration or a raw dictionary |
| 59 | + if hasattr(team_config, "agents"): |
| 60 | + agents_raw = team_config.agents or [] |
| 61 | + elif isinstance(team_config, dict): |
| 62 | + agents_raw = team_config.get("agents", []) |
| 63 | + else: |
| 64 | + # Unknown type; try to coerce to a list |
| 65 | + try: |
| 66 | + agents_raw = list(team_config) |
| 67 | + except Exception: |
| 68 | + agents_raw = [] |
| 69 | + |
| 70 | + descriptors: List[Dict[str, Any]] = [] |
| 71 | + for a in agents_raw: |
| 72 | + if isinstance(a, TeamAgent): |
| 73 | + desc = { |
| 74 | + "input_key": a.input_key, |
| 75 | + "type": a.type, |
| 76 | + "name": a.name, |
| 77 | + "system_message": getattr(a, "system_message", ""), |
| 78 | + "description": getattr(a, "description", ""), |
| 79 | + "icon": getattr(a, "icon", ""), |
| 80 | + "index_name": getattr(a, "index_name", ""), |
| 81 | + "use_rag": getattr(a, "use_rag", False), |
| 82 | + "use_mcp": getattr(a, "use_mcp", False), |
| 83 | + "coding_tools": getattr(a, "coding_tools", False), |
| 84 | + # Placeholder for later wiring to a runtime/agent instance |
| 85 | + "agent_obj": None, |
| 86 | + } |
| 87 | + elif isinstance(a, dict): |
| 88 | + desc = { |
| 89 | + "input_key": a.get("input_key"), |
| 90 | + "type": a.get("type"), |
| 91 | + "name": a.get("name"), |
| 92 | + "system_message": a.get("system_message") or a.get("instructions"), |
| 93 | + "description": a.get("description"), |
| 94 | + "icon": a.get("icon"), |
| 95 | + "index_name": a.get("index_name"), |
| 96 | + "use_rag": a.get("use_rag", False), |
| 97 | + "use_mcp": a.get("use_mcp", False), |
| 98 | + "coding_tools": a.get("coding_tools", False), |
| 99 | + "agent_obj": None, |
| 100 | + } |
| 101 | + else: |
| 102 | + # Fallback: keep raw object for later introspection |
| 103 | + desc = {"raw": a, "agent_obj": None} |
| 104 | + |
| 105 | + descriptors.append(desc) |
| 106 | + |
| 107 | + return descriptors |
| 108 | + |
| 109 | + async def instantiate_agents(self, agent_descriptors: List[Dict[str, Any]]): |
| 110 | + """Placeholder for instantiating runtime agent objects from descriptors. |
| 111 | +
|
| 112 | + The real implementation should create Semantic Kernel / Foundry agents |
| 113 | + and attach them to each descriptor under the key `agent_obj` or return a |
| 114 | + list of instantiated agents. |
| 115 | +
|
| 116 | + Raises: |
| 117 | + NotImplementedError -- this is only a skeleton. |
| 118 | + """ |
| 119 | + raise NotImplementedError( |
| 120 | + "Agent instantiation is not implemented in the skeleton" |
| 121 | + ) |
0 commit comments