agentleFS
MicrosoftKnown publishermicrosoft/semantic-link-labs/AGENTS.md

semantic-link-labs

AGENTS.md584 starsChanged 10 months agoMITView on GitHub

This guide provides comprehensive instructions for AI agents working on the Semantic Link Labs (sempy_labs) codebase — an open-source Python library that extends the capabilities of Semantic Link for Microsoft Fabric notebooks. Semantic Link Labs is a community-driven extension library designed for use in Microsoft Fabric notebooks. It provides additional functionalities to work with: Semantic Link Labs depends on the semantic-link-sempy package as specified in pyproject.toml: The library uses the public APIs from sempy.fabric for: - FabricRestClient — HTTP client…

  • Installs packages

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

24 rules. About 0 are common, 15 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Important: Only use public APIs from sempy as documented at:

    line 43
  2. Distinctive:

    Use descriptive, meaningful names for functions, variables, and classes.

    line 114
  3. Very specific:

    Use the typing module for complex annotations (e.g., List[str], Dict[str, int], Optional[T]).

    line 116
  4. Very specific:

    Use Union[str, UUID] for parameters that accept both name and ID.

    line 117
  5. Distinctive:

    Write clear docstrings for each function.

    line 121
  6. Distinctive:

    Follow the Single Responsibility Principle.

    line 123
  7. Distinctive:

    ALWAYS prioritize readability over cleverness.

    line 128
  8. Distinctive:

    Document design decisions explaining *why*, not just *what*.

    line 129
  9. Distinctive:

    Write concise, efficient, and idiomatic Python code.

    line 130
  10. Very specific:

    All public functions MUST have the @log decorator from sempy:

    line 138
  11. Distinctive:

    Use these common parameter patterns for consistency:

    line 164
  12. Very specific:

    Always document that None workspace resolves to attached lakehouse workspace:

    line 174
  13. Very specific:

    ALWAYS return pandas.DataFrame for functions that return tabular data.

    line 185
  14. Very specific:

    Use _create_dataframe helper to initialize empty DataFrames with proper column types.

    line 186
  15. Distinctive:

    Always reference the official API docs in docstrings:

    line 325
  16. Distinctive:

    Use numpydoc style for all docstrings with these sections:

    line 423
  17. Distinctive:

    Follow PEP 8 style guide

    line 446
  18. Distinctive:

    Use 4 spaces for indentation (no tabs)

    line 447
  19. Distinctive:

    Use black for code formatting

    line 449
  20. Distinctive:

    Use LF (Unix-style) line endings

    line 450
  21. Distinctive:

    Follow the coding standards and patterns described above.

    line 469
  22. Very specific:

    Add to the module's __init__.py:

    line 473
  23. Very specific:

    If it's a top-level function, add to src/sempy_labs/__init__.py:

    line 486
  24. Distinctive:

    Before committing code changes, run these checks:

    line 558

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Semantic Link Labs Development Agent Guide

This guide provides comprehensive instructions for AI agents working on the Semantic Link Labs (sempy_labs) codebase — an open-source Python library that extends the capabilities of Semantic Link for Microsoft Fabric notebooks.

Project Overview

Semantic Link Labs is a community-driven extension library designed for use in Microsoft Fabric notebooks. It provides additional functionalities to work with:

  • Semantic models (datasets) — Management, analysis, and migration tools
  • Workspaces — Fabric and Power BI workspace operations
  • Lakehouses — Lakehouse table management and shortcuts
  • Reports — Report analysis, rebinding, and BPA
  • Capacities — Capacity management and migration
  • And many more — Notebooks, gateways, connections, etc.

Key Features

Feature CategoryDescription
TOM WrapperTabular Object Model wrapper for semantic model management
Best Practice AnalyzerModel and Report BPA for quality checks
Direct LakeMigration, schema sync, and guardrails for Direct Lake models
Vertipaq AnalyzerSemantic model memory and performance analysis
Admin APIsAdmin-level operations for tenant management
Migration ToolsCapacity and model migration utilities

Dependency on Semantic Link

Semantic Link Labs depends on the semantic-link-sempy package as specified in pyproject.toml:

dependencies = [
    "semantic-link-sempy>=0.14.2",
    ...
]

The library uses the public APIs from sempy.fabric for:

  • FabricRestClient — HTTP client for REST API calls
  • create_tom_server — TOM server connection
  • Standard Fabric context functions

Important: Only use public APIs from sempy as documented at:


Source Code Layout

Main source code is located under src/sempy_labs/:

PathDescription
__init__.pyMain module exports
_helper_functions.pyShared utility functions (2800+ lines)
_authentication.pyService Principal authentication
_utils.pyItem type mappings and constants
_icons.pyIcons, emojis, and UI constants

Core Submodules

SubmodulePurpose
tom/TOM (Tabular Object Model) wrapper for semantic models
admin/Admin API functions
report/Report operations (BPA, rebind, export)
lakehouse/Lakehouse operations (shortcuts, tables, schemas)
directlake/Direct Lake model management
migration/Model and capacity migration tools

Feature Modules (top-level)

FileFeature
_model_bpa.pyModel Best Practice Analyzer
_model_bpa_rules.pyBPA rule definitions
_vertipaq.pyVertipaq Analyzer
_workspaces.pyWorkspace management
_capacities.pyAzure capacity operations
_refresh_semantic_model.pyModel refresh operations
_translations.pyModel metadata translations
_delta_analyzer.pyDelta table analysis

Other Key Directories

DirectoryPurpose
tests/Unit tests
notebooks/Sample helper notebooks
docs/Sphinx documentation source
.github/Issue templates and CI workflows

Development Guidelines

Core Principles

  1. USE SKILLS PROACTIVELY — Before starting ANY task, check the Skills Reference section below and read the relevant SKILL.md files. Skills contain domain-specific knowledge, patterns, fixtures, and best practices developed by the team. Failing to use skills leads to suboptimal implementations that require refactoring.
  2. Break down complexity — Decompose large tasks into smaller, manageable subtasks. Use the planning-with-files skill for complex work.
  3. Understand before coding — Fully understand requirements, context, and constraints before writing code.
  4. Clarify, don't assume — Ask for specifics rather than making assumptions about requirements.
  5. Backward compatibility — ALWAYS maintain backward compatibility for existing functions.
  6. Minimal changes — Do NOT change existing code unless strongly necessary.
  7. Follow existing patterns — Match the coding style and patterns already in the codebase.
  8. Document everything — Every public function must have complete docstrings.

Python Coding Standards

Naming and Type Annotations

  • Use descriptive, meaningful names for functions, variables, and classes.
  • Include type hints for all function parameters and return values.
  • Use the typing module for complex annotations (e.g., List[str], Dict[str, int], Optional[T]).
  • Use Union[str, UUID] for parameters that accept both name and ID.

Function Design

  • Write clear docstrings for each function.
  • Break down complex functions into smaller helper functions.
  • Follow the Single Responsibility Principle.
  • Handle edge cases explicitly with clear exception handling.

Code Clarity

  • ALWAYS prioritize readability over cleverness.
  • Document design decisions explaining why, not just what.
  • Write concise, efficient, and idiomatic Python code.

Public Function Conventions

Required Decorator

All public functions MUST have the @log decorator from sempy:

from sempy._utils._log import log

@log
def my_public_function(...):
    ...

Naming Conventions

Function names should start with a verb indicating the action:

PrefixUse Case
list_Retrieves a collection of items
get_Retrieves a single item or property
create_Creates a new resource
update_Modifies an existing resource
delete_Removes a resource
resolve_Converts name to ID or vice versa
run_Executes an analysis or process

Standard Parameters

Use these common parameter patterns for consistency:

ParameterTypeUse Case
workspaceOptional[str | UUID] = NoneFabric workspace name or ID
datasetstr | UUIDSemantic model name or ID
lakehouseOptional[str | UUID] = NoneLakehouse name or ID

Default Workspace Resolution

Always document that None workspace resolves to attached lakehouse workspace:

workspace : str | uuid.UUID, default=None
    The Fabric workspace name or ID.
    Defaults to None which resolves to the workspace of the attached lakehouse
    or if no lakehouse attached, resolves to the workspace of the notebook.

Return Values

  • ALWAYS return pandas.DataFrame for functions that return tabular data.
  • Use _create_dataframe helper to initialize empty DataFrames with proper column types.

Service Principal Support

For functions supporting Service Principal authentication, add this to the docstring:

"""
...
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
...
"""

Example: Well-Formed Public Function

from sempy._utils._log import log
from sempy_labs._helper_functions import (
    resolve_workspace_name_and_id,
    _base_api,
    _create_dataframe,
)
import sempy_labs._icons as icons
from typing import Optional
from uuid import UUID
import pandas as pd


@log
def list_items(
    item_type: Optional[str] = None,
    workspace: Optional[str | UUID] = None,
) -> pd.DataFrame:
    """
    Returns a list of items in the specified workspace.

    This is a wrapper function for the following API: `Items - List Items <https://learn.microsoft.com/rest/api/fabric/core/items/list-items>`_.

    Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

    Parameters
    ----------
    item_type : str, default=None
        Filter by item type. If None, returns all item types.
    workspace : str | uuid.UUID, default=None
        The Fabric workspace name or ID.
        Defaults to None which resolves to the workspace of the attached lakehouse
        or if no lakehouse attached, resolves to the workspace of the notebook.

    Returns
    -------
    pandas.DataFrame
        A pandas dataframe showing the items in the workspace.
    """

    (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)

    columns = {
        "Item Id": "string",
        "Item Name": "string",
        "Item Type": "string",
    }
    df = _create_dataframe(columns=columns)

    responses = _base_api(
        request=f"/v1/workspaces/{workspace_id}/items",
        uses_pagination=True,
        client="fabric_sp",
    )

    # Process responses and build dataframe...

    return df

REST API Client Pattern

Using _base_api Helper

The _base_api function in _helper_functions.py is the standard way to make REST API calls:

from sempy_labs._helper_functions import _base_api

# Simple GET request - MUST call .json() to get dict
response = _base_api(
    request="/v1/workspaces/{workspace_id}/items/{item_id}",
    client="fabric_sp",
).json()  # <-- Don't forget .json()!

# POST with payload
response = _base_api(
    request="/v1/workspaces/{workspace_id}/items",
    method="post",
    payload={"displayName": name},
    status_codes=[201, 202],
    client="fabric_sp",
)

# With pagination - returns list of dicts, no .json() needed
responses = _base_api(
    request=url,
    uses_pagination=True,
    client="fabric_sp",
)

# Long-running operation - returns dict directly, no .json() needed
result = _base_api(
    request=url,
    method="post",
    lro_return_json=True,  # Returns JSON when LRO completes
    client="fabric_sp",
)

_base_api Return Types (IMPORTANT)

ParametersReturn TypeUsage
DefaultResponseMust call .json() to get dict
uses_pagination=Truelist[dict]Iterate directly
lro_return_json=TruedictUse directly
lro_return_status_code=TrueintHTTP status code

Client Types

ClientUse Case
fabricStandard Fabric API (default credentials)
fabric_spFabric API with Service Principal support
azureAzure Resource Manager API
graphMicrosoft Graph API
onelakeOneLake storage API

API Documentation Links

Always reference the official API docs in docstrings:

"""
This is a wrapper function for the following API: `Items - List Items <https://learn.microsoft.com/rest/api/fabric/core/items/list-items>`_.
"""

TOM Wrapper Usage

The TOM wrapper (tom/) provides a Pythonic interface to the Tabular Object Model:

from sempy_labs.tom import connect_semantic_model

with connect_semantic_model(
    dataset="My Model",
    readonly=False,  # Set to True for read-only operations
    workspace="My Workspace"
) as tom:
    # Access model objects
    for measure in tom.all_measures():
        print(measure.Name)

    # Modify model (requires readonly=False)
    tom.model.Tables["Sales"].Measures["Revenue"].Description = "Total revenue"

    # Changes are saved when context exits

TOM Methods

The TOMWrapper class provides helper methods:

MethodReturns
all_columns()Iterator of all columns
all_measures()Iterator of all measures
all_tables()Access model.Tables
all_partitions()Iterator of all partitions
all_hierarchies()Iterator of all hierarchies
all_calculation_items()Iterator of calculation items

Helper Functions

Common helper functions in _helper_functions.py:

Workspace/Item Resolution

from sempy_labs._helper_functions import (
    resolve_workspace_id,
    resolve_workspace_name_and_id,
    resolve_dataset_id,
    resolve_dataset_name_and_id,
    resolve_item_id,
    resolve_item_name,
)

DataFrame Utilities

from sempy_labs._helper_functions import (
    _create_dataframe,        # Create empty DataFrame with typed columns
    _update_dataframe_datatypes,  # Update column types
)

Validation

from sempy_labs._helper_functions import (
    _is_valid_uuid,           # Check if string is valid UUID
)

Icons and Messages

import sempy_labs._icons as icons

print(f"{icons.green_dot} Success message")
print(f"{icons.red_dot} Error message")
print(f"{icons.warning} Warning message")
print(f"{icons.in_progress} In progress...")

Documentation Standards

Docstrings

Use numpydoc style for all docstrings with these sections:

  1. Short description — One-line summary
  2. Long description — Extended explanation (optional)
  3. Parameters — Document each parameter with type and default
  4. Returns / Yields — Document return value
  5. Raises — Document exceptions (if applicable)

Parameter Documentation Format

Parameters
----------
item_type : str, default=None
    Filter by item type. If None, returns all item types.
workspace : str | uuid.UUID, default=None
    The Fabric workspace name or ID.
    Defaults to None which resolves to the workspace of the attached lakehouse
    or if no lakehouse attached, resolves to the workspace of the notebook.

Code Style

  • Follow PEP 8 style guide
  • Use 4 spaces for indentation (no tabs)
  • Maximum line length: 200 characters (as per pyproject.toml)
  • Use black for code formatting
  • Use LF (Unix-style) line endings

Adding New Functions

Step 1: Choose the Right Module

Function TypeLocation
General workspace/item operations_helper_functions.py or dedicated _*.py
Admin operationsadmin/ submodule
Report operationsreport/ submodule
Lakehouse operationslakehouse/ submodule
Direct Lake operationsdirectlake/ submodule
TOM operationstom/_model.py

Step 2: Implement the Function

Follow the coding standards and patterns described above.

Step 3: Export the Function

Add to the module's __init__.py:

from ._my_module import my_new_function

__all__ = [
    ...,
    "my_new_function",
]

Step 4: Add to Main Package

If it's a top-level function, add to src/sempy_labs/__init__.py:

from ._my_module import my_new_function

__all__ = [
    ...,
    "my_new_function",
]

Testing

Test Framework

  • Framework: pytest
  • Location: tests/ directory
  • Configuration: pyproject.toml

Running Tests

# Run all tests
pytest -s tests/

# Run specific test
pytest -s tests/ -k test_name

Writing Tests

Tests should be minimal but effective:

import pytest

def test_my_function():
    """Test my_function basic behavior."""
    from sempy_labs import my_function

    result = my_function(input_value)

    assert isinstance(result, pd.DataFrame)
    assert not result.empty

Building Documentation

Documentation is built with Sphinx and hosted on ReadTheDocs.

Local Build

cd docs
sphinx-apidoc -f -o source ../src/sempy_labs/
make html

Documentation Configuration

  • Config: docs/source/conf.py
  • Theme: sphinx_rtd_theme
  • Style: numpydoc

Pre-Commit Checklist

Before committing code changes, run these checks:

# 1. Format code
black src/sempy_labs tests

# 2. Check style violations
flake8 src/sempy_labs tests

# 3. Verify type correctness (optional but recommended)
mypy src/sempy_labs

# 4. Run relevant tests
pytest -s tests/ -k <test_pattern>

# 5. Build documentation (if functions were added or modified)
cd docs && sphinx-apidoc -f -o source ../src/sempy_labs/ && make html && cd ..

Verify before committing:

  • All new public functions have the @log decorator
  • Docstrings follow numpydoc style with all required sections
  • API reference links are included in docstrings (for API wrappers)
  • Functions are exported in the appropriate __init__.py
  • Tests pass locally

Quick Commands

TaskCommand
Install package in dev modepip install -e .
Run all testspytest -s tests/
Run specific testpytest -s tests/ -k test_name
Build docs locallycd docs && make html
Format code with blackblack src/sempy_labs tests

Important Files

FilePurpose
pyproject.tomlPackage configuration and dependencies
environment.ymlConda environment for development
.readthedocs.yamlReadTheDocs build configuration
.github/workflows/build.yamlCI/CD pipeline
src/sempy_labs/__init__.pyMain package exports
src/sempy_labs/_helper_functions.pyShared utilities

Skills Reference

CRITICAL: ALWAYS USE SKILLS

Skills are mandatory reading before starting any task. They contain:

  • Established patterns and conventions used by the team
  • Step-by-step workflows validated by developers
  • Common pitfalls and how to avoid them
  • Templates and examples for common tasks

Before writing any code:

  1. Identify which skills apply to your task (see table below)
  2. Read the full SKILL.md content
  3. Follow the patterns and use the helpers defined in the skill

Examples of when to use skills:

  • Complex multi-step tasks → Read planning-with-files FIRST
  • Adding new functions → Read add-function AND rest-api-patterns
  • Writing tests → Read write-tests
  • Running tests → Read run-tests
  • Need reference implementations → Read github-repo-explore
  • Building docs → Read build-docs

Skipping skills leads to implementations that miss established patterns and require refactoring.

Development Skills

SkillFilePurpose
Add FunctionSKILL.mdAdding new API wrapper functions to the library
REST API PatternsSKILL.mdImplementing REST API wrapper functions with _base_api
TOM OperationsSKILL.mdWorking with TOM wrapper for semantic models
Direct LakeSKILL.mdDirect Lake model operations and migration

Testing Skills

SkillFilePurpose
Run TestsSKILL.mdRunning pytest tests locally
Write TestsSKILL.mdWriting unit tests with pytest

Code Quality Skills

SkillFilePurpose
Code StyleSKILL.mdLinting with flake8, formatting with black, type checking with mypy
Build DocsSKILL.mdBuilding and validating Sphinx documentation

Planning & Task Management

SkillFilePurpose
Planning with FilesSKILL.mdUSE FOR COMPLEX TASKS. Manus-style file-based planning with task_plan.md, findings.md, progress.md

External Resources & Review

SkillFilePurpose
GitHub Repo ExploreSKILL.mdSearch and explore external GitHub repositories for reference implementations
PR Review CommentsSKILL.mdPosting inline PR review comments to GitHub

External Resources

ResourceURL
DocumentationReadTheDocs
GitHub WikiWiki
Code ExamplesExamples
Fabric REST APIDocs
Power BI REST APIDocs
Semantic Link APIDocs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.