Repository: phidatahq/phidata
File: libs/agno/agno/os/app.py (Python)

Code before:

        self.telemetry = telemetry
        self.tracing = tracing
        self.tracing_db = tracing_db

        self.enable_mcp_server = enable_mcp_server
        self.lifespan = lifespan

        # RBAC
        self.authorization = authorization
        self.authorization_config = authorization_config

        # CORS configuration - merge user-provided origins with defaults from settings
        self.cors_allowed_origins = resolve_origins(cors_allowed_origins, self.settings.cors_origin_list)

        # If True, run agent/team hooks as FastAPI background tasks
        self.run_hooks_in_background = run_hooks_in_background

        # List of all MCP tools used inside the AgentOS
        self.mcp_tools: List[Any] = []
        self._mcp_app: Optional[Any] = None

        # Check for duplicate IDs before initialization
        self._check_duplicate_ids(self.agents)
        self._check_duplicate_ids(self.teams)
        self._check_duplicate_ids(self.workflows)

        self._initialize_agents()
        self._initialize_teams()
        self._initialize_workflows()

        if self.tracing:
            self._setup_tracing()

        if self.telemetry:
            from agno.api.os import OSLaunch, log_os_telemetry

            log_os_telemetry(launch=OSLaunch(os_id=self.id, data=self._get_telemetry_data()))

    def _add_agent_os_to_lifespan_function(self, lifespan):
        """
        Inspect a lifespan function and wrap it to pass agent_os if it accepts it.

        Returns:
            A wrapped lifespan that passes agent_os if the lifespan function expects it.
        """
        # Getting the actual function inside the lifespan
        lifespan_function = lifespan
        if hasattr(lifespan, "__wrapped__"):
            lifespan_function = lifespan.__wrapped__


Review comment (refactor):
Let's jus do `self._check_duplicate_duplicate_ids`. Better to keep the logic together as we'll always want to check all

And we have `self` there, no need to pass self.agents etc either

Code after:

        self.telemetry = telemetry
        self.tracing = tracing
        self.tracing_db = tracing_db

        self.enable_mcp_server = enable_mcp_server
        self.lifespan = lifespan

        # RBAC
        self.authorization = authorization
        self.authorization_config = authorization_config

        # CORS configuration - merge user-provided origins with defaults from settings
        self.cors_allowed_origins = resolve_origins(cors_allowed_origins, self.settings.cors_origin_list)

        # If True, run agent/team hooks as FastAPI background tasks
        self.run_hooks_in_background = run_hooks_in_background

        # List of all MCP tools used inside the AgentOS
        self.mcp_tools: List[Any] = []
        self._mcp_app: Optional[Any] = None

        self._initialize_agents()
        self._initialize_teams()
        self._initialize_workflows()

        # Check for duplicate IDs
        self._raise_if_duplicate_ids()

        if self.tracing:
            self._setup_tracing()

        if self.telemetry:
            from agno.api.os import OSLaunch, log_os_telemetry

            log_os_telemetry(launch=OSLaunch(os_id=self.id, data=self._get_telemetry_data()))

    def _add_agent_os_to_lifespan_function(self, lifespan):
        """
        Inspect a lifespan function and wrap it to pass agent_os if it accepts it.

        Returns:
            A wrapped lifespan that passes agent_os if the lifespan function expects it.
        """
        # Getting the actual function inside the lifespan
        lifespan_function = lifespan
        if hasattr(lifespan, "__wrapped__"):
            lifespan_function = lifespan.__wrapped__

        try:
            from inspect import signature