This document describes how to setup your environment with Python and uv, if you're working on new features or a bug fix for Agent Framework, or simply want to run the tests included.
For coding standards and conventions, see CODING_STANDARD.md.
We are using a tool called poethepoet for task management and uv for dependency management. At the end of this document, you will find the available Poe tasks.
Check that you've cloned the repository to ~/workspace or a similar folder.
Avoid /mnt/c/ and prefer using your WSL user's home directory.
Ensure you have the WSL extension for VSCode installed.
uv allows us to use AF from the local files, without worrying about paths, as if you had AF pip package installed.
To install AF and all the required tools in your system, first, navigate to the directory containing this DEV_SETUP using your chosen shell.
Check the uv documentation for the installation instructions. At the time of writing this is the command to install uv:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Check the uv documentation for the installation instructions. At the time of writing this is the command to install uv:
curl -LsSf https://astral.sh/uv/install.sh | shFor MacOS users, Homebrew provides an easy installation of uv with the uv Formulae
brew install uvYou can then run the following commands manually:
# Install Python 3.10, 3.11, 3.12, and 3.13
uv python install 3.10 3.11 3.12 3.13
# Create a virtual environment with Python 3.10 (you can change this to 3.11, 3.12 or 3.13)
$PYTHON_VERSION = "3.10"
uv venv --python $PYTHON_VERSION
# Install AF and all dependencies
uv sync --dev
# Install all the tools and dependencies
uv run poe install
# Install prek hooks
uv run poe prek-installAlternatively, you can reinstall the venv, pacakges, dependencies and prek hooks with a single command (but this requires poe in the current env), this is especially useful if you want to switch python versions:
uv run poe setup -p 3.13You can then run different commands through Poe the Poet, use uv run poe to discover which ones.
Install the Python extension for VSCode.
Open the python folder in VSCode.
The workspace for python should be rooted in the
./pythonfolder.
Open any of the .py files in the project and run the Python: Select Interpreter
command from the command palette. Make sure the virtual env (default path is .venv) created by uv is selected.
Make sure you have an OpenAI API Key or Azure OpenAI service key
There are two methods to manage keys, secrets, and endpoints:
-
Store them in environment variables. AF Python leverages pydantic settings to load keys, secrets, and endpoints from the environment.
When you are using VSCode and have the python extension setup, it automatically loads environment variables from a
.envfile, so you don't have to manually set them in the terminal. During runtime on different platforms, environment settings set as part of the deployments should be used. -
Store them in a separate
.envfile, likedev.env, you can then pass that name into the constructor for most services, to theenv_file_pathparameter, see below.Make sure to add
*.envto your.gitignorefile.
To configure a .env file with just the keys needed for OpenAI Chat Completions, you can create a openai.env (this name is just as an example, a single .env with all required keys is more common) file in the root of the python folder with the following content:
Content of .env or openai.env:
OPENAI_API_KEY=""
OPENAI_CHAT_MODEL_ID="gpt-4o-mini"You will then configure the ChatClient class with the keyword argument env_file_path:
from agent_framework.openai import OpenAIChatClient
client = OpenAIChatClient(env_file_path="openai.env")All the tests are located in the tests folder of each package. Tests marked with @pytest.mark.integration and @skip_if_..._integration_tests_disabled are integration tests that require external services (e.g., OpenAI, Azure OpenAI). They are automatically skipped when the required API keys or service endpoints are not configured in your environment or .env file.
You can select or exclude integration tests using pytest markers:
# Run only unit tests (exclude integration tests)
uv run poe all-tests -m "not integration"
# Run only integration tests
uv run poe all-tests -m integrationAlternatively, you can run them using VSCode Tasks. Open the command palette
(Ctrl+Shift+P) and type Tasks: Run Task. Select Test from the list.
If you want to run the tests for a single package, you can use the uv run poe test command with the package name as an argument. For example, to run the tests for the agent_framework package, you can use:
uv run poe --directory packages/core testLarge packages (core, ag-ui, orchestrations, anthropic) use pytest-xdist for parallel test execution within the package. The all-tests task also uses xdist across all packages.
These commands also output the coverage report.
To run the same checks that run during a commit and the GitHub Action Python Code Quality, you can use this command, from the python folder:
uv run poe checkIdeally you should run these checks before committing any changes, when you install using the instructions above the prek hooks should be installed already.
We try to maintain a high code coverage for the project. To run the code coverage on the unit tests, you can use the following command:
uv run poe testThis will show you which files are not covered by the tests, including the specific lines not covered. Make sure to consider the untested lines from the code you are working on, but feel free to add other tests as well, that is always welcome!
There are many people committing to Semantic Kernel, so it is important to keep your local repository up to date. To do this, you can run the following commands:
git fetch upstream main
git rebase upstream/main
git push --force-with-leaseor:
git fetch upstream main
git merge upstream/main
git pushThis is assuming the upstream branch refers to the main repository. If you have a different name for the upstream branch, you can replace upstream with the name of your upstream branch.
After running the rebase command, you may need to resolve any conflicts that arise. If you are unsure how to resolve a conflict, please refer to the GitHub's documentation on resolving conflicts, or for VSCode.
This project uses poethepoet for task management and uv for dependency management.
Once uv is installed, and you do not yet have a virtual environment setup:
uv venvand then you can run the following tasks:
uv sync --all-extras --devAfter this initial setup, you can use the following tasks to manage your development environment. It is advised to use the following setup command since that also installs the prek hooks.
Set up the development environment with a virtual environment, install dependencies and prek hooks:
uv run poe setup
# or with specific Python version
uv run poe setup --python 3.12Install all dependencies including extras and dev dependencies, including updates:
uv run poe installCreate a virtual environment with specified Python version or switch python version:
uv run poe venv
# or with specific Python version
uv run poe venv --python 3.12Install prek hooks:
uv run poe prek-installEach of the following tasks run against both the main agent-framework package and the extension packages in parallel, ensuring consistent code quality across the project.
Format code using ruff (runs in parallel across all packages):
uv run poe fmtRun linting checks and fix issues (runs in parallel across all packages):
uv run poe lintRun Pyright type checking (runs in parallel across all packages):
uv run poe pyrightRun MyPy type checking (runs in parallel across all packages):
uv run poe mypyRun both Pyright and MyPy type checking:
uv run poe typingLint markdown code blocks:
uv run poe markdown-code-lintRun all package-level quality checks (format, lint, pyright, mypy) in parallel across all packages. This runs the full cross-product of (package × check) concurrently:
uv run poe check-packagesRun all quality checks including package checks, samples, tests and markdown lint:
uv run poe checkRun unit tests with coverage by invoking the test task in each package in parallel:
uv run poe testTo run tests for a specific package only, use the --directory flag:
# Run tests for the core package
uv run --directory packages/core poe test
# Run tests for the azure-ai package
uv run --directory packages/azure-ai poe testRun all tests in a single pytest invocation across all packages in parallel (excluding lab and devui). This is faster than test as it uses pytest's parallel execution:
uv run poe all-testsSame as all-tests but with coverage reporting enabled:
uv run poe all-tests-covBuild all packages:
uv run poe buildClean the dist directories:
uv run poe clean-distPublish packages to PyPI:
uv run poe publishPrek hooks run automatically on commit and execute a subset of the checks on changed files only. Package-level checks (fmt, lint, pyright) run in parallel but only for packages with changed files. Markdown and sample checks are skipped when no relevant files were changed. If the core package is changed, all packages are checked. You can also run all checks using prek directly:
uv run prek run -a